OLD | NEW |
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, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 EXPECT_GT(modules[0].size, 0); | 96 EXPECT_GT(modules[0].size, 0); |
97 EXPECT_GT(modules[1].size, 0); | 97 EXPECT_GT(modules[1].size, 0); |
98 | 98 |
99 EXPECT_EQ(modules[0].timestamp, | 99 EXPECT_EQ(modules[0].timestamp, |
100 GetTimestampForModule(GetModuleHandle(nullptr))); | 100 GetTimestampForModule(GetModuleHandle(nullptr))); |
101 // System modules are forced to particular stamps and the file header values | 101 // System modules are forced to particular stamps and the file header values |
102 // don't match the on-disk times. Just make sure we got some data here. | 102 // don't match the on-disk times. Just make sure we got some data here. |
103 EXPECT_GT(modules[1].timestamp, 0); | 103 EXPECT_GT(modules[1].timestamp, 0); |
104 } | 104 } |
105 | 105 |
106 void TestOtherProcess(const std::wstring& child_name_suffix) { | 106 void TestOtherProcess(const base::string16& directory_modification) { |
107 ProcessInfo process_info; | 107 ProcessInfo process_info; |
108 | 108 |
109 ::UUID system_uuid; | 109 ::UUID system_uuid; |
110 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid)); | 110 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid)); |
111 UUID started_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1)); | 111 UUID started_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1)); |
112 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid)); | 112 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid)); |
113 UUID done_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1)); | 113 UUID done_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1)); |
114 | 114 |
115 ScopedKernelHANDLE started( | 115 ScopedKernelHANDLE started( |
116 CreateEvent(nullptr, true, false, started_uuid.ToString16().c_str())); | 116 CreateEvent(nullptr, true, false, started_uuid.ToString16().c_str())); |
117 ASSERT_TRUE(started.get()); | 117 ASSERT_TRUE(started.get()); |
118 ScopedKernelHANDLE done( | 118 ScopedKernelHANDLE done( |
119 CreateEvent(nullptr, true, false, done_uuid.ToString16().c_str())); | 119 CreateEvent(nullptr, true, false, done_uuid.ToString16().c_str())); |
120 ASSERT_TRUE(done.get()); | 120 ASSERT_TRUE(done.get()); |
121 | 121 |
122 base::FilePath test_executable = Paths::Executable(); | 122 base::FilePath test_executable = Paths::Executable(); |
| 123 |
123 std::wstring child_test_executable = | 124 std::wstring child_test_executable = |
124 test_executable.RemoveFinalExtension().value() + | 125 test_executable.DirName() |
125 L"_process_info_test_child_" + child_name_suffix + L".exe"; | 126 .Append(directory_modification) |
| 127 .Append(test_executable.BaseName().RemoveFinalExtension().value() + |
| 128 L"_process_info_test_child.exe") |
| 129 .value(); |
126 // TODO(scottmg): Command line escaping utility. | 130 // TODO(scottmg): Command line escaping utility. |
127 std::wstring command_line = child_test_executable + L" " + | 131 std::wstring command_line = child_test_executable + L" " + |
128 started_uuid.ToString16() + L" " + | 132 started_uuid.ToString16() + L" " + |
129 done_uuid.ToString16(); | 133 done_uuid.ToString16(); |
130 STARTUPINFO startup_info = {0}; | 134 STARTUPINFO startup_info = {0}; |
131 startup_info.cb = sizeof(startup_info); | 135 startup_info.cb = sizeof(startup_info); |
132 PROCESS_INFORMATION process_information; | 136 PROCESS_INFORMATION process_information; |
133 ASSERT_TRUE(CreateProcess(child_test_executable.c_str(), | 137 ASSERT_TRUE(CreateProcess(child_test_executable.c_str(), |
134 &command_line[0], | 138 &command_line[0], |
135 nullptr, | 139 nullptr, |
(...skipping 12 matching lines...) Expand all Loading... |
148 ASSERT_EQ(WaitForSingleObject(started.get(), INFINITE), WAIT_OBJECT_0); | 152 ASSERT_EQ(WaitForSingleObject(started.get(), INFINITE), WAIT_OBJECT_0); |
149 | 153 |
150 ASSERT_TRUE(process_info.Initialize(process_information.hProcess)); | 154 ASSERT_TRUE(process_info.Initialize(process_information.hProcess)); |
151 | 155 |
152 // Tell the test it's OK to shut down now that we've read our data. | 156 // Tell the test it's OK to shut down now that we've read our data. |
153 SetEvent(done.get()); | 157 SetEvent(done.get()); |
154 | 158 |
155 std::vector<ProcessInfo::Module> modules; | 159 std::vector<ProcessInfo::Module> modules; |
156 EXPECT_TRUE(process_info.Modules(&modules)); | 160 EXPECT_TRUE(process_info.Modules(&modules)); |
157 ASSERT_GE(modules.size(), 3u); | 161 ASSERT_GE(modules.size(), 3u); |
158 std::wstring child_name = L"\\crashpad_util_test_process_info_test_child_" + | 162 std::wstring child_name = L"\\crashpad_util_test_process_info_test_child.exe"; |
159 child_name_suffix + L".exe"; | |
160 ASSERT_GE(modules[0].name.size(), child_name.size()); | 163 ASSERT_GE(modules[0].name.size(), child_name.size()); |
161 EXPECT_EQ(child_name, | 164 EXPECT_EQ(child_name, |
162 modules[0].name.substr(modules[0].name.size() - child_name.size())); | 165 modules[0].name.substr(modules[0].name.size() - child_name.size())); |
163 ASSERT_GE(modules[1].name.size(), wcslen(kNtdllName)); | 166 ASSERT_GE(modules[1].name.size(), wcslen(kNtdllName)); |
164 EXPECT_EQ( | 167 EXPECT_EQ( |
165 kNtdllName, | 168 kNtdllName, |
166 modules[1].name.substr(modules[1].name.size() - wcslen(kNtdllName))); | 169 modules[1].name.substr(modules[1].name.size() - wcslen(kNtdllName))); |
167 // lz32.dll is an uncommonly-used-but-always-available module that the test | 170 // lz32.dll is an uncommonly-used-but-always-available module that the test |
168 // binary manually loads. | 171 // binary manually loads. |
169 const wchar_t kLz32dllName[] = L"\\lz32.dll"; | 172 const wchar_t kLz32dllName[] = L"\\lz32.dll"; |
170 ASSERT_GE(modules.back().name.size(), wcslen(kLz32dllName)); | 173 ASSERT_GE(modules.back().name.size(), wcslen(kLz32dllName)); |
171 EXPECT_EQ(kLz32dllName, | 174 EXPECT_EQ(kLz32dllName, |
172 modules.back().name.substr(modules.back().name.size() - | 175 modules.back().name.substr(modules.back().name.size() - |
173 wcslen(kLz32dllName))); | 176 wcslen(kLz32dllName))); |
174 } | 177 } |
175 | 178 |
176 // This test can't run the child if the host OS is x86, and can't read from the | 179 TEST(ProcessInfo, OtherProcess) { |
177 // child if it is x86 and the child is x64, so it only makes sense to run this | 180 TestOtherProcess(FILE_PATH_LITERAL(".")); |
178 // if we built as x64. | 181 } |
| 182 |
179 #if defined(ARCH_CPU_64_BITS) | 183 #if defined(ARCH_CPU_64_BITS) |
180 TEST(ProcessInfo, OtherProcessX64) { | 184 TEST(ProcessInfo, OtherProcessWOW64) { |
181 TestOtherProcess(L"x64"); | 185 #ifndef NDEBUG |
| 186 TestOtherProcess(FILE_PATH_LITERAL("..\\..\\out\\Debug")); |
| 187 #else |
| 188 TestOtherProcess(FILE_PATH_LITERAL("..\\..\\out\\Release")); |
| 189 #endif |
182 } | 190 } |
183 #endif // ARCH_CPU_64_BITS | 191 #endif // ARCH_CPU_64_BITS |
184 | 192 |
185 TEST(ProcessInfo, OtherProcessX86) { | |
186 TestOtherProcess(L"x86"); | |
187 } | |
188 | |
189 } // namespace | 193 } // namespace |
190 } // namespace test | 194 } // namespace test |
191 } // namespace crashpad | 195 } // namespace crashpad |
OLD | NEW |