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

Side by Side Diff: minidump/minidump_thread_id_map_test.cc

Issue 693933002: Add MinidumpThreadListWriter::InitializeFromSnapshot() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@minidump_init_from_snapshot_context_new
Patch Set: Created 6 years, 1 month 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_thread_id_map.h"
16
17 #include <vector>
18
19 #include "base/basictypes.h"
20 #include "gtest/gtest.h"
21 #include "snapshot/test/test_thread_snapshot.h"
22
23 namespace crashpad {
24 namespace test {
25 namespace {
26
27 bool MapHasKeyValue(
28 const MinidumpThreadIDMap* map, uint64_t key, uint32_t expected_value) {
29 auto iterator = map->find(key);
30 if (iterator == map->end()) {
31 EXPECT_NE(map->end(), iterator);
32 return false;
33 }
34 if (iterator->second != expected_value) {
35 EXPECT_EQ(expected_value, iterator->second);
36 return false;
37 }
38 return true;
39 }
40
41 TEST(MinidumpThreadIDMap, MinidumpThreadIDMap) {
42 std::vector<const ThreadSnapshot*> thread_snapshots;
43
44 MinidumpThreadIDMap thread_id_map;
45
46 // No threads to map.
47 BuildMinidumpThreadIDMap(thread_snapshots, &thread_id_map);
48
49 EXPECT_TRUE(thread_id_map.empty());
50
51 TestThreadSnapshot test_thread_snapshots[5] = {};
52
53 for (size_t index = 0; index < arraysize(test_thread_snapshots); ++index) {
54 thread_snapshots.push_back(&test_thread_snapshots[index]);
55 }
56
Robert Sesek 2014/11/04 15:34:58 Everything above this line could go in SetUp()
57 // A simple mapping.
Robert Sesek 2014/11/04 15:34:58 …and then each of these could be a TEST().
58 test_thread_snapshots[0].SetThreadID(1);
59 test_thread_snapshots[1].SetThreadID(3);
60 test_thread_snapshots[2].SetThreadID(5);
61 test_thread_snapshots[3].SetThreadID(7);
62 test_thread_snapshots[4].SetThreadID(9);
63
64 thread_id_map.clear();
65 BuildMinidumpThreadIDMap(thread_snapshots, &thread_id_map);
66
67 EXPECT_EQ(5u, thread_id_map.size());
68 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 1, 1);
69 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 3, 3);
70 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 5, 5);
71 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 7, 7);
72 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 9, 9);
73
74 // A mapping with some truncation.
75 test_thread_snapshots[0].SetThreadID(0x0000000000000000);
76 test_thread_snapshots[1].SetThreadID(0x9999999900000001);
77 test_thread_snapshots[2].SetThreadID(0x9999999980000001);
78 test_thread_snapshots[3].SetThreadID(0x99999999fffffffe);
79 test_thread_snapshots[4].SetThreadID(0x99999999ffffffff);
80
81 thread_id_map.clear();
82 BuildMinidumpThreadIDMap(thread_snapshots, &thread_id_map);
83
84 EXPECT_EQ(5u, thread_id_map.size());
85 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000000000000, 0x00000000);
86 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x9999999900000001, 0x00000001);
87 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x9999999980000001, 0x80000001);
88 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x99999999fffffffe, 0xfffffffe);
89 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x99999999ffffffff, 0xffffffff);
90
91 // A mapping where thread IDs are duplicated.
92 test_thread_snapshots[0].SetThreadID(2);
93 test_thread_snapshots[1].SetThreadID(4);
94 test_thread_snapshots[2].SetThreadID(4);
95 test_thread_snapshots[3].SetThreadID(6);
96 test_thread_snapshots[4].SetThreadID(8);
97
98 thread_id_map.clear();
99 BuildMinidumpThreadIDMap(thread_snapshots, &thread_id_map);
100
101 EXPECT_EQ(4u, thread_id_map.size());
102 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 2, 2);
103 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 4, 4);
104 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 6, 6);
105 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 8, 8);
106
107 // A mapping with a collision.
108 test_thread_snapshots[0].SetThreadID(0x0000000000000010);
109 test_thread_snapshots[1].SetThreadID(0x0000000000000020);
110 test_thread_snapshots[2].SetThreadID(0x0000000000000030);
111 test_thread_snapshots[3].SetThreadID(0x0000000000000040);
112 test_thread_snapshots[4].SetThreadID(0x0000000100000010);
113
114 thread_id_map.clear();
115 BuildMinidumpThreadIDMap(thread_snapshots, &thread_id_map);
116
117 EXPECT_EQ(5u, thread_id_map.size());
118 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000000000010, 0);
119 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000000000020, 1);
120 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000000000030, 2);
121 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000000000040, 3);
122 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000100000010, 4);
123
124 // A mapping with a collision and a duplicate thread ID.
125 test_thread_snapshots[0].SetThreadID(0x0000000100000010);
126 test_thread_snapshots[1].SetThreadID(0x0000000000000010);
127 test_thread_snapshots[2].SetThreadID(0x0000000000000020);
128 test_thread_snapshots[3].SetThreadID(0x0000000000000030);
129 test_thread_snapshots[4].SetThreadID(0x0000000000000020);
130
131 thread_id_map.clear();
132 BuildMinidumpThreadIDMap(thread_snapshots, &thread_id_map);
133
134 EXPECT_EQ(4u, thread_id_map.size());
135 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000100000010, 0);
136 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000000000010, 1);
137 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000000000020, 2);
138 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000000000030, 3);
139
140 // A mapping with nothing but duplicates.
141 test_thread_snapshots[0].SetThreadID(6);
142 test_thread_snapshots[1].SetThreadID(6);
143 test_thread_snapshots[2].SetThreadID(6);
144 test_thread_snapshots[3].SetThreadID(6);
145 test_thread_snapshots[4].SetThreadID(6);
146
147 thread_id_map.clear();
148 BuildMinidumpThreadIDMap(thread_snapshots, &thread_id_map);
149
150 EXPECT_EQ(1u, thread_id_map.size());
151 EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 6, 6);
152 }
153
154 } // namespace
155 } // namespace test
156 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698