Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc067bc4 authored by Christopher Ferris's avatar Christopher Ferris Committed by Automerger Merge Worker
Browse files

Merge "debuggerd_client_test: less racy test setup" am: 6e80656b am: 09e14a6d am: 34cd42b6

parents 6a024715 34cd42b6
Loading
Loading
Loading
Loading
+20 −10
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@


#include <fcntl.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdio.h>
#include <sys/eventfd.h>
#include <unistd.h>
#include <unistd.h>


#include <chrono>
#include <chrono>
@@ -51,23 +52,35 @@ static int getThreadCount() {


TEST(debuggerd_client, race) {
TEST(debuggerd_client, race) {
  static int THREAD_COUNT = getThreadCount();
  static int THREAD_COUNT = getThreadCount();
  pid_t forkpid = fork();


  ASSERT_NE(-1, forkpid);
  // Semaphore incremented once per thread started.
  unique_fd barrier(eventfd(0, EFD_SEMAPHORE));
  ASSERT_NE(-1, barrier.get());


  pid_t forkpid = fork();
  ASSERT_NE(-1, forkpid);
  if (forkpid == 0) {
  if (forkpid == 0) {
    // Spawn a bunch of threads, to make crash_dump take longer.
    // Spawn a bunch of threads, to make crash_dump take longer.
    std::vector<std::thread> threads;
    std::vector<std::thread> threads;
    threads.reserve(THREAD_COUNT);
    for (int i = 0; i < THREAD_COUNT; ++i) {
    for (int i = 0; i < THREAD_COUNT; ++i) {
      threads.emplace_back([]() {
      threads.emplace_back([&barrier]() {
        while (true) {
        uint64_t count = 1;
          std::this_thread::sleep_for(60s);
        ASSERT_NE(-1, write(barrier.get(), &count, sizeof(count)));
        for (;;) {
          pause();
        }
        }
      });
      });
    }
    }
    for (;;) {
      pause();
    }
  }


    std::this_thread::sleep_for(60s);
  // Wait for the child to spawn all of its threads.
    exit(0);
  for (int i = 0; i < THREAD_COUNT; ++i) {
    uint64_t count;
    ASSERT_NE(-1, read(barrier.get(), &count, sizeof(count)));
  }
  }


  unique_fd pipe_read, pipe_write;
  unique_fd pipe_read, pipe_write;
@@ -77,9 +90,6 @@ TEST(debuggerd_client, race) {
  constexpr int PIPE_SIZE = 16 * 1024 * 1024;
  constexpr int PIPE_SIZE = 16 * 1024 * 1024;
  ASSERT_EQ(PIPE_SIZE, fcntl(pipe_read.get(), F_SETPIPE_SZ, PIPE_SIZE));
  ASSERT_EQ(PIPE_SIZE, fcntl(pipe_read.get(), F_SETPIPE_SZ, PIPE_SIZE));


  // Wait for a bit to let the child spawn all of its threads.
  std::this_thread::sleep_for(1s);

  ASSERT_TRUE(
  ASSERT_TRUE(
      debuggerd_trigger_dump(forkpid, kDebuggerdNativeBacktrace, 60000, std::move(pipe_write)));
      debuggerd_trigger_dump(forkpid, kDebuggerdNativeBacktrace, 60000, std::move(pipe_write)));
  // Immediately kill the forked child, to make sure that the dump didn't return early.
  // Immediately kill the forked child, to make sure that the dump didn't return early.