summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/lldb/unittests/Utility/RangeMapTest.cpp
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2020-08-03 14:33:06 +0000
committerpatrick <patrick@openbsd.org>2020-08-03 14:33:06 +0000
commit061da546b983eb767bad15e67af1174fb0bcf31c (patch)
tree83c78b820819d70aa40c36d90447978b300078c5 /gnu/llvm/lldb/unittests/Utility/RangeMapTest.cpp
parentImport LLVM 10.0.0 release including clang, lld and lldb. (diff)
downloadwireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.tar.xz
wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.zip
Import LLVM 10.0.0 release including clang, lld and lldb.
ok hackroom tested by plenty
Diffstat (limited to 'gnu/llvm/lldb/unittests/Utility/RangeMapTest.cpp')
-rw-r--r--gnu/llvm/lldb/unittests/Utility/RangeMapTest.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/gnu/llvm/lldb/unittests/Utility/RangeMapTest.cpp b/gnu/llvm/lldb/unittests/Utility/RangeMapTest.cpp
new file mode 100644
index 00000000000..9f9b96559a4
--- /dev/null
+++ b/gnu/llvm/lldb/unittests/Utility/RangeMapTest.cpp
@@ -0,0 +1,96 @@
+//===-- RangeTest.cpp ----------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Utility/RangeMap.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+
+using RangeDataVectorT = RangeDataVector<uint32_t, uint32_t, uint32_t>;
+using EntryT = RangeDataVectorT::Entry;
+
+static testing::Matcher<const EntryT *> EntryIs(uint32_t ID) {
+ return testing::Pointee(testing::Field(&EntryT::data, ID));
+}
+
+TEST(RangeDataVector, FindEntryThatContains) {
+ RangeDataVectorT Map;
+ uint32_t NextID = 0;
+ Map.Append(EntryT(0, 10, NextID++));
+ Map.Append(EntryT(10, 10, NextID++));
+ Map.Append(EntryT(20, 10, NextID++));
+ Map.Sort();
+
+ EXPECT_THAT(Map.FindEntryThatContains(0), EntryIs(0));
+ EXPECT_THAT(Map.FindEntryThatContains(9), EntryIs(0));
+ EXPECT_THAT(Map.FindEntryThatContains(10), EntryIs(1));
+ EXPECT_THAT(Map.FindEntryThatContains(19), EntryIs(1));
+ EXPECT_THAT(Map.FindEntryThatContains(20), EntryIs(2));
+ EXPECT_THAT(Map.FindEntryThatContains(29), EntryIs(2));
+ EXPECT_THAT(Map.FindEntryThatContains(30), nullptr);
+}
+
+TEST(RangeDataVector, FindEntryThatContains_Overlap) {
+ RangeDataVectorT Map;
+ uint32_t NextID = 0;
+ Map.Append(EntryT(0, 40, NextID++));
+ Map.Append(EntryT(10, 20, NextID++));
+ Map.Append(EntryT(20, 10, NextID++));
+ Map.Sort();
+
+ // With overlapping intervals, the intention seems to be to return the first
+ // interval which contains the address.
+ EXPECT_THAT(Map.FindEntryThatContains(25), EntryIs(0));
+
+ // However, this does not always succeed.
+ // TODO: This should probably return the range (0, 40) as well.
+ EXPECT_THAT(Map.FindEntryThatContains(35), nullptr);
+}
+
+TEST(RangeDataVector, CustomSort) {
+ // First the default ascending order sorting of the data field.
+ auto Map = RangeDataVectorT();
+ Map.Append(EntryT(0, 10, 50));
+ Map.Append(EntryT(0, 10, 52));
+ Map.Append(EntryT(0, 10, 53));
+ Map.Append(EntryT(0, 10, 51));
+ Map.Sort();
+
+ EXPECT_THAT(Map.GetSize(), 4);
+ EXPECT_THAT(Map.GetEntryRef(0).data, 50);
+ EXPECT_THAT(Map.GetEntryRef(1).data, 51);
+ EXPECT_THAT(Map.GetEntryRef(2).data, 52);
+ EXPECT_THAT(Map.GetEntryRef(3).data, 53);
+
+ // And then a custom descending order sorting of the data field.
+ class CtorParam {};
+ class CustomSort {
+ public:
+ CustomSort(CtorParam) {}
+ bool operator()(const uint32_t a_data, const uint32_t b_data) {
+ return a_data > b_data;
+ }
+ };
+ using RangeDataVectorCustomSortT =
+ RangeDataVector<uint32_t, uint32_t, uint32_t, 0, CustomSort>;
+ using EntryT = RangeDataVectorT::Entry;
+
+ auto MapC = RangeDataVectorCustomSortT(CtorParam());
+ MapC.Append(EntryT(0, 10, 50));
+ MapC.Append(EntryT(0, 10, 52));
+ MapC.Append(EntryT(0, 10, 53));
+ MapC.Append(EntryT(0, 10, 51));
+ MapC.Sort();
+
+ EXPECT_THAT(MapC.GetSize(), 4);
+ EXPECT_THAT(MapC.GetEntryRef(0).data, 53);
+ EXPECT_THAT(MapC.GetEntryRef(1).data, 52);
+ EXPECT_THAT(MapC.GetEntryRef(2).data, 51);
+ EXPECT_THAT(MapC.GetEntryRef(3).data, 50);
+}