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

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: fixes 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
19 #include "base/files/file_path.h"
20 #include "build/build_config.h"
21 #include "gtest/gtest.h"
22 #include "util/misc/uuid.h"
23 #include "util/test/executable_path.h"
24 #include "util/win/scoped_handle.h"
25
26 namespace crashpad {
27 namespace test {
28 namespace {
29
30 const wchar_t kNtdllName[] = L"\\ntdll.dll";
31
32 TEST(ProcessInfo, Self) {
33 ProcessInfo process_info;
34 ASSERT_TRUE(process_info.Initialize(GetCurrentProcess()));
35 EXPECT_EQ(GetCurrentProcessId(), process_info.ProcessID());
36 EXPECT_GT(process_info.ParentProcessID(), 0u);
37
38 #if defined(ARCH_CPU_64_BITS)
39 EXPECT_TRUE(process_info.Is64Bit());
40 EXPECT_FALSE(process_info.IsWow64());
41 #else
42 EXPECT_FALSE(process_info.Is64Bit());
43 // Assume we won't be running these tests on a 32 bit host OS.
44 EXPECT_TRUE(process_info.IsWow64());
45 #endif
46
47 std::wstring command_line;
48 EXPECT_TRUE(process_info.CommandLine(&command_line));
49 EXPECT_EQ(std::wstring(GetCommandLine()), command_line);
50
51 std::vector<std::wstring> modules;
52 EXPECT_TRUE(process_info.Modules(&modules));
53 ASSERT_GT(modules.size(), 0u);
54 ASSERT_GE(modules[0].size(), wcslen(kNtdllName));
Mark Mentovai 2015/03/05 21:53:36 #include <wchar.h>.
scottmg 2015/03/06 00:42:52 Done.
55 EXPECT_EQ(kNtdllName,
56 modules[0].substr(modules[0].size() - wcslen(kNtdllName)));
57 }
58
59 TEST(ProcessInfo, SomeOtherProcess) {
60 ProcessInfo process_info;
61
62 ::UUID system_uuid;
63 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid));
64 UUID started_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1));
65 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid));
66 UUID done_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1));
67
68 ScopedKernelHANDLE started(
69 CreateEvent(nullptr, true, false, started_uuid.ToString16().c_str()));
70 ASSERT_TRUE(started.get());
71 ScopedKernelHANDLE done(
72 CreateEvent(nullptr, true, false, done_uuid.ToString16().c_str()));
73 ASSERT_TRUE(done.get());
74
75 base::FilePath test_executable = ExecutablePath();
76 std::wstring child_test_executable =
77 test_executable.RemoveFinalExtension().value() +
78 L"_process_info_test_child.exe";
79 // TODO(scottmg): Command line escaping utility.
80 std::wstring command_line = child_test_executable + L" " +
81 started_uuid.ToString16() + L" " +
82 done_uuid.ToString16();
83 STARTUPINFO si = {0};
84 si.cb = sizeof(si);
85 PROCESS_INFORMATION pi;
86 ASSERT_TRUE(CreateProcess(child_test_executable.c_str(),
87 &command_line[0],
88 nullptr,
89 nullptr,
90 false,
91 0,
92 nullptr,
93 nullptr,
94 &si,
95 &pi));
96 // Take ownership of the two process handles returned.
97 ScopedKernelHANDLE process_main_thread_handle(pi.hThread);
98 ScopedKernelHANDLE process_handle(pi.hProcess);
99
100 // Wait until the test has completed initialization.
101 ASSERT_EQ(WaitForSingleObject(started.get(), INFINITE), WAIT_OBJECT_0);
102
103 ASSERT_TRUE(process_info.Initialize(pi.hProcess));
104
105 // Tell the test it's OK to shut down now that we've read our data.
106 SetEvent(done.get());
107
108 std::vector<std::wstring> modules;
109 EXPECT_TRUE(process_info.Modules(&modules));
110 ASSERT_GE(modules.size(), 2u);
111 ASSERT_GE(modules[0].size(), wcslen(kNtdllName));
112 EXPECT_EQ(kNtdllName,
113 modules[0].substr(modules[0].size() - wcslen(kNtdllName)));
114 // lz32.dll is an uncommonly-used-but-always-available module that the test
115 // binary manually loads.
116 const wchar_t kLz32dllName[] = L"\\lz32.dll";
117 ASSERT_GE(modules.back().size(), wcslen(kLz32dllName));
118 EXPECT_EQ(
119 kLz32dllName,
120 modules.back().substr(modules.back().size() - wcslen(kLz32dllName)));
121 }
122
123 } // namespace
124 } // namespace test
125 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698