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

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

Issue 977003003: win: Add implementation of ProcessInfo (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: fixes2 Created 5 years, 9 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
(Empty)
1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "util/win/process_info.h"
16
17 #include <rpc.h>
18 #include <wchar.h>
19
20 #include "base/files/file_path.h"
21 #include "build/build_config.h"
22 #include "gtest/gtest.h"
23 #include "util/misc/uuid.h"
24 #include "util/test/executable_path.h"
25 #include "util/win/scoped_handle.h"
26
27 namespace crashpad {
28 namespace test {
29 namespace {
30
31 const wchar_t kNtdllName[] = L"\\ntdll.dll";
32
33 TEST(ProcessInfo, Self) {
34 ProcessInfo process_info;
35 ASSERT_TRUE(process_info.Initialize(GetCurrentProcess()));
36 EXPECT_EQ(GetCurrentProcessId(), process_info.ProcessID());
37 EXPECT_GT(process_info.ParentProcessID(), 0u);
38
39 #if defined(ARCH_CPU_64_BITS)
40 EXPECT_TRUE(process_info.Is64Bit());
41 EXPECT_FALSE(process_info.IsWow64());
42 #else
43 EXPECT_FALSE(process_info.Is64Bit());
44 // Assume we won't be running these tests on a 32 bit host OS.
45 EXPECT_TRUE(process_info.IsWow64());
46 #endif
47
48 std::wstring command_line;
49 EXPECT_TRUE(process_info.CommandLine(&command_line));
50 EXPECT_EQ(std::wstring(GetCommandLine()), command_line);
51
52 std::vector<std::wstring> modules;
53 EXPECT_TRUE(process_info.Modules(&modules));
54 ASSERT_GE(modules.size(), 2u);
55 const wchar_t kSelfName[] = L"\\util_test.exe";
56 ASSERT_GE(modules[0].size(), wcslen(kSelfName));
57 EXPECT_EQ(kSelfName,
58 modules[0].substr(modules[0].size() - wcslen(kSelfName)));
59 ASSERT_GE(modules[1].size(), wcslen(kNtdllName));
60 EXPECT_EQ(kNtdllName,
61 modules[1].substr(modules[1].size() - wcslen(kNtdllName)));
62 }
63
64 TEST(ProcessInfo, SomeOtherProcess) {
65 ProcessInfo process_info;
66
67 ::UUID system_uuid;
68 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid));
69 UUID started_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1));
70 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid));
71 UUID done_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1));
72
73 ScopedKernelHANDLE started(
74 CreateEvent(nullptr, true, false, started_uuid.ToString16().c_str()));
75 ASSERT_TRUE(started.get());
76 ScopedKernelHANDLE done(
77 CreateEvent(nullptr, true, false, done_uuid.ToString16().c_str()));
78 ASSERT_TRUE(done.get());
79
80 base::FilePath test_executable = ExecutablePath();
81 std::wstring child_test_executable =
82 test_executable.RemoveFinalExtension().value() +
83 L"_process_info_test_child.exe";
84 // TODO(scottmg): Command line escaping utility.
85 std::wstring command_line = child_test_executable + L" " +
86 started_uuid.ToString16() + L" " +
87 done_uuid.ToString16();
88 STARTUPINFO si = {0};
Mark Mentovai 2015/03/06 03:40:24 startup_info, process_info. That’ll make the argum
scottmg 2015/03/06 06:04:08 si/pi was a hacky way of avoiding conflict with Pr
89 si.cb = sizeof(si);
90 PROCESS_INFORMATION pi;
91 ASSERT_TRUE(CreateProcess(child_test_executable.c_str(),
92 &command_line[0],
93 nullptr,
94 nullptr,
95 false,
96 0,
97 nullptr,
98 nullptr,
99 &si,
100 &pi));
101 // Take ownership of the two process handles returned.
102 ScopedKernelHANDLE process_main_thread_handle(pi.hThread);
103 ScopedKernelHANDLE process_handle(pi.hProcess);
104
105 // Wait until the test has completed initialization.
106 ASSERT_EQ(WaitForSingleObject(started.get(), INFINITE), WAIT_OBJECT_0);
107
108 ASSERT_TRUE(process_info.Initialize(pi.hProcess));
109
110 // Tell the test it's OK to shut down now that we've read our data.
111 SetEvent(done.get());
112
113 std::vector<std::wstring> modules;
114 EXPECT_TRUE(process_info.Modules(&modules));
115 ASSERT_GE(modules.size(), 3u);
116 const wchar_t kChildName[] = L"\\util_test_process_info_test_child.exe";
117 ASSERT_GE(modules[0].size(), wcslen(kChildName));
118 EXPECT_EQ(kChildName,
119 modules[0].substr(modules[0].size() - wcslen(kChildName)));
120 ASSERT_GE(modules[1].size(), wcslen(kNtdllName));
121 EXPECT_EQ(kNtdllName,
122 modules[1].substr(modules[1].size() - wcslen(kNtdllName)));
123 // lz32.dll is an uncommonly-used-but-always-available module that the test
124 // binary manually loads.
125 const wchar_t kLz32dllName[] = L"\\lz32.dll";
126 ASSERT_GE(modules.back().size(), wcslen(kLz32dllName));
127 EXPECT_EQ(
128 kLz32dllName,
129 modules.back().substr(modules.back().size() - wcslen(kLz32dllName)));
130 }
131
132 } // namespace
133 } // namespace test
134 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698