aboutsummaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-01-04 22:11:11 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-01-04 22:11:11 +0000
commitc82ad72f63369bc462e59458f09960d66daa58a9 (patch)
tree58bc455a8d052220f9ae11e65d6f06d671a7a4c4 /unittests
parentb915e9e0fc85ba6f398b3fab0db6a81a8913af94 (diff)
Vendor import of llvm trunk r291012:vendor/llvm/llvm-trunk-r291012
Notes
Notes: svn path=/vendor/llvm/dist/; revision=311315 svn path=/vendor/llvm/llvm-trunk-r291012/; revision=311316; tag=vendor/llvm/llvm-trunk-r291012
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ADT/PriorityWorklistTest.cpp47
-rw-r--r--unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp75
-rw-r--r--unittests/Support/YAMLIOTest.cpp62
3 files changed, 155 insertions, 29 deletions
diff --git a/unittests/ADT/PriorityWorklistTest.cpp b/unittests/ADT/PriorityWorklistTest.cpp
index bbe026434c63..040a11f95f42 100644
--- a/unittests/ADT/PriorityWorklistTest.cpp
+++ b/unittests/ADT/PriorityWorklistTest.cpp
@@ -13,6 +13,8 @@
#include "llvm/ADT/PriorityWorklist.h"
#include "gtest/gtest.h"
+#include <list>
+#include <vector>
namespace {
@@ -72,6 +74,51 @@ TYPED_TEST(PriorityWorklistTest, Basic) {
EXPECT_TRUE(W.empty());
}
+TYPED_TEST(PriorityWorklistTest, InsertSequence) {
+ TypeParam W;
+ ASSERT_TRUE(W.insert(2));
+ ASSERT_TRUE(W.insert(4));
+ ASSERT_TRUE(W.insert(7));
+ // Insert a sequence that has internal duplicates and a duplicate among
+ // existing entries.
+ W.insert(std::vector<int>({42, 13, 42, 7, 8}));
+ EXPECT_EQ(8, W.pop_back_val());
+ EXPECT_EQ(7, W.pop_back_val());
+ EXPECT_EQ(42, W.pop_back_val());
+ EXPECT_EQ(13, W.pop_back_val());
+ EXPECT_EQ(4, W.pop_back_val());
+ EXPECT_EQ(2, W.pop_back_val());
+ ASSERT_TRUE(W.empty());
+
+ // Simpler tests with various other input types.
+ ASSERT_TRUE(W.insert(2));
+ ASSERT_TRUE(W.insert(7));
+ // Use a non-random-access container.
+ W.insert(std::list<int>({7, 5}));
+ EXPECT_EQ(5, W.pop_back_val());
+ EXPECT_EQ(7, W.pop_back_val());
+ EXPECT_EQ(2, W.pop_back_val());
+ ASSERT_TRUE(W.empty());
+
+ ASSERT_TRUE(W.insert(2));
+ ASSERT_TRUE(W.insert(7));
+ // Use a raw array.
+ int A[] = {7, 5};
+ W.insert(A);
+ EXPECT_EQ(5, W.pop_back_val());
+ EXPECT_EQ(7, W.pop_back_val());
+ EXPECT_EQ(2, W.pop_back_val());
+ ASSERT_TRUE(W.empty());
+
+ ASSERT_TRUE(W.insert(2));
+ ASSERT_TRUE(W.insert(7));
+ // Inserting an empty sequence does nothing.
+ W.insert(std::vector<int>());
+ EXPECT_EQ(7, W.pop_back_val());
+ EXPECT_EQ(2, W.pop_back_val());
+ ASSERT_TRUE(W.empty());
+}
+
TYPED_TEST(PriorityWorklistTest, EraseIf) {
TypeParam W;
W.insert(23);
diff --git a/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp b/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
index e2f4bb788dd0..ec8297f277f4 100644
--- a/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
+++ b/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
@@ -984,10 +984,11 @@ TEST(DWARFDebugInfo, TestRelations) {
enum class Tag: uint16_t {
A = dwarf::DW_TAG_lo_user,
B,
- B1,
- B2,
C,
- C1
+ C1,
+ C2,
+ D,
+ D1
};
// Scope to allow us to re-use the same DIE names
@@ -996,18 +997,20 @@ TEST(DWARFDebugInfo, TestRelations) {
//
// CU
// A
- // B
- // B1
- // B2
- // C
- // C1
+ // B
+ // C
+ // C1
+ // C2
+ // D
+ // D1
dwarfgen::DIE CUDie = CU.getUnitDIE();
- CUDie.addChild((dwarf::Tag)Tag::A);
- dwarfgen::DIE B = CUDie.addChild((dwarf::Tag)Tag::B);
- dwarfgen::DIE C = CUDie.addChild((dwarf::Tag)Tag::C);
- B.addChild((dwarf::Tag)Tag::B1);
- B.addChild((dwarf::Tag)Tag::B2);
+ dwarfgen::DIE A = CUDie.addChild((dwarf::Tag)Tag::A);
+ A.addChild((dwarf::Tag)Tag::B);
+ dwarfgen::DIE C = A.addChild((dwarf::Tag)Tag::C);
+ dwarfgen::DIE D = A.addChild((dwarf::Tag)Tag::D);
C.addChild((dwarf::Tag)Tag::C1);
+ C.addChild((dwarf::Tag)Tag::C2);
+ D.addChild((dwarf::Tag)Tag::D1);
}
MemoryBufferRef FileBuffer(DG->generate(), "dwarf");
@@ -1023,7 +1026,7 @@ TEST(DWARFDebugInfo, TestRelations) {
// Get the compile unit DIE is valid.
auto CUDie = U->getUnitDIE(false);
EXPECT_TRUE(CUDie.isValid());
- // DieDG.dump(llvm::outs(), U, UINT32_MAX);
+ // CUDie.dump(llvm::outs(), UINT32_MAX);
// The compile unit doesn't have a parent or a sibling.
auto ParentDie = CUDie.getParent();
@@ -1033,9 +1036,10 @@ TEST(DWARFDebugInfo, TestRelations) {
// Get the children of the compile unit
auto A = CUDie.getFirstChild();
- auto B = A.getSibling();
+ auto B = A.getFirstChild();
auto C = B.getSibling();
- auto Null = C.getSibling();
+ auto D = C.getSibling();
+ auto Null = D.getSibling();
// Verify NULL Die is NULL and has no children or siblings
EXPECT_TRUE(Null.isNULL());
@@ -1046,31 +1050,44 @@ TEST(DWARFDebugInfo, TestRelations) {
EXPECT_EQ(A.getTag(), (dwarf::Tag)Tag::A);
EXPECT_EQ(B.getTag(), (dwarf::Tag)Tag::B);
EXPECT_EQ(C.getTag(), (dwarf::Tag)Tag::C);
+ EXPECT_EQ(D.getTag(), (dwarf::Tag)Tag::D);
// Verify who has children
- EXPECT_FALSE(A.hasChildren());
- EXPECT_TRUE(B.hasChildren());
+ EXPECT_TRUE(A.hasChildren());
+ EXPECT_FALSE(B.hasChildren());
+ EXPECT_TRUE(C.hasChildren());
+ EXPECT_TRUE(D.hasChildren());
// Make sure the parent of all the children of the compile unit are the
// compile unit.
EXPECT_EQ(A.getParent(), CUDie);
- EXPECT_EQ(B.getParent(), CUDie);
- EXPECT_EQ(Null.getParent(), CUDie);
-
- EXPECT_FALSE(A.getFirstChild().isValid());
+
+ // Make sure the parent of all the children of A are the A.
+ // B is the first child in A, so we need to verify we can get the previous
+ // DIE as the parent.
+ EXPECT_EQ(B.getParent(), A);
+ // C is the second child in A, so we need to make sure we can backup across
+ // other DIE (B) at the same level to get the correct parent.
+ EXPECT_EQ(C.getParent(), A);
+ // D is the third child of A. We need to verify we can backup across other DIE
+ // (B and C) including DIE that have children (D) to get the correct parent.
+ EXPECT_EQ(D.getParent(), A);
+
+ // Verify that a DIE with no children returns an invalid DWARFDie.
+ EXPECT_FALSE(B.getFirstChild().isValid());
// Verify the children of the B DIE
- auto B1 = B.getFirstChild();
- auto B2 = B1.getSibling();
- EXPECT_TRUE(B2.getSibling().isNULL());
+ auto C1 = C.getFirstChild();
+ auto C2 = C1.getSibling();
+ EXPECT_TRUE(C2.getSibling().isNULL());
// Verify all children of the B DIE correctly valid or invalid.
- EXPECT_EQ(B1.getTag(), (dwarf::Tag)Tag::B1);
- EXPECT_EQ(B2.getTag(), (dwarf::Tag)Tag::B2);
+ EXPECT_EQ(C1.getTag(), (dwarf::Tag)Tag::C1);
+ EXPECT_EQ(C2.getTag(), (dwarf::Tag)Tag::C2);
// Make sure the parent of all the children of the B are the B.
- EXPECT_EQ(B1.getParent(), B);
- EXPECT_EQ(B2.getParent(), B);
+ EXPECT_EQ(C1.getParent(), C);
+ EXPECT_EQ(C2.getParent(), C);
}
TEST(DWARFDebugInfo, TestDWARFDie) {
diff --git a/unittests/Support/YAMLIOTest.cpp b/unittests/Support/YAMLIOTest.cpp
index c3e18d332356..dc7c5d47cba9 100644
--- a/unittests/Support/YAMLIOTest.cpp
+++ b/unittests/Support/YAMLIOTest.cpp
@@ -2369,6 +2369,68 @@ TEST(YAMLIO, TestMapWithContext) {
out.clear();
}
+LLVM_YAML_IS_STRING_MAP(int)
+
+TEST(YAMLIO, TestCustomMapping) {
+ std::map<std::string, int> x;
+ x["foo"] = 1;
+ x["bar"] = 2;
+
+ std::string out;
+ llvm::raw_string_ostream ostr(out);
+ Output xout(ostr, nullptr, 0);
+
+ xout << x;
+ ostr.flush();
+ EXPECT_EQ("---\n"
+ "bar: 2\n"
+ "foo: 1\n"
+ "...\n",
+ out);
+
+ Input yin(out);
+ std::map<std::string, int> y;
+ yin >> y;
+ EXPECT_EQ(2ul, y.size());
+ EXPECT_EQ(1, y["foo"]);
+ EXPECT_EQ(2, y["bar"]);
+}
+
+LLVM_YAML_IS_STRING_MAP(FooBar)
+
+TEST(YAMLIO, TestCustomMappingStruct) {
+ std::map<std::string, FooBar> x;
+ x["foo"].foo = 1;
+ x["foo"].bar = 2;
+ x["bar"].foo = 3;
+ x["bar"].bar = 4;
+
+ std::string out;
+ llvm::raw_string_ostream ostr(out);
+ Output xout(ostr, nullptr, 0);
+
+ xout << x;
+ ostr.flush();
+ EXPECT_EQ("---\n"
+ "bar: \n"
+ " foo: 3\n"
+ " bar: 4\n"
+ "foo: \n"
+ " foo: 1\n"
+ " bar: 2\n"
+ "...\n",
+ out);
+
+ Input yin(out);
+ std::map<std::string, FooBar> y;
+ yin >> y;
+ EXPECT_EQ(2ul, y.size());
+ EXPECT_EQ(1, y["foo"].foo);
+ EXPECT_EQ(2, y["foo"].bar);
+ EXPECT_EQ(3, y["bar"].foo);
+ EXPECT_EQ(4, y["bar"].bar);
+}
+
TEST(YAMLIO, InvalidInput) {
// polluting 1 value in the sequence
Input yin("---\n- foo: 3\n bar: 5\n1\n- foo: 3\n bar: 5\n...\n");