Chromium Code Reviews| Index: minidump/minidump_thread_id_map_test.cc |
| diff --git a/minidump/minidump_thread_id_map_test.cc b/minidump/minidump_thread_id_map_test.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..33e8149377b6d1ff7c2a3c08363475ca0c076b9b |
| --- /dev/null |
| +++ b/minidump/minidump_thread_id_map_test.cc |
| @@ -0,0 +1,156 @@ |
| +// Copyright 2014 The Crashpad Authors. All rights reserved. |
| +// |
| +// Licensed under the Apache License, Version 2.0 (the "License"); |
| +// you may not use this file except in compliance with the License. |
| +// You may obtain a copy of the License at |
| +// |
| +// http://www.apache.org/licenses/LICENSE-2.0 |
| +// |
| +// Unless required by applicable law or agreed to in writing, software |
| +// distributed under the License is distributed on an "AS IS" BASIS, |
| +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| +// See the License for the specific language governing permissions and |
| +// limitations under the License. |
| + |
| +#include "minidump/minidump_thread_id_map.h" |
| + |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "gtest/gtest.h" |
| +#include "snapshot/test/test_thread_snapshot.h" |
| + |
| +namespace crashpad { |
| +namespace test { |
| +namespace { |
| + |
| +bool MapHasKeyValue( |
| + const MinidumpThreadIDMap* map, uint64_t key, uint32_t expected_value) { |
| + auto iterator = map->find(key); |
| + if (iterator == map->end()) { |
| + EXPECT_NE(map->end(), iterator); |
| + return false; |
| + } |
| + if (iterator->second != expected_value) { |
| + EXPECT_EQ(expected_value, iterator->second); |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +TEST(MinidumpThreadIDMap, MinidumpThreadIDMap) { |
| + std::vector<const ThreadSnapshot*> thread_snapshots; |
| + |
| + MinidumpThreadIDMap thread_id_map; |
| + |
| + // No threads to map. |
| + BuildMinidumpThreadIDMap(thread_snapshots, &thread_id_map); |
| + |
| + EXPECT_TRUE(thread_id_map.empty()); |
| + |
| + TestThreadSnapshot test_thread_snapshots[5] = {}; |
| + |
| + for (size_t index = 0; index < arraysize(test_thread_snapshots); ++index) { |
| + thread_snapshots.push_back(&test_thread_snapshots[index]); |
| + } |
| + |
|
Robert Sesek
2014/11/04 15:34:58
Everything above this line could go in SetUp()
|
| + // A simple mapping. |
|
Robert Sesek
2014/11/04 15:34:58
…and then each of these could be a TEST().
|
| + test_thread_snapshots[0].SetThreadID(1); |
| + test_thread_snapshots[1].SetThreadID(3); |
| + test_thread_snapshots[2].SetThreadID(5); |
| + test_thread_snapshots[3].SetThreadID(7); |
| + test_thread_snapshots[4].SetThreadID(9); |
| + |
| + thread_id_map.clear(); |
| + BuildMinidumpThreadIDMap(thread_snapshots, &thread_id_map); |
| + |
| + EXPECT_EQ(5u, thread_id_map.size()); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 1, 1); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 3, 3); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 5, 5); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 7, 7); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 9, 9); |
| + |
| + // A mapping with some truncation. |
| + test_thread_snapshots[0].SetThreadID(0x0000000000000000); |
| + test_thread_snapshots[1].SetThreadID(0x9999999900000001); |
| + test_thread_snapshots[2].SetThreadID(0x9999999980000001); |
| + test_thread_snapshots[3].SetThreadID(0x99999999fffffffe); |
| + test_thread_snapshots[4].SetThreadID(0x99999999ffffffff); |
| + |
| + thread_id_map.clear(); |
| + BuildMinidumpThreadIDMap(thread_snapshots, &thread_id_map); |
| + |
| + EXPECT_EQ(5u, thread_id_map.size()); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000000000000, 0x00000000); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x9999999900000001, 0x00000001); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x9999999980000001, 0x80000001); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x99999999fffffffe, 0xfffffffe); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x99999999ffffffff, 0xffffffff); |
| + |
| + // A mapping where thread IDs are duplicated. |
| + test_thread_snapshots[0].SetThreadID(2); |
| + test_thread_snapshots[1].SetThreadID(4); |
| + test_thread_snapshots[2].SetThreadID(4); |
| + test_thread_snapshots[3].SetThreadID(6); |
| + test_thread_snapshots[4].SetThreadID(8); |
| + |
| + thread_id_map.clear(); |
| + BuildMinidumpThreadIDMap(thread_snapshots, &thread_id_map); |
| + |
| + EXPECT_EQ(4u, thread_id_map.size()); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 2, 2); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 4, 4); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 6, 6); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 8, 8); |
| + |
| + // A mapping with a collision. |
| + test_thread_snapshots[0].SetThreadID(0x0000000000000010); |
| + test_thread_snapshots[1].SetThreadID(0x0000000000000020); |
| + test_thread_snapshots[2].SetThreadID(0x0000000000000030); |
| + test_thread_snapshots[3].SetThreadID(0x0000000000000040); |
| + test_thread_snapshots[4].SetThreadID(0x0000000100000010); |
| + |
| + thread_id_map.clear(); |
| + BuildMinidumpThreadIDMap(thread_snapshots, &thread_id_map); |
| + |
| + EXPECT_EQ(5u, thread_id_map.size()); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000000000010, 0); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000000000020, 1); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000000000030, 2); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000000000040, 3); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000100000010, 4); |
| + |
| + // A mapping with a collision and a duplicate thread ID. |
| + test_thread_snapshots[0].SetThreadID(0x0000000100000010); |
| + test_thread_snapshots[1].SetThreadID(0x0000000000000010); |
| + test_thread_snapshots[2].SetThreadID(0x0000000000000020); |
| + test_thread_snapshots[3].SetThreadID(0x0000000000000030); |
| + test_thread_snapshots[4].SetThreadID(0x0000000000000020); |
| + |
| + thread_id_map.clear(); |
| + BuildMinidumpThreadIDMap(thread_snapshots, &thread_id_map); |
| + |
| + EXPECT_EQ(4u, thread_id_map.size()); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000100000010, 0); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000000000010, 1); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000000000020, 2); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 0x0000000000000030, 3); |
| + |
| + // A mapping with nothing but duplicates. |
| + test_thread_snapshots[0].SetThreadID(6); |
| + test_thread_snapshots[1].SetThreadID(6); |
| + test_thread_snapshots[2].SetThreadID(6); |
| + test_thread_snapshots[3].SetThreadID(6); |
| + test_thread_snapshots[4].SetThreadID(6); |
| + |
| + thread_id_map.clear(); |
| + BuildMinidumpThreadIDMap(thread_snapshots, &thread_id_map); |
| + |
| + EXPECT_EQ(1u, thread_id_map.size()); |
| + EXPECT_PRED3(MapHasKeyValue, &thread_id_map, 6, 6); |
| +} |
| + |
| +} // namespace |
| +} // namespace test |
| +} // namespace crashpad |