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

Side by Side Diff: third_party/crashpad/crashpad/minidump/minidump_context_writer_test.cc

Issue 1505213004: Copy Crashpad into the Chrome tree instead of importing it via DEPS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments, update README.chromium Created 5 years 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.
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 "minidump/minidump_context_writer.h"
16
17 #include <stdint.h>
18
19 #include "gtest/gtest.h"
20 #include "minidump/minidump_context.h"
21 #include "minidump/test/minidump_context_test_util.h"
22 #include "minidump/test/minidump_writable_test_util.h"
23 #include "snapshot/cpu_context.h"
24 #include "snapshot/test/test_cpu_context.h"
25 #include "util/file/string_file.h"
26
27 namespace crashpad {
28 namespace test {
29 namespace {
30
31 TEST(MinidumpContextWriter, MinidumpContextX86Writer) {
32 StringFile string_file;
33
34 {
35 // Make sure that a context writer that’s untouched writes a zeroed-out
36 // context.
37 SCOPED_TRACE("zero");
38
39 MinidumpContextX86Writer context_writer;
40
41 EXPECT_TRUE(context_writer.WriteEverything(&string_file));
42 ASSERT_EQ(sizeof(MinidumpContextX86), string_file.string().size());
43
44 const MinidumpContextX86* observed =
45 MinidumpWritableAtRVA<MinidumpContextX86>(string_file.string(), 0);
46 ASSERT_TRUE(observed);
47
48 ExpectMinidumpContextX86(0, observed, false);
49 }
50
51 {
52 SCOPED_TRACE("nonzero");
53
54 string_file.Reset();
55 const uint32_t kSeed = 0x8086;
56
57 MinidumpContextX86Writer context_writer;
58 InitializeMinidumpContextX86(context_writer.context(), kSeed);
59
60 EXPECT_TRUE(context_writer.WriteEverything(&string_file));
61 ASSERT_EQ(sizeof(MinidumpContextX86), string_file.string().size());
62
63 const MinidumpContextX86* observed =
64 MinidumpWritableAtRVA<MinidumpContextX86>(string_file.string(), 0);
65 ASSERT_TRUE(observed);
66
67 ExpectMinidumpContextX86(kSeed, observed, false);
68 }
69 }
70
71 TEST(MinidumpContextWriter, MinidumpContextAMD64Writer) {
72 StringFile string_file;
73
74 {
75 // Make sure that a context writer that’s untouched writes a zeroed-out
76 // context.
77 SCOPED_TRACE("zero");
78
79 MinidumpContextAMD64Writer context_writer;
80
81 EXPECT_TRUE(context_writer.WriteEverything(&string_file));
82 ASSERT_EQ(sizeof(MinidumpContextAMD64), string_file.string().size());
83
84 const MinidumpContextAMD64* observed =
85 MinidumpWritableAtRVA<MinidumpContextAMD64>(string_file.string(), 0);
86 ASSERT_TRUE(observed);
87
88 ExpectMinidumpContextAMD64(0, observed, false);
89 }
90
91 {
92 SCOPED_TRACE("nonzero");
93
94 string_file.Reset();
95 const uint32_t kSeed = 0x808664;
96
97 MinidumpContextAMD64Writer context_writer;
98 InitializeMinidumpContextAMD64(context_writer.context(), kSeed);
99
100 EXPECT_TRUE(context_writer.WriteEverything(&string_file));
101 ASSERT_EQ(sizeof(MinidumpContextAMD64), string_file.string().size());
102
103 const MinidumpContextAMD64* observed =
104 MinidumpWritableAtRVA<MinidumpContextAMD64>(string_file.string(), 0);
105 ASSERT_TRUE(observed);
106
107 ExpectMinidumpContextAMD64(kSeed, observed, false);
108 }
109 }
110
111 TEST(MinidumpContextWriter, CreateFromSnapshot_X86) {
112 const uint32_t kSeed = 32;
113
114 CPUContextX86 context_snapshot_x86;
115 CPUContext context_snapshot;
116 context_snapshot.x86 = &context_snapshot_x86;
117 InitializeCPUContextX86(&context_snapshot, kSeed);
118
119 scoped_ptr<MinidumpContextWriter> context_writer =
120 MinidumpContextWriter::CreateFromSnapshot(&context_snapshot);
121 ASSERT_TRUE(context_writer);
122
123 StringFile string_file;
124 ASSERT_TRUE(context_writer->WriteEverything(&string_file));
125
126 const MinidumpContextX86* observed =
127 MinidumpWritableAtRVA<MinidumpContextX86>(string_file.string(), 0);
128 ASSERT_TRUE(observed);
129
130 ExpectMinidumpContextX86(kSeed, observed, true);
131 }
132
133 TEST(MinidumpContextWriter, CreateFromSnapshot_AMD64) {
134 const uint32_t kSeed = 64;
135
136 CPUContextX86_64 context_snapshot_x86_64;
137 CPUContext context_snapshot;
138 context_snapshot.x86_64 = &context_snapshot_x86_64;
139 InitializeCPUContextX86_64(&context_snapshot, kSeed);
140
141 scoped_ptr<MinidumpContextWriter> context_writer =
142 MinidumpContextWriter::CreateFromSnapshot(&context_snapshot);
143 ASSERT_TRUE(context_writer);
144
145 StringFile string_file;
146 ASSERT_TRUE(context_writer->WriteEverything(&string_file));
147
148 const MinidumpContextAMD64* observed =
149 MinidumpWritableAtRVA<MinidumpContextAMD64>(string_file.string(), 0);
150 ASSERT_TRUE(observed);
151
152 ExpectMinidumpContextAMD64(kSeed, observed, true);
153 }
154
155 } // namespace
156 } // namespace test
157 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698