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

Side by Side Diff: util/win/process_info_test.cc

Issue 1052813002: win: make CrashpadInfo retrievable (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: . Created 5 years, 7 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
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 "util/win/process_info.h" 15 #include "util/win/process_info.h"
16 16
17 #include <rpc.h> 17 #include <rpc.h>
18 #include <wchar.h> 18 #include <wchar.h>
19 19
20 #include "base/files/file_path.h" 20 #include "base/files/file_path.h"
21 #include "build/build_config.h" 21 #include "build/build_config.h"
22 #include "gtest/gtest.h" 22 #include "gtest/gtest.h"
23 #include "test/paths.h" 23 #include "test/paths.h"
24 #include "util/file/file_io.h"
24 #include "util/misc/uuid.h" 25 #include "util/misc/uuid.h"
25 #include "util/win/scoped_handle.h" 26 #include "util/win/scoped_handle.h"
26 27
27 namespace crashpad { 28 namespace crashpad {
28 namespace test { 29 namespace test {
29 namespace { 30 namespace {
30 31
31 const wchar_t kNtdllName[] = L"\\ntdll.dll"; 32 const wchar_t kNtdllName[] = L"\\ntdll.dll";
32 33
34 time_t GetTimestampForModule(HMODULE module) {
35 wchar_t filename[_MAX_PATH];
Mark Mentovai 2015/04/30 20:58:36 I wasn’t familiar with _MAX_PATH with an underscor
scottmg 2015/04/30 22:09:44 Done.
36 if (!GetModuleFileName(module, filename, sizeof(filename)))
Mark Mentovai 2015/04/30 20:58:36 arraysize, not sizeof?
scottmg 2015/04/30 22:09:44 Oops!
37 return 0;
38 struct _stat stat_buf;
39 int rv = _wstat(filename, &stat_buf);
40 if (rv != 0)
41 return 0;
Mark Mentovai 2015/04/30 20:58:36 EXPECT_EQ(0, rv) also to make sure that gtest sees
scottmg 2015/04/30 22:09:44 Done.
42 return stat_buf.st_mtime;
43 }
44
33 TEST(ProcessInfo, Self) { 45 TEST(ProcessInfo, Self) {
34 ProcessInfo process_info; 46 ProcessInfo process_info;
35 ASSERT_TRUE(process_info.Initialize(GetCurrentProcess())); 47 ASSERT_TRUE(process_info.Initialize(GetCurrentProcess()));
36 EXPECT_EQ(GetCurrentProcessId(), process_info.ProcessID()); 48 EXPECT_EQ(GetCurrentProcessId(), process_info.ProcessID());
37 EXPECT_GT(process_info.ParentProcessID(), 0u); 49 EXPECT_GT(process_info.ParentProcessID(), 0u);
38 50
39 #if defined(ARCH_CPU_64_BITS) 51 #if defined(ARCH_CPU_64_BITS)
40 EXPECT_TRUE(process_info.Is64Bit()); 52 EXPECT_TRUE(process_info.Is64Bit());
41 EXPECT_FALSE(process_info.IsWow64()); 53 EXPECT_FALSE(process_info.IsWow64());
42 #else 54 #else
43 EXPECT_FALSE(process_info.Is64Bit()); 55 EXPECT_FALSE(process_info.Is64Bit());
44 // Assume we won't be running these tests on a 32 bit host OS. 56 // Assume we won't be running these tests on a 32 bit host OS.
45 EXPECT_TRUE(process_info.IsWow64()); 57 EXPECT_TRUE(process_info.IsWow64());
46 #endif 58 #endif
47 59
48 std::wstring command_line; 60 std::wstring command_line;
49 EXPECT_TRUE(process_info.CommandLine(&command_line)); 61 EXPECT_TRUE(process_info.CommandLine(&command_line));
50 EXPECT_EQ(std::wstring(GetCommandLine()), command_line); 62 EXPECT_EQ(std::wstring(GetCommandLine()), command_line);
51 63
52 std::vector<std::wstring> modules; 64 std::vector<ProcessInfo::Module> modules;
53 EXPECT_TRUE(process_info.Modules(&modules)); 65 EXPECT_TRUE(process_info.Modules(&modules));
54 ASSERT_GE(modules.size(), 2u); 66 ASSERT_GE(modules.size(), 2u);
55 const wchar_t kSelfName[] = L"\\crashpad_util_test.exe"; 67 const wchar_t kSelfName[] = L"\\crashpad_util_test.exe";
56 ASSERT_GE(modules[0].size(), wcslen(kSelfName)); 68 ASSERT_GE(modules[0].name.size(), wcslen(kSelfName));
57 EXPECT_EQ(kSelfName, 69 EXPECT_EQ(kSelfName,
58 modules[0].substr(modules[0].size() - wcslen(kSelfName))); 70 modules[0].name.substr(modules[0].name.size() - wcslen(kSelfName)));
59 ASSERT_GE(modules[1].size(), wcslen(kNtdllName)); 71 ASSERT_GE(modules[1].name.size(), wcslen(kNtdllName));
60 EXPECT_EQ(kNtdllName, 72 EXPECT_EQ(
61 modules[1].substr(modules[1].size() - wcslen(kNtdllName))); 73 kNtdllName,
74 modules[1].name.substr(modules[1].name.size() - wcslen(kNtdllName)));
75
76 EXPECT_EQ(modules[0].dll_base,
77 reinterpret_cast<uintptr_t>(GetModuleHandle(nullptr)));
78 EXPECT_EQ(modules[1].dll_base,
79 reinterpret_cast<uintptr_t>(GetModuleHandle(L"ntdll.dll")));
80
81 EXPECT_GT(modules[0].size, 0);
82 EXPECT_GT(modules[1].size, 0);
83
84 EXPECT_EQ(modules[0].timestamp,
85 GetTimestampForModule(GetModuleHandle(nullptr)));
86 // System modules are forced to particular stamps and the file header values
87 // don't match the on-disk times. Just make sure we got some data here.
88 EXPECT_GT(modules[1].timestamp, 0);
62 } 89 }
63 90
64 void TestOtherProcess(const std::wstring& child_name_suffix) { 91 void TestOtherProcess(const std::wstring& child_name_suffix) {
65 ProcessInfo process_info; 92 ProcessInfo process_info;
66 93
67 ::UUID system_uuid; 94 ::UUID system_uuid;
68 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid)); 95 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid));
69 UUID started_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1)); 96 UUID started_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1));
70 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid)); 97 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid));
71 UUID done_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1)); 98 UUID done_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 ScopedKernelHANDLE process_handle(process_information.hProcess); 130 ScopedKernelHANDLE process_handle(process_information.hProcess);
104 131
105 // Wait until the test has completed initialization. 132 // Wait until the test has completed initialization.
106 ASSERT_EQ(WaitForSingleObject(started.get(), INFINITE), WAIT_OBJECT_0); 133 ASSERT_EQ(WaitForSingleObject(started.get(), INFINITE), WAIT_OBJECT_0);
107 134
108 ASSERT_TRUE(process_info.Initialize(process_information.hProcess)); 135 ASSERT_TRUE(process_info.Initialize(process_information.hProcess));
109 136
110 // Tell the test it's OK to shut down now that we've read our data. 137 // Tell the test it's OK to shut down now that we've read our data.
111 SetEvent(done.get()); 138 SetEvent(done.get());
112 139
113 std::vector<std::wstring> modules; 140 std::vector<ProcessInfo::Module> modules;
114 EXPECT_TRUE(process_info.Modules(&modules)); 141 EXPECT_TRUE(process_info.Modules(&modules));
115 ASSERT_GE(modules.size(), 3u); 142 ASSERT_GE(modules.size(), 3u);
116 std::wstring child_name = L"\\crashpad_util_test_process_info_test_child_" + 143 std::wstring child_name = L"\\crashpad_util_test_process_info_test_child_" +
117 child_name_suffix + L".exe"; 144 child_name_suffix + L".exe";
118 ASSERT_GE(modules[0].size(), child_name.size()); 145 ASSERT_GE(modules[0].name.size(), child_name.size());
119 EXPECT_EQ(child_name, 146 EXPECT_EQ(child_name,
120 modules[0].substr(modules[0].size() - child_name.size())); 147 modules[0].name.substr(modules[0].name.size() - child_name.size()));
121 ASSERT_GE(modules[1].size(), wcslen(kNtdllName)); 148 ASSERT_GE(modules[1].name.size(), wcslen(kNtdllName));
122 EXPECT_EQ(kNtdllName, 149 EXPECT_EQ(
123 modules[1].substr(modules[1].size() - wcslen(kNtdllName))); 150 kNtdllName,
151 modules[1].name.substr(modules[1].name.size() - wcslen(kNtdllName)));
124 // lz32.dll is an uncommonly-used-but-always-available module that the test 152 // lz32.dll is an uncommonly-used-but-always-available module that the test
125 // binary manually loads. 153 // binary manually loads.
126 const wchar_t kLz32dllName[] = L"\\lz32.dll"; 154 const wchar_t kLz32dllName[] = L"\\lz32.dll";
127 ASSERT_GE(modules.back().size(), wcslen(kLz32dllName)); 155 ASSERT_GE(modules.back().name.size(), wcslen(kLz32dllName));
128 EXPECT_EQ( 156 EXPECT_EQ(kLz32dllName,
129 kLz32dllName, 157 modules.back().name.substr(modules.back().name.size() -
130 modules.back().substr(modules.back().size() - wcslen(kLz32dllName))); 158 wcslen(kLz32dllName)));
131 } 159 }
132 160
133 TEST(ProcessInfo, OtherProcessX64) { 161 TEST(ProcessInfo, OtherProcessX64) {
134 TestOtherProcess(L"x64"); 162 TestOtherProcess(L"x64");
135 } 163 }
136 164
137 TEST(ProcessInfo, OtherProcessX86) { 165 TEST(ProcessInfo, OtherProcessX86) {
138 TestOtherProcess(L"x86"); 166 TestOtherProcess(L"x86");
139 } 167 }
140 168
141 } // namespace 169 } // namespace
142 } // namespace test 170 } // namespace test
143 } // namespace crashpad 171 } // namespace crashpad
OLDNEW
« util/numeric/checked_address_range.h ('K') | « util/win/process_info.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698