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

Side by Side Diff: snapshot/api/module_annotations_win_test.cc

Issue 1586433003: Adding an API to read module annotations in snapshot.gyp (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Last comments Created 4 years, 11 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 2016 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 "snapshot/api/module_annotations_win.h"
16
17 #include "client/crashpad_info.h"
18 #include "gtest/gtest.h"
19 #include "test/win/win_multiprocess.h"
20 #include "util/file/file_io.h"
21
22 namespace crashpad {
23 namespace test {
24 namespace {
25
26 class ModuleAnnotationsMultiprocessTest final : public WinMultiprocess {
27 private:
28 void WinMultiprocessParent() override {
29 // Read the child executable module.
30 HMODULE module = nullptr;
31 CheckedReadFile(ReadPipeHandle(), &module, sizeof(module));
32
33 // Reopen the child process with necessary access.
34 HANDLE process_handle =
35 OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
36 FALSE,
37 GetProcessId(ChildProcess()));
38 EXPECT_TRUE(process_handle);
39
40 // Read the module annotations in the child process and verify them.
41 std::map<std::string, std::string> annotations;
42 ASSERT_TRUE(ReadModuleAnnotations(process_handle, module, &annotations));
43
44 EXPECT_GE(annotations.size(), 3u);
45 EXPECT_EQ("value", annotations["#APITEST# key"]);
46 EXPECT_EQ("y", annotations["#APITEST# x"]);
47 EXPECT_EQ("", annotations["#APITEST# empty_value"]);
48
49 // Signal the child process to terminate.
50 char c = ' ';
51 CheckedWriteFile(WritePipeHandle(), &c, sizeof(c));
52 }
53
54 void WinMultiprocessChild() override {
55 // Set some test annotations.
56 crashpad::CrashpadInfo* crashpad_info =
57 crashpad::CrashpadInfo::GetCrashpadInfo();
58
59 crashpad::SimpleStringDictionary* simple_annotations =
60 new crashpad::SimpleStringDictionary();
61 simple_annotations->SetKeyValue("#APITEST# key", "value");
62 simple_annotations->SetKeyValue("#APITEST# x", "y");
63 simple_annotations->SetKeyValue("#APITEST# empty_value", "");
64
65 crashpad_info->set_simple_annotations(simple_annotations);
66
67 // Send the executable module.
68 HMODULE module = GetModuleHandle(nullptr);
69 CheckedWriteFile(WritePipeHandle(), &module, sizeof(module));
70
71 // Wait until a signal from the parent process to terminate.
72 char c;
73 CheckedReadFile(ReadPipeHandle(), &c, sizeof(c));
74 }
75 };
76
77 TEST(ModuleAnnotationsWin, ReadAnnotations) {
78 WinMultiprocess::Run<ModuleAnnotationsMultiprocessTest>();
79 }
80
81 } // namespace
82 } // namespace test
83 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698