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

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

Issue 1160843006: win: add a child ProcessReader test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: . Created 5 years, 6 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 | « no previous file | test/win/win_multiprocess.cc » ('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 <windows.h> 18 #include <windows.h>
18 19
19 #include "gtest/gtest.h" 20 #include "gtest/gtest.h"
21 #include "test/win/win_multiprocess.h"
20 22
21 namespace crashpad { 23 namespace crashpad {
22 namespace test { 24 namespace test {
23 namespace { 25 namespace {
24 26
25 TEST(ProcessReaderWin, SelfBasic) { 27 TEST(ProcessReaderWin, SelfBasic) {
26 ProcessReaderWin process_reader; 28 ProcessReaderWin process_reader;
27 ASSERT_TRUE(process_reader.Initialize(GetCurrentProcess())); 29 ASSERT_TRUE(process_reader.Initialize(GetCurrentProcess()));
28 30
29 #if !defined(ARCH_CPU_64_BITS) 31 #if !defined(ARCH_CPU_64_BITS)
30 EXPECT_FALSE(process_reader.Is64Bit()); 32 EXPECT_FALSE(process_reader.Is64Bit());
31 #else 33 #else
32 EXPECT_TRUE(process_reader.Is64Bit()); 34 EXPECT_TRUE(process_reader.Is64Bit());
33 #endif 35 #endif
34 36
35 EXPECT_EQ(GetCurrentProcessId(), process_reader.ProcessID()); 37 EXPECT_EQ(GetCurrentProcessId(), process_reader.ProcessID());
36 38
37 const char kTestMemory[] = "Some test memory"; 39 const char kTestMemory[] = "Some test memory";
38 char buffer[arraysize(kTestMemory)]; 40 char buffer[arraysize(kTestMemory)];
39 ASSERT_TRUE( 41 ASSERT_TRUE(
40 process_reader.ReadMemory(reinterpret_cast<uintptr_t>(kTestMemory), 42 process_reader.ReadMemory(reinterpret_cast<uintptr_t>(kTestMemory),
41 sizeof(kTestMemory), 43 sizeof(kTestMemory),
42 &buffer)); 44 &buffer));
43 EXPECT_STREQ(kTestMemory, buffer); 45 EXPECT_STREQ(kTestMemory, buffer);
44 } 46 }
45 47
48 const char kTestMemory[] = "Read me from another process";
49
50 class ProcessReaderChild final : public WinMultiprocess {
51 public:
52 ProcessReaderChild() : WinMultiprocess() {}
53 ~ProcessReaderChild() {}
54
55 private:
56 void WinMultiprocessParent() override {
57 ProcessReaderWin process_reader;
58 ASSERT_TRUE(process_reader.Initialize(ChildProcess()));
59
60 #if !defined(ARCH_CPU_64_BITS)
61 EXPECT_FALSE(process_reader.Is64Bit());
62 #else
63 EXPECT_TRUE(process_reader.Is64Bit());
64 #endif
65
66 WinVMAddress address;
67 CheckedReadFile(ReadPipeHandle(), &address, sizeof(address));
68
69 char buffer[sizeof(kTestMemory)];
70 ASSERT_TRUE(
71 process_reader.ReadMemory(address, sizeof(kTestMemory), &buffer));
72 EXPECT_EQ(0, strcmp(kTestMemory, buffer));
73 }
74
75 void WinMultiprocessChild() override {
76 WinVMAddress address = reinterpret_cast<WinVMAddress>(kTestMemory);
77 CheckedWriteFile(WritePipeHandle(), &address, sizeof(address));
78
79 // Wait for the parent to signal that it's OK to exit by closing its end of
80 // the pipe.
81 CheckedReadFileAtEOF(ReadPipeHandle());
82 }
83
84 DISALLOW_COPY_AND_ASSIGN(ProcessReaderChild);
85 };
86
87 TEST(ProcessReaderWin, ChildBasic) {
88 ProcessReaderChild process_reader_child;
89 process_reader_child.Run();
90 }
91
46 TEST(ProcessReaderWin, SelfOneThread) { 92 TEST(ProcessReaderWin, SelfOneThread) {
47 ProcessReaderWin process_reader; 93 ProcessReaderWin process_reader;
48 ASSERT_TRUE(process_reader.Initialize(GetCurrentProcess())); 94 ASSERT_TRUE(process_reader.Initialize(GetCurrentProcess()));
49 95
50 const std::vector<ProcessReaderWin::Thread>& threads = 96 const std::vector<ProcessReaderWin::Thread>& threads =
51 process_reader.Threads(); 97 process_reader.Threads();
52 98
53 // If other tests ran in this process previously, threads may have been 99 // If other tests ran in this process previously, threads may have been
54 // created and may still be running. This check must look for at least one 100 // created and may still be running. This check must look for at least one
55 // thread, not exactly one thread. 101 // thread, not exactly one thread.
56 ASSERT_GE(threads.size(), 1u); 102 ASSERT_GE(threads.size(), 1u);
57 103
58 EXPECT_EQ(GetThreadId(GetCurrentThread()), threads[0].id); 104 EXPECT_EQ(GetThreadId(GetCurrentThread()), threads[0].id);
59 #if defined(ARCH_CPU_64_BITS) 105 #if defined(ARCH_CPU_64_BITS)
60 EXPECT_NE(0, threads[0].context.Rip); 106 EXPECT_NE(0, threads[0].context.Rip);
61 #else 107 #else
62 EXPECT_NE(0, threads[0].context.Eip); 108 EXPECT_NE(0, threads[0].context.Eip);
63 #endif 109 #endif
64 110
65 EXPECT_EQ(0, threads[0].suspend_count); 111 EXPECT_EQ(0, threads[0].suspend_count);
66 } 112 }
67 113
68 } // namespace 114 } // namespace
69 } // namespace test 115 } // namespace test
70 } // namespace crashpad 116 } // namespace crashpad
OLDNEW
« no previous file with comments | « no previous file | test/win/win_multiprocess.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698