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

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: . 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 2014 The Crashpad Authors. All rights reserved.
Mark Mentovai 2015/03/05 17:32:23 2015 (I’ve been goofing this up a lot too, a PRESU
scottmg 2015/03/05 20:31:08 Done.
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 "gtest/gtest.h"
21 #include "util/misc/uuid.h"
22 #include "util/test/executable_path.h"
23
24 namespace crashpad {
25 namespace test {
26 namespace {
27
28 void TestSelfProcess(const ProcessInfo& process_info) {
Mark Mentovai 2015/03/05 17:32:23 Why don’t you just put this in-line into the TEST(
scottmg 2015/03/05 20:31:07 Done.
29 EXPECT_EQ(GetCurrentProcessId(), process_info.ProcessID());
30 EXPECT_GT(process_info.ParentProcessID(), 0u);
31
32 #if defined(ARCH_CPU_64_BITS)
Mark Mentovai 2015/03/05 17:32:23 #include "build/build_config.h"
scottmg 2015/03/05 20:31:07 Done.
33 EXPECT_TRUE(process_info.Is64Bit());
Mark Mentovai 2015/03/05 17:32:23 You can check that WoW64 is false here too.
scottmg 2015/03/05 20:31:07 Done.
34 #else
35 EXPECT_FALSE(process_info.Is64Bit());
36 // Assume we won't be running these tests on a 32 bit host OS.
37 EXPECT_TRUE(process_info.IsWow64());
38 #endif
39
40 std::wstring command_line;
41 EXPECT_TRUE(process_info.CommandLine(&command_line));
42 EXPECT_EQ(std::wstring(GetCommandLineW()), command_line);
Mark Mentovai 2015/03/05 17:32:23 Can’t you just use GetCommandLine() and let the SD
scottmg 2015/03/05 20:31:07 Done.
43
44 std::vector<std::wstring> modules;
45 EXPECT_TRUE(process_info.Modules(&modules));
46 ASSERT_GT(modules.size(), 0u);
47 EXPECT_EQ(L"ntdll.dll", modules[0].substr(modules[0].size() - 9));
Mark Mentovai 2015/03/05 17:32:23 Will the module name that shows up here always be
Mark Mentovai 2015/03/05 17:32:23 Not kosher unless you’ve checked that the size >=
scottmg 2015/03/05 20:31:07 Done.
scottmg 2015/03/05 20:31:07 Done.
48 }
49
50 TEST(ProcessInfo, Self) {
51 ProcessInfo process_info;
52 ASSERT_TRUE(process_info.Initialize(GetCurrentProcess()));
53 TestSelfProcess(process_info);
54 }
55
56 TEST(ProcessInfo, SomeOtherProcess) {
57 ProcessInfo process_info;
58
59 ::UUID system_uuid;
60 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid));
61 UUID started_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1));
62 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid));
63 UUID done_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1));
64
65 HANDLE started =
66 CreateEvent(nullptr, true, false, started_uuid.ToString16().c_str());
67 ASSERT_TRUE(started);
68 HANDLE done =
69 CreateEvent(nullptr, true, false, done_uuid.ToString16().c_str());
70 ASSERT_TRUE(done);
71
72 base::FilePath test_executable = ExecutablePath();
73 std::wstring child_test_executable =
74 test_executable.RemoveFinalExtension().value() +
75 L"_process_info_test_child.exe";
76 std::wstring command_line = child_test_executable + L" " +
Mark Mentovai 2015/03/05 17:32:23 Ideally we’d have a utility to properly escape com
scottmg 2015/03/05 20:31:07 TODO for now. At the moment it's just the two guid
77 started_uuid.ToString16() + L" " +
78 done_uuid.ToString16();
79 STARTUPINFO si = {0};
80 si.cb = sizeof(si);
81 PROCESS_INFORMATION pi;
82 ASSERT_TRUE(CreateProcess(child_test_executable.c_str(),
83 &command_line[0],
84 nullptr,
85 nullptr,
86 false,
87 0,
88 nullptr,
89 nullptr,
90 &si,
91 &pi));
92 ASSERT_EQ(WaitForSingleObject(started, INFINITE), WAIT_OBJECT_0);
93
94 ASSERT_TRUE(process_info.Initialize(pi.hProcess));
95
96 std::vector<std::wstring> modules;
97 EXPECT_TRUE(process_info.Modules(&modules));
98 ASSERT_GE(modules.size(), 2u);
99 EXPECT_EQ(L"ntdll.dll", modules[0].substr(modules[0].size() - 9));
Mark Mentovai 2015/03/05 17:32:23 Do you want to look for the main executable as wel
Mark Mentovai 2015/03/05 17:32:23 The same comments about wcslen() and checking the
scottmg 2015/03/05 20:31:07 The main executable doesn't appear in the list at
scottmg 2015/03/05 20:31:07 Done.
Mark Mentovai 2015/03/05 21:53:36 scottmg wrote:
100 EXPECT_EQ(L"lz32.dll", modules.back().substr(modules.back().size() - 8));
Mark Mentovai 2015/03/05 17:32:23 This was a surprise until I read the test file, bu
scottmg 2015/03/05 20:31:07 Done.
101
102 SetEvent(done);
103
104 CloseHandle(pi.hThread);
Mark Mentovai 2015/03/05 17:32:23 Scopers? There are ASSERTs in here that translate
scottmg 2015/03/05 20:31:07 Done.
105 CloseHandle(pi.hProcess);
106 CloseHandle(done);
107 CloseHandle(started);
108 }
109
110 } // namespace
111 } // namespace test
112 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698