Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: snapshot/win/process_reader_win_test.cc

Issue 1326443007: win: Fix incorrect thread suspend count due to ScopedProcessSuspend (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: assert some threads captured Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « snapshot/win/process_reader_win.cc ('k') | snapshot/win/process_snapshot_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Crashpad Authors. All rights reserved. 1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "snapshot/win/process_reader_win.h" 15 #include "snapshot/win/process_reader_win.h"
16 16
17 #include <string.h> 17 #include <string.h>
18 #include <windows.h> 18 #include <windows.h>
19 19
20 #include "gtest/gtest.h" 20 #include "gtest/gtest.h"
21 #include "test/win/win_multiprocess.h" 21 #include "test/win/win_multiprocess.h"
22 #include "util/win/scoped_process_suspend.h"
22 23
23 namespace crashpad { 24 namespace crashpad {
24 namespace test { 25 namespace test {
25 namespace { 26 namespace {
26 27
27 TEST(ProcessReaderWin, SelfBasic) { 28 TEST(ProcessReaderWin, SelfBasic) {
28 ProcessReaderWin process_reader; 29 ProcessReaderWin process_reader;
29 ASSERT_TRUE(process_reader.Initialize(GetCurrentProcess())); 30 ASSERT_TRUE(process_reader.Initialize(GetCurrentProcess(),
31 ProcessSuspensionState::kRunning));
30 32
31 #if !defined(ARCH_CPU_64_BITS) 33 #if !defined(ARCH_CPU_64_BITS)
32 EXPECT_FALSE(process_reader.Is64Bit()); 34 EXPECT_FALSE(process_reader.Is64Bit());
33 #else 35 #else
34 EXPECT_TRUE(process_reader.Is64Bit()); 36 EXPECT_TRUE(process_reader.Is64Bit());
35 #endif 37 #endif
36 38
37 EXPECT_EQ(GetCurrentProcessId(), process_reader.ProcessID()); 39 EXPECT_EQ(GetCurrentProcessId(), process_reader.ProcessID());
38 40
39 const char kTestMemory[] = "Some test memory"; 41 const char kTestMemory[] = "Some test memory";
40 char buffer[arraysize(kTestMemory)]; 42 char buffer[arraysize(kTestMemory)];
41 ASSERT_TRUE( 43 ASSERT_TRUE(
42 process_reader.ReadMemory(reinterpret_cast<uintptr_t>(kTestMemory), 44 process_reader.ReadMemory(reinterpret_cast<uintptr_t>(kTestMemory),
43 sizeof(kTestMemory), 45 sizeof(kTestMemory),
44 &buffer)); 46 &buffer));
45 EXPECT_STREQ(kTestMemory, buffer); 47 EXPECT_STREQ(kTestMemory, buffer);
46 } 48 }
47 49
48 const char kTestMemory[] = "Read me from another process"; 50 const char kTestMemory[] = "Read me from another process";
49 51
50 class ProcessReaderChild final : public WinMultiprocess { 52 class ProcessReaderChild final : public WinMultiprocess {
51 public: 53 public:
52 ProcessReaderChild() : WinMultiprocess() {} 54 ProcessReaderChild() : WinMultiprocess() {}
53 ~ProcessReaderChild() {} 55 ~ProcessReaderChild() {}
54 56
55 private: 57 private:
56 void WinMultiprocessParent() override { 58 void WinMultiprocessParent() override {
57 ProcessReaderWin process_reader; 59 ProcessReaderWin process_reader;
58 ASSERT_TRUE(process_reader.Initialize(ChildProcess())); 60 ASSERT_TRUE(process_reader.Initialize(ChildProcess(),
61 ProcessSuspensionState::kRunning));
59 62
60 #if !defined(ARCH_CPU_64_BITS) 63 #if !defined(ARCH_CPU_64_BITS)
61 EXPECT_FALSE(process_reader.Is64Bit()); 64 EXPECT_FALSE(process_reader.Is64Bit());
62 #else 65 #else
63 EXPECT_TRUE(process_reader.Is64Bit()); 66 EXPECT_TRUE(process_reader.Is64Bit());
64 #endif 67 #endif
65 68
66 WinVMAddress address; 69 WinVMAddress address;
67 CheckedReadFile(ReadPipeHandle(), &address, sizeof(address)); 70 CheckedReadFile(ReadPipeHandle(), &address, sizeof(address));
68 71
(...skipping 14 matching lines...) Expand all
83 86
84 DISALLOW_COPY_AND_ASSIGN(ProcessReaderChild); 87 DISALLOW_COPY_AND_ASSIGN(ProcessReaderChild);
85 }; 88 };
86 89
87 TEST(ProcessReaderWin, ChildBasic) { 90 TEST(ProcessReaderWin, ChildBasic) {
88 WinMultiprocess::Run<ProcessReaderChild>(); 91 WinMultiprocess::Run<ProcessReaderChild>();
89 } 92 }
90 93
91 TEST(ProcessReaderWin, SelfOneThread) { 94 TEST(ProcessReaderWin, SelfOneThread) {
92 ProcessReaderWin process_reader; 95 ProcessReaderWin process_reader;
93 ASSERT_TRUE(process_reader.Initialize(GetCurrentProcess())); 96 ASSERT_TRUE(process_reader.Initialize(GetCurrentProcess(),
97 ProcessSuspensionState::kRunning));
94 98
95 const std::vector<ProcessReaderWin::Thread>& threads = 99 const std::vector<ProcessReaderWin::Thread>& threads =
96 process_reader.Threads(); 100 process_reader.Threads();
97 101
98 // If other tests ran in this process previously, threads may have been 102 // If other tests ran in this process previously, threads may have been
99 // created and may still be running. This check must look for at least one 103 // created and may still be running. This check must look for at least one
100 // thread, not exactly one thread. 104 // thread, not exactly one thread.
101 ASSERT_GE(threads.size(), 1u); 105 ASSERT_GE(threads.size(), 1u);
102 106
103 EXPECT_EQ(GetThreadId(GetCurrentThread()), threads[0].id); 107 EXPECT_EQ(GetThreadId(GetCurrentThread()), threads[0].id);
104 #if defined(ARCH_CPU_64_BITS) 108 #if defined(ARCH_CPU_64_BITS)
105 EXPECT_NE(0, threads[0].context.Rip); 109 EXPECT_NE(0, threads[0].context.Rip);
106 #else 110 #else
107 EXPECT_NE(0u, threads[0].context.Eip); 111 EXPECT_NE(0u, threads[0].context.Eip);
108 #endif 112 #endif
109 113
110 EXPECT_EQ(0, threads[0].suspend_count); 114 EXPECT_EQ(0, threads[0].suspend_count);
111 } 115 }
112 116
117 class ProcessReaderChildThreadSuspendCount final : public WinMultiprocess {
118 public:
119 ProcessReaderChildThreadSuspendCount() : WinMultiprocess() {}
120 ~ProcessReaderChildThreadSuspendCount() {}
121
122 private:
123 void WinMultiprocessParent() override {
124 {
125 ProcessReaderWin process_reader;
126 ASSERT_TRUE(process_reader.Initialize(ChildProcess(),
127 ProcessSuspensionState::kRunning));
128
129 const auto& threads = process_reader.Threads();
130 ASSERT_FALSE(threads.empty());
131 for (const auto& thread : threads)
132 EXPECT_EQ(0u, thread.suspend_count);
133 }
134
135 {
136 ScopedProcessSuspend suspend(ChildProcess());
137
138 ProcessReaderWin process_reader;
139 ASSERT_TRUE(process_reader.Initialize(
140 ChildProcess(), ProcessSuspensionState::kSuspended));
141
142 // Confirm that thread counts are adjusted correctly for the process being
143 // suspended.
144 const auto& threads = process_reader.Threads();
145 ASSERT_FALSE(threads.empty());
146 for (const auto& thread : threads)
147 EXPECT_EQ(0u, thread.suspend_count);
148 }
149 }
150
151 void WinMultiprocessChild() override {
152 WinVMAddress address = reinterpret_cast<WinVMAddress>(kTestMemory);
153 CheckedWriteFile(WritePipeHandle(), &address, sizeof(address));
154
155 // Wait for the parent to signal that it's OK to exit by closing its end of
156 // the pipe.
157 CheckedReadFileAtEOF(ReadPipeHandle());
158 }
159
160 DISALLOW_COPY_AND_ASSIGN(ProcessReaderChildThreadSuspendCount);
161 };
162
163 TEST(ProcessReaderWin, ChildThreadSuspendCounts) {
164 WinMultiprocess::Run<ProcessReaderChildThreadSuspendCount>();
165 }
166
113 } // namespace 167 } // namespace
114 } // namespace test 168 } // namespace test
115 } // namespace crashpad 169 } // namespace crashpad
OLDNEW
« no previous file with comments | « snapshot/win/process_reader_win.cc ('k') | snapshot/win/process_snapshot_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698