| Index: snapshot/win/process_reader_win_test.cc
|
| diff --git a/snapshot/win/process_reader_win_test.cc b/snapshot/win/process_reader_win_test.cc
|
| index 1cb4bdda51ad37efe98fdc25f256adaf9cbcf352..9e2e52cd6a9ceb9e1bd4ce1d560d3ecbccabf7c8 100644
|
| --- a/snapshot/win/process_reader_win_test.cc
|
| +++ b/snapshot/win/process_reader_win_test.cc
|
| @@ -19,6 +19,8 @@
|
|
|
| #include "gtest/gtest.h"
|
| #include "test/win/win_multiprocess.h"
|
| +#include "util/synchronization/semaphore.h"
|
| +#include "util/thread/thread.h"
|
| #include "util/win/scoped_process_suspend.h"
|
|
|
| namespace crashpad {
|
| @@ -104,7 +106,7 @@ TEST(ProcessReaderWin, SelfOneThread) {
|
| // thread, not exactly one thread.
|
| ASSERT_GE(threads.size(), 1u);
|
|
|
| - EXPECT_EQ(GetThreadId(GetCurrentThread()), threads[0].id);
|
| + EXPECT_EQ(GetCurrentThreadId(), threads[0].id);
|
| #if defined(ARCH_CPU_64_BITS)
|
| EXPECT_NE(0, threads[0].context.Rip);
|
| #else
|
| @@ -120,14 +122,36 @@ class ProcessReaderChildThreadSuspendCount final : public WinMultiprocess {
|
| ~ProcessReaderChildThreadSuspendCount() {}
|
|
|
| private:
|
| + enum : unsigned int { kCreatedThreads = 3 };
|
| +
|
| + class SleepingThread : public Thread {
|
| + public:
|
| + SleepingThread() : done_(nullptr) {}
|
| +
|
| + void SetHandle(Semaphore* done) {
|
| + done_= done;
|
| + }
|
| +
|
| + void ThreadMain() override {
|
| + done_->Wait();
|
| + };
|
| +
|
| + private:
|
| + Semaphore* done_;
|
| + };
|
| +
|
| void WinMultiprocessParent() override {
|
| + char c;
|
| + CheckedReadFile(ReadPipeHandle(), &c, sizeof(c));
|
| + ASSERT_EQ(' ', c);
|
| +
|
| {
|
| ProcessReaderWin process_reader;
|
| ASSERT_TRUE(process_reader.Initialize(ChildProcess(),
|
| ProcessSuspensionState::kRunning));
|
|
|
| const auto& threads = process_reader.Threads();
|
| - ASSERT_FALSE(threads.empty());
|
| + ASSERT_GE(threads.size(), kCreatedThreads + 1);
|
| for (const auto& thread : threads)
|
| EXPECT_EQ(0u, thread.suspend_count);
|
| }
|
| @@ -142,19 +166,33 @@ class ProcessReaderChildThreadSuspendCount final : public WinMultiprocess {
|
| // Confirm that thread counts are adjusted correctly for the process being
|
| // suspended.
|
| const auto& threads = process_reader.Threads();
|
| - ASSERT_FALSE(threads.empty());
|
| + ASSERT_GE(threads.size(), kCreatedThreads + 1);
|
| for (const auto& thread : threads)
|
| EXPECT_EQ(0u, thread.suspend_count);
|
| }
|
| }
|
|
|
| void WinMultiprocessChild() override {
|
| - WinVMAddress address = reinterpret_cast<WinVMAddress>(kTestMemory);
|
| - CheckedWriteFile(WritePipeHandle(), &address, sizeof(address));
|
| + // Create three dummy threads so we can confirm we read successfully read
|
| + // more than just the main thread.
|
| + SleepingThread threads[kCreatedThreads];
|
| + Semaphore done(0);
|
| + for (auto& thread : threads)
|
| + thread.SetHandle(&done);
|
| + for (auto& thread : threads)
|
| + thread.Start();
|
| +
|
| + char c = ' ';
|
| + CheckedWriteFile(WritePipeHandle(), &c, sizeof(c));
|
|
|
| // Wait for the parent to signal that it's OK to exit by closing its end of
|
| // the pipe.
|
| CheckedReadFileAtEOF(ReadPipeHandle());
|
| +
|
| + for (int i = 0; i < arraysize(threads); ++i)
|
| + done.Signal();
|
| + for (auto& thread : threads)
|
| + thread.Join();
|
| }
|
|
|
| DISALLOW_COPY_AND_ASSIGN(ProcessReaderChildThreadSuspendCount);
|
|
|