diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-07-01 13:22:02 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-07-01 13:22:02 +0000 |
commit | 9df3605dea17e84f8183581f6103bd0c79e2a606 (patch) | |
tree | 70a2f36ce9eb9bb213603cd7f2f120af53fc176f /unittests | |
parent | 08bbd35a80bf7765fe0d3043f9eb5a2f2786b649 (diff) | |
download | src-test2-9df3605dea17e84f8183581f6103bd0c79e2a606.tar.gz src-test2-9df3605dea17e84f8183581f6103bd0c79e2a606.zip |
Notes
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp | 19 | ||||
-rw-r--r-- | unittests/DebugInfo/DWARF/CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp | 304 | ||||
-rw-r--r-- | unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp | 8 | ||||
-rw-r--r-- | unittests/DebugInfo/DWARF/DwarfGenerator.h | 1 | ||||
-rw-r--r-- | unittests/IR/DominatorTreeTest.cpp | 15 | ||||
-rw-r--r-- | unittests/ProfileData/CoverageMappingTest.cpp | 18 | ||||
-rw-r--r-- | unittests/Support/CMakeLists.txt | 1 | ||||
-rw-r--r-- | unittests/Support/ErrnoTest.cpp | 36 | ||||
-rw-r--r-- | unittests/Support/YAMLIOTest.cpp | 30 |
10 files changed, 272 insertions, 162 deletions
diff --git a/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp b/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp index 882df5f25216..0e881759656d 100644 --- a/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp +++ b/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp @@ -117,4 +117,23 @@ TEST(LegalizerInfoTest, MultipleTypes) { ASSERT_EQ(L.getAction({G_PTRTOINT, 1, p0}), std::make_pair(LegalizerInfo::Legal, p0)); } + +TEST(LegalizerInfoTest, MultipleSteps) { + using namespace TargetOpcode; + LegalizerInfo L; + LLT s16 = LLT::scalar(16); + LLT s32 = LLT::scalar(32); + LLT s64 = LLT::scalar(64); + + L.setAction({G_UREM, 0, s16}, LegalizerInfo::WidenScalar); + L.setAction({G_UREM, 0, s32}, LegalizerInfo::Lower); + L.setAction({G_UREM, 0, s64}, LegalizerInfo::Lower); + + L.computeTables(); + + ASSERT_EQ(L.getAction({G_UREM, LLT::scalar(16)}), + std::make_pair(LegalizerInfo::WidenScalar, LLT::scalar(32))); + ASSERT_EQ(L.getAction({G_UREM, LLT::scalar(32)}), + std::make_pair(LegalizerInfo::Lower, LLT::scalar(32))); +} } diff --git a/unittests/DebugInfo/DWARF/CMakeLists.txt b/unittests/DebugInfo/DWARF/CMakeLists.txt index ed512a92ef18..1966472a9467 100644 --- a/unittests/DebugInfo/DWARF/CMakeLists.txt +++ b/unittests/DebugInfo/DWARF/CMakeLists.txt @@ -17,3 +17,5 @@ set(DebugInfoSources add_llvm_unittest(DebugInfoDWARFTests ${DebugInfoSources} ) + +target_link_libraries(DebugInfoDWARFTests LLVMTestingSupport) diff --git a/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp b/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp index bf004d6ffc23..6ffb710d2549 100644 --- a/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp +++ b/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp @@ -15,16 +15,22 @@ #include "llvm/ADT/Triple.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/Config/llvm-config.h" +#include "llvm/CodeGen/AsmPrinter.h" #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/DebugInfo/DWARF/DWARFDie.h" #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" +#include "llvm/MC/MCContext.h" +#include "llvm/MC/MCSectionELF.h" +#include "llvm/MC/MCStreamer.h" #include "llvm/Object/ObjectFile.h" #include "llvm/ObjectYAML/DWARFEmitter.h" #include "llvm/ObjectYAML/DWARFYAML.h" #include "llvm/Support/Error.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/TargetSelect.h" +#include "llvm/Support/TargetRegistry.h" +#include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" #include <climits> #include <cstdint> @@ -57,28 +63,19 @@ Triple getHostTripleForAddrSize(uint8_t AddrSize) { return PT; } -/// Take any llvm::Expected and check and handle any errors. -/// -/// \param Expected a llvm::Excepted instance to check. -/// \returns true if there were errors, false otherwise. -template <typename T> -static bool HandleExpectedError(T &Expected) { - std::string ErrorMsg; - handleAllErrors(Expected.takeError(), [&](const ErrorInfoBase &EI) { - ErrorMsg = EI.message(); - }); - if (!ErrorMsg.empty()) { - ::testing::AssertionFailure() << "error: " << ErrorMsg; - return true; - } - return false; +static bool isConfigurationSupported(Triple &T) { + initLLVMIfNeeded(); + std::string Err; + return TargetRegistry::lookupTarget(T.getTriple(), Err); } template <uint16_t Version, class AddrType, class RefAddrType> void TestAllForms() { - // Test that we can decode all DW_FORM values correctly. + Triple Triple = getHostTripleForAddrSize(sizeof(AddrType)); + if (!isConfigurationSupported(Triple)) + return; - const uint8_t AddrSize = sizeof(AddrType); + // Test that we can decode all DW_FORM values correctly. const AddrType AddrValue = (AddrType)0x0123456789abcdefULL; const uint8_t BlockData[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; const uint32_t BlockSize = sizeof(BlockData); @@ -97,11 +94,9 @@ void TestAllForms() { const uint32_t Dwarf32Values[] = {1, 2, 3, 4, 5, 6, 7, 8}; const char *StringValue = "Hello"; const char *StrpValue = "World"; - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); + auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); dwarfgen::DIE CUDie = CU.getUnitDIE(); @@ -427,16 +422,16 @@ TEST(DWARFDebugInfo, TestDWARF32Version5Addr8AllForms) { } template <uint16_t Version, class AddrType> void TestChildren() { + Triple Triple = getHostTripleForAddrSize(sizeof(AddrType)); + if (!isConfigurationSupported(Triple)) + return; + // Test that we can decode DW_FORM_ref_addr values correctly in DWARF 2 with // 4 byte addresses. DW_FORM_ref_addr values should be 4 bytes when using // 8 byte addresses. - const uint8_t AddrSize = sizeof(AddrType); - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); dwarfgen::DIE CUDie = CU.getUnitDIE(); @@ -551,14 +546,13 @@ TEST(DWARFDebugInfo, TestDWARF32Version4Addr8Children) { } template <uint16_t Version, class AddrType> void TestReferences() { - // Test that we can decode DW_FORM_refXXX values correctly in DWARF. + Triple Triple = getHostTripleForAddrSize(sizeof(AddrType)); + if (!isConfigurationSupported(Triple)) + return; - const uint8_t AddrSize = sizeof(AddrType); - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); + // Test that we can decode DW_FORM_refXXX values correctly in DWARF. auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU1 = DG->addCompileUnit(); dwarfgen::CompileUnit &CU2 = DG->addCompileUnit(); @@ -800,22 +794,22 @@ TEST(DWARFDebugInfo, TestDWARF32Version4Addr8References) { } template <uint16_t Version, class AddrType> void TestAddresses() { + Triple Triple = getHostTripleForAddrSize(sizeof(AddrType)); + if (!isConfigurationSupported(Triple)) + return; + // Test the DWARF APIs related to accessing the DW_AT_low_pc and // DW_AT_high_pc. - const uint8_t AddrSize = sizeof(AddrType); const bool SupportsHighPCAsOffset = Version >= 4; - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); dwarfgen::DIE CUDie = CU.getUnitDIE(); - + CUDie.addAttribute(DW_AT_name, DW_FORM_strp, "/tmp/main.c"); CUDie.addAttribute(DW_AT_language, DW_FORM_data2, DW_LANG_C); - + // Create a subprogram DIE with no low or high PC. dwarfgen::DIE SubprogramNoPC = CUDie.addChild(DW_TAG_subprogram); SubprogramNoPC.addAttribute(DW_AT_name, DW_FORM_strp, "no_pc"); @@ -838,18 +832,18 @@ template <uint16_t Version, class AddrType> void TestAddresses() { ActualHighPCOffset); else SubprogramLowHighPC.addAttribute(DW_AT_high_pc, DW_FORM_addr, ActualHighPC); - + StringRef FileBytes = DG->generate(); MemoryBufferRef FileBuffer(FileBytes, "dwarf"); auto Obj = object::ObjectFile::createObjectFile(FileBuffer); EXPECT_TRUE((bool)Obj); DWARFContextInMemory DwarfContext(*Obj.get()); - + // Verify the number of compile units is correct. uint32_t NumCUs = DwarfContext.getNumCompileUnits(); EXPECT_EQ(NumCUs, 1u); DWARFCompileUnit *U = DwarfContext.getCompileUnitAtIndex(0); - + // Get the compile unit DIE is valid. auto DieDG = U->getUnitDIE(false); EXPECT_TRUE(DieDG.isValid()); @@ -873,7 +867,7 @@ template <uint16_t Version, class AddrType> void TestAddresses() { OptU64 = SubprogramDieNoPC.getHighPC(ActualLowPC); EXPECT_FALSE((bool)OptU64); EXPECT_FALSE(SubprogramDieNoPC.getLowAndHighPC(LowPC, HighPC, SectionIndex)); - + // Verify the that our subprogram with only a low PC value succeeds when // we ask for the Low PC, but fails appropriately when asked for the high PC // or both low and high PC values. @@ -971,19 +965,18 @@ TEST(DWARFDebugInfo, TestDWARF32Version4Addr8Addresses) { } TEST(DWARFDebugInfo, TestRelations) { + Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + if (!isConfigurationSupported(Triple)) + return; + // Test the DWARF APIs related to accessing the DW_AT_low_pc and // DW_AT_high_pc. uint16_t Version = 4; - - const uint8_t AddrSize = sizeof(void *); - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); - + enum class Tag: uint16_t { A = dwarf::DW_TAG_lo_user, B, @@ -1020,34 +1013,34 @@ TEST(DWARFDebugInfo, TestRelations) { auto Obj = object::ObjectFile::createObjectFile(FileBuffer); EXPECT_TRUE((bool)Obj); DWARFContextInMemory DwarfContext(*Obj.get()); - + // Verify the number of compile units is correct. uint32_t NumCUs = DwarfContext.getNumCompileUnits(); EXPECT_EQ(NumCUs, 1u); DWARFCompileUnit *U = DwarfContext.getCompileUnitAtIndex(0); - + // Get the compile unit DIE is valid. auto CUDie = U->getUnitDIE(false); EXPECT_TRUE(CUDie.isValid()); - + // The compile unit doesn't have a parent or a sibling. auto ParentDie = CUDie.getParent(); EXPECT_FALSE(ParentDie.isValid()); auto SiblingDie = CUDie.getSibling(); EXPECT_FALSE(SiblingDie.isValid()); - + // Get the children of the compile unit auto A = CUDie.getFirstChild(); auto B = A.getFirstChild(); auto C = B.getSibling(); auto D = C.getSibling(); auto Null = D.getSibling(); - + // Verify NULL Die is NULL and has no children or siblings EXPECT_TRUE(Null.isNULL()); EXPECT_FALSE(Null.getSibling().isValid()); EXPECT_FALSE(Null.getFirstChild().isValid()); - + // Verify all children of the compile unit DIE are correct. EXPECT_EQ(A.getTag(), (dwarf::Tag)Tag::A); EXPECT_EQ(B.getTag(), (dwarf::Tag)Tag::B); @@ -1063,7 +1056,7 @@ TEST(DWARFDebugInfo, TestRelations) { // Make sure the parent of all the children of the compile unit are the // compile unit. EXPECT_EQ(A.getParent(), CUDie); - + // 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. @@ -1082,7 +1075,7 @@ TEST(DWARFDebugInfo, TestRelations) { 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(C1.getTag(), (dwarf::Tag)Tag::C1); EXPECT_EQ(C2.getTag(), (dwarf::Tag)Tag::C2); @@ -1102,24 +1095,23 @@ TEST(DWARFDebugInfo, TestDWARFDie) { } TEST(DWARFDebugInfo, TestChildIterators) { + Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + if (!isConfigurationSupported(Triple)) + return; + // Test the DWARF APIs related to iterating across the children of a DIE using // the DWARFDie::iterator class. uint16_t Version = 4; - - const uint8_t AddrSize = sizeof(void *); - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); - + enum class Tag: uint16_t { A = dwarf::DW_TAG_lo_user, B, }; - + // Scope to allow us to re-use the same DIE names { // Create DWARF tree that looks like: @@ -1131,24 +1123,24 @@ TEST(DWARFDebugInfo, TestChildIterators) { CUDie.addChild((dwarf::Tag)Tag::A); CUDie.addChild((dwarf::Tag)Tag::B); } - + MemoryBufferRef FileBuffer(DG->generate(), "dwarf"); auto Obj = object::ObjectFile::createObjectFile(FileBuffer); EXPECT_TRUE((bool)Obj); DWARFContextInMemory DwarfContext(*Obj.get()); - + // Verify the number of compile units is correct. uint32_t NumCUs = DwarfContext.getNumCompileUnits(); EXPECT_EQ(NumCUs, 1u); DWARFCompileUnit *U = DwarfContext.getCompileUnitAtIndex(0); - + // Get the compile unit DIE is valid. auto CUDie = U->getUnitDIE(false); EXPECT_TRUE(CUDie.isValid()); uint32_t Index; DWARFDie A; DWARFDie B; - + // Verify the compile unit DIE's children. Index = 0; for (auto Die : CUDie.children()) { @@ -1157,7 +1149,7 @@ TEST(DWARFDebugInfo, TestChildIterators) { case 1: B = Die; break; } } - + EXPECT_EQ(A.getTag(), (dwarf::Tag)Tag::A); EXPECT_EQ(B.getTag(), (dwarf::Tag)Tag::B); @@ -1206,7 +1198,7 @@ TEST(DWARFDebugInfo, TestEmptyChildren) { // Get the compile unit DIE is valid. auto CUDie = U->getUnitDIE(false); EXPECT_TRUE(CUDie.isValid()); - + // Verify that the CU Die that says it has children, but doesn't, actually // has begin and end iterators that are equal. We want to make sure we don't // see the Null DIEs during iteration. @@ -1214,21 +1206,20 @@ TEST(DWARFDebugInfo, TestEmptyChildren) { } TEST(DWARFDebugInfo, TestAttributeIterators) { + Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + if (!isConfigurationSupported(Triple)) + return; + // Test the DWARF APIs related to iterating across all attribute values in a // a DWARFDie. uint16_t Version = 4; - - const uint8_t AddrSize = sizeof(void *); - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); const uint64_t CULowPC = 0x1000; StringRef CUPath("/tmp/main.c"); - + // Scope to allow us to re-use the same DIE names { auto CUDie = CU.getUnitDIE(); @@ -1240,53 +1231,52 @@ TEST(DWARFDebugInfo, TestAttributeIterators) { // Encode an attribute value after an attribute with no data. CUDie.addAttribute(DW_AT_low_pc, DW_FORM_addr, CULowPC); } - + MemoryBufferRef FileBuffer(DG->generate(), "dwarf"); auto Obj = object::ObjectFile::createObjectFile(FileBuffer); EXPECT_TRUE((bool)Obj); DWARFContextInMemory DwarfContext(*Obj.get()); - + // Verify the number of compile units is correct. uint32_t NumCUs = DwarfContext.getNumCompileUnits(); EXPECT_EQ(NumCUs, 1u); DWARFCompileUnit *U = DwarfContext.getCompileUnitAtIndex(0); - + // Get the compile unit DIE is valid. auto CUDie = U->getUnitDIE(false); EXPECT_TRUE(CUDie.isValid()); - + auto R = CUDie.attributes(); auto I = R.begin(); auto E = R.end(); - + ASSERT_NE(E, I); EXPECT_EQ(I->Attr, DW_AT_name); auto ActualCUPath = I->Value.getAsCString(); EXPECT_EQ(CUPath, *ActualCUPath); - + ASSERT_NE(E, ++I); EXPECT_EQ(I->Attr, DW_AT_declaration); EXPECT_EQ(1ull, *I->Value.getAsUnsignedConstant()); - + ASSERT_NE(E, ++I); EXPECT_EQ(I->Attr, DW_AT_low_pc); EXPECT_EQ(CULowPC, *I->Value.getAsAddress()); - + EXPECT_EQ(E, ++I); } TEST(DWARFDebugInfo, TestFindRecurse) { + Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + if (!isConfigurationSupported(Triple)) + return; + uint16_t Version = 4; - - const uint8_t AddrSize = sizeof(void *); - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); - + StringRef SpecDieName = "spec"; StringRef SpecLinkageName = "spec_linkage"; StringRef AbsDieName = "abs"; @@ -1305,21 +1295,21 @@ TEST(DWARFDebugInfo, TestFindRecurse) { VarAbsDie.addAttribute(DW_AT_name, DW_FORM_strp, AbsDieName); VarDie.addAttribute(DW_AT_abstract_origin, DW_FORM_ref4, VarAbsDie); } - + MemoryBufferRef FileBuffer(DG->generate(), "dwarf"); auto Obj = object::ObjectFile::createObjectFile(FileBuffer); EXPECT_TRUE((bool)Obj); DWARFContextInMemory DwarfContext(*Obj.get()); - + // Verify the number of compile units is correct. uint32_t NumCUs = DwarfContext.getNumCompileUnits(); EXPECT_EQ(NumCUs, 1u); DWARFCompileUnit *U = DwarfContext.getCompileUnitAtIndex(0); - + // Get the compile unit DIE is valid. auto CUDie = U->getUnitDIE(false); EXPECT_TRUE(CUDie.isValid()); - + auto FuncSpecDie = CUDie.getFirstChild(); auto FuncAbsDie = FuncSpecDie.getSibling(); auto FuncDie = FuncAbsDie.getSibling(); @@ -1344,11 +1334,11 @@ TEST(DWARFDebugInfo, TestFindRecurse) { auto LinkageNameOpt = FuncDie.findRecursively(DW_AT_linkage_name); EXPECT_EQ(SpecLinkageName, toString(LinkageNameOpt).getValueOr(nullptr)); - + // Make sure we can't extract the name from the abstract origin die when using // DWARFDie::find() since it won't check the DW_AT_abstract_origin DIE. EXPECT_FALSE(VarDie.find(DW_AT_name)); - + // Make sure we can extract the name from the abstract origin die when using // DWARFDie::findRecursively() since it should recurse through the // DW_AT_abstract_origin DIE. @@ -1408,7 +1398,7 @@ TEST(DWARFDebugInfo, TestDwarfToFunctions) { FormVal.setForm(DW_FORM_udata); FormVal.setUValue(UData8); FormValOpt = FormVal; - + EXPECT_FALSE(toString(FormValOpt).hasValue()); EXPECT_TRUE(toUnsigned(FormValOpt).hasValue()); EXPECT_FALSE(toReference(FormValOpt).hasValue()); @@ -1428,7 +1418,7 @@ TEST(DWARFDebugInfo, TestDwarfToFunctions) { FormVal.setForm(DW_FORM_ref_addr); FormVal.setUValue(RefData); FormValOpt = FormVal; - + EXPECT_FALSE(toString(FormValOpt).hasValue()); EXPECT_FALSE(toUnsigned(FormValOpt).hasValue()); EXPECT_TRUE(toReference(FormValOpt).hasValue()); @@ -1448,7 +1438,7 @@ TEST(DWARFDebugInfo, TestDwarfToFunctions) { FormVal.setForm(DW_FORM_udata); FormVal.setSValue(SData8); FormValOpt = FormVal; - + EXPECT_FALSE(toString(FormValOpt).hasValue()); EXPECT_TRUE(toUnsigned(FormValOpt).hasValue()); EXPECT_FALSE(toReference(FormValOpt).hasValue()); @@ -1469,7 +1459,7 @@ TEST(DWARFDebugInfo, TestDwarfToFunctions) { FormVal.setForm(DW_FORM_block1); FormVal.setBlockValue(Array); FormValOpt = FormVal; - + EXPECT_FALSE(toString(FormValOpt).hasValue()); EXPECT_FALSE(toUnsigned(FormValOpt).hasValue()); EXPECT_FALSE(toReference(FormValOpt).hasValue()); @@ -1490,19 +1480,18 @@ TEST(DWARFDebugInfo, TestDwarfToFunctions) { } TEST(DWARFDebugInfo, TestFindAttrs) { + Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + if (!isConfigurationSupported(Triple)) + return; + // Test the DWARFDie::find() and DWARFDie::findRecursively() that take an // ArrayRef<dwarf::Attribute> value to make sure they work correctly. uint16_t Version = 4; - - const uint8_t AddrSize = sizeof(void *); - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); - + StringRef DieMangled("_Z3fooi"); // Scope to allow us to re-use the same DIE names { @@ -1512,21 +1501,21 @@ TEST(DWARFDebugInfo, TestFindAttrs) { FuncSpecDie.addAttribute(DW_AT_MIPS_linkage_name, DW_FORM_strp, DieMangled); FuncDie.addAttribute(DW_AT_specification, DW_FORM_ref4, FuncSpecDie); } - + MemoryBufferRef FileBuffer(DG->generate(), "dwarf"); auto Obj = object::ObjectFile::createObjectFile(FileBuffer); EXPECT_TRUE((bool)Obj); DWARFContextInMemory DwarfContext(*Obj.get()); - + // Verify the number of compile units is correct. uint32_t NumCUs = DwarfContext.getNumCompileUnits(); EXPECT_EQ(NumCUs, 1u); DWARFCompileUnit *U = DwarfContext.getCompileUnitAtIndex(0); - + // Get the compile unit DIE is valid. auto CUDie = U->getUnitDIE(false); EXPECT_TRUE(CUDie.isValid()); - + auto FuncSpecDie = CUDie.getFirstChild(); auto FuncDie = FuncSpecDie.getSibling(); @@ -1543,7 +1532,7 @@ TEST(DWARFDebugInfo, TestFindAttrs) { // Make sure we can't extract the linkage name attributes when using // DWARFDie::find() since it won't check the DW_AT_specification DIE. EXPECT_FALSE(FuncDie.find(Attrs).hasValue()); - + // Make sure we can extract the name from the specification die when using // DWARFDie::findRecursively() since it should recurse through the // DW_AT_specification DIE. @@ -1553,14 +1542,13 @@ TEST(DWARFDebugInfo, TestFindAttrs) { } TEST(DWARFDebugInfo, TestImplicitConstAbbrevs) { - uint16_t Version = 5; + Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + if (!isConfigurationSupported(Triple)) + return; - const uint8_t AddrSize = sizeof(void *); - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); + uint16_t Version = 5; auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); dwarfgen::DIE CUDie = CU.getUnitDIE(); @@ -2073,38 +2061,38 @@ TEST(DWARFDebugInfo, TestDwarfVerifyCUDontShareLineTable) { - '' - /tmp/main.c - /tmp/foo.c - debug_abbrev: + debug_abbrev: - Code: 0x00000001 Tag: DW_TAG_compile_unit Children: DW_CHILDREN_no - Attributes: + Attributes: - Attribute: DW_AT_name Form: DW_FORM_strp - Attribute: DW_AT_stmt_list Form: DW_FORM_sec_offset - debug_info: - - Length: + debug_info: + - Length: TotalLength: 16 Version: 4 AbbrOffset: 0 AddrSize: 8 - Entries: + Entries: - AbbrCode: 0x00000001 - Values: + Values: - Value: 0x0000000000000001 - Value: 0x0000000000000000 - - Length: + - Length: TotalLength: 16 Version: 4 AbbrOffset: 0 AddrSize: 8 - Entries: + Entries: - AbbrCode: 0x00000001 - Values: + Values: - Value: 0x000000000000000D - Value: 0x0000000000000000 - debug_line: - - Length: + debug_line: + - Length: TotalLength: 60 Version: 2 PrologueLength: 34 @@ -2114,14 +2102,14 @@ TEST(DWARFDebugInfo, TestDwarfVerifyCUDontShareLineTable) { LineRange: 14 OpcodeBase: 13 StandardOpcodeLengths: [ 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 ] - IncludeDirs: + IncludeDirs: - /tmp - Files: + Files: - Name: main.c DirIdx: 1 ModTime: 0 Length: 0 - Opcodes: + Opcodes: - Opcode: DW_LNS_extended_op ExtLen: 9 SubOpcode: DW_LNE_set_address @@ -2146,4 +2134,48 @@ TEST(DWARFDebugInfo, TestDwarfVerifyCUDontShareLineTable) { "offset:"); } +TEST(DWARFDebugInfo, TestErrorReportingPolicy) { + Triple Triple("x86_64-pc-linux"); + if (!isConfigurationSupported(Triple)) + return; + + auto ExpectedDG = dwarfgen::Generator::create(Triple, 4 /*DwarfVersion*/); + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); + dwarfgen::Generator *DG = ExpectedDG.get().get(); + AsmPrinter *AP = DG->getAsmPrinter(); + MCContext *MC = DG->getMCContext(); + + // Emit two compressed sections with broken headers. + AP->OutStreamer->SwitchSection( + MC->getELFSection(".zdebug_foo", 0 /*Type*/, 0 /*Flags*/)); + AP->OutStreamer->EmitBytes("0"); + AP->OutStreamer->SwitchSection( + MC->getELFSection(".zdebug_bar", 0 /*Type*/, 0 /*Flags*/)); + AP->OutStreamer->EmitBytes("0"); + + MemoryBufferRef FileBuffer(DG->generate(), "dwarf"); + auto Obj = object::ObjectFile::createObjectFile(FileBuffer); + EXPECT_TRUE((bool)Obj); + + // Case 1: error handler handles all errors. That allows + // DWARFContextInMemory + // to parse whole file and find both two errors we know about. + int Errors = 0; + DWARFContextInMemory Ctx1(*Obj.get(), nullptr, [&](Error E) { + ++Errors; + consumeError(std::move(E)); + return ErrorPolicy::Continue; + }); + EXPECT_TRUE(Errors == 2); + + // Case 2: error handler stops parsing of object after first error. + Errors = 0; + DWARFContextInMemory Ctx2(*Obj.get(), nullptr, [&](Error E) { + ++Errors; + consumeError(std::move(E)); + return ErrorPolicy::Halt; + }); + EXPECT_TRUE(Errors == 1); +} + } // end anonymous namespace diff --git a/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp b/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp index 621796b684d6..f283ac0961cc 100644 --- a/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp +++ b/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp @@ -97,8 +97,8 @@ DWARFFormValue createDataXFormValue(dwarf::Form Form, RawTypeT Value) { memcpy(Raw, &Value, sizeof(RawTypeT)); uint32_t Offset = 0; DWARFFormValue Result(Form); - DataExtractor Data(StringRef(Raw, sizeof(RawTypeT)), - sys::IsLittleEndianHost, sizeof(void*)); + DWARFDataExtractor Data(StringRef(Raw, sizeof(RawTypeT)), + sys::IsLittleEndianHost, sizeof(void *)); Result.extractValue(Data, &Offset, nullptr); return Result; } @@ -109,7 +109,7 @@ DWARFFormValue createULEBFormValue(uint64_t Value) { encodeULEB128(Value, OS); uint32_t Offset = 0; DWARFFormValue Result(DW_FORM_udata); - DataExtractor Data(OS.str(), sys::IsLittleEndianHost, sizeof(void*)); + DWARFDataExtractor Data(OS.str(), sys::IsLittleEndianHost, sizeof(void *)); Result.extractValue(Data, &Offset, nullptr); return Result; } @@ -120,7 +120,7 @@ DWARFFormValue createSLEBFormValue(int64_t Value) { encodeSLEB128(Value, OS); uint32_t Offset = 0; DWARFFormValue Result(DW_FORM_sdata); - DataExtractor Data(OS.str(), sys::IsLittleEndianHost, sizeof(void*)); + DWARFDataExtractor Data(OS.str(), sys::IsLittleEndianHost, sizeof(void *)); Result.extractValue(Data, &Offset, nullptr); return Result; } diff --git a/unittests/DebugInfo/DWARF/DwarfGenerator.h b/unittests/DebugInfo/DWARF/DwarfGenerator.h index 76665e5193e8..dd7e8709638d 100644 --- a/unittests/DebugInfo/DWARF/DwarfGenerator.h +++ b/unittests/DebugInfo/DWARF/DwarfGenerator.h @@ -215,6 +215,7 @@ public: BumpPtrAllocator &getAllocator() { return Allocator; } AsmPrinter *getAsmPrinter() const { return Asm.get(); } + MCContext *getMCContext() const { return MC.get(); } DIEAbbrevSet &getAbbrevSet() { return Abbreviations; } DwarfStringPool &getStringPool() { return *StringPool; } diff --git a/unittests/IR/DominatorTreeTest.cpp b/unittests/IR/DominatorTreeTest.cpp index 232f0cbd4ed9..fa3dad8a2ab1 100644 --- a/unittests/IR/DominatorTreeTest.cpp +++ b/unittests/IR/DominatorTreeTest.cpp @@ -220,6 +220,7 @@ TEST(DominatorTree, Unreachable) { EXPECT_EQ(PostDominatedBBs.size(), 0UL); // Check DFS Numbers before + DT->updateDFSNumbers(); EXPECT_EQ(DT->getNode(BB0)->getDFSNumIn(), 0UL); EXPECT_EQ(DT->getNode(BB0)->getDFSNumOut(), 7UL); EXPECT_EQ(DT->getNode(BB1)->getDFSNumIn(), 1UL); @@ -229,12 +230,19 @@ TEST(DominatorTree, Unreachable) { EXPECT_EQ(DT->getNode(BB4)->getDFSNumIn(), 3UL); EXPECT_EQ(DT->getNode(BB4)->getDFSNumOut(), 4UL); + // Check levels before + EXPECT_EQ(DT->getNode(BB0)->getLevel(), 0U); + EXPECT_EQ(DT->getNode(BB1)->getLevel(), 1U); + EXPECT_EQ(DT->getNode(BB2)->getLevel(), 1U); + EXPECT_EQ(DT->getNode(BB4)->getLevel(), 1U); + // Reattach block 3 to block 1 and recalculate BB1->getTerminator()->eraseFromParent(); BranchInst::Create(BB4, BB3, ConstantInt::getTrue(F.getContext()), BB1); DT->recalculate(F); // Check DFS Numbers after + DT->updateDFSNumbers(); EXPECT_EQ(DT->getNode(BB0)->getDFSNumIn(), 0UL); EXPECT_EQ(DT->getNode(BB0)->getDFSNumOut(), 9UL); EXPECT_EQ(DT->getNode(BB1)->getDFSNumIn(), 1UL); @@ -246,6 +254,13 @@ TEST(DominatorTree, Unreachable) { EXPECT_EQ(DT->getNode(BB4)->getDFSNumIn(), 5UL); EXPECT_EQ(DT->getNode(BB4)->getDFSNumOut(), 6UL); + // Check levels after + EXPECT_EQ(DT->getNode(BB0)->getLevel(), 0U); + EXPECT_EQ(DT->getNode(BB1)->getLevel(), 1U); + EXPECT_EQ(DT->getNode(BB2)->getLevel(), 1U); + EXPECT_EQ(DT->getNode(BB3)->getLevel(), 2U); + EXPECT_EQ(DT->getNode(BB4)->getLevel(), 1U); + // Change root node DT->verifyDomTree(); BasicBlock *NewEntry = diff --git a/unittests/ProfileData/CoverageMappingTest.cpp b/unittests/ProfileData/CoverageMappingTest.cpp index ea51f717a1db..1d621f4060ca 100644 --- a/unittests/ProfileData/CoverageMappingTest.cpp +++ b/unittests/ProfileData/CoverageMappingTest.cpp @@ -232,15 +232,17 @@ struct CoverageMappingTest : ::testing::TestWithParam<std::pair<bool, bool>> { } Expected<std::unique_ptr<CoverageMapping>> readOutputFunctions() { - if (!UseMultipleReaders) { - CoverageMappingReaderMock CovReader(OutputFunctions); - return CoverageMapping::load(CovReader, *ProfileReader); - } - std::vector<std::unique_ptr<CoverageMappingReader>> CoverageReaders; - for (const auto &OF : OutputFunctions) { - ArrayRef<OutputFunctionCoverageData> Funcs(OF); - CoverageReaders.push_back(make_unique<CoverageMappingReaderMock>(Funcs)); + if (UseMultipleReaders) { + for (const auto &OF : OutputFunctions) { + ArrayRef<OutputFunctionCoverageData> Funcs(OF); + CoverageReaders.push_back( + make_unique<CoverageMappingReaderMock>(Funcs)); + } + } else { + ArrayRef<OutputFunctionCoverageData> Funcs(OutputFunctions); + CoverageReaders.push_back( + make_unique<CoverageMappingReaderMock>(Funcs)); } return CoverageMapping::load(CoverageReaders, *ProfileReader); } diff --git a/unittests/Support/CMakeLists.txt b/unittests/Support/CMakeLists.txt index e2a6561089bc..641163e39ed3 100644 --- a/unittests/Support/CMakeLists.txt +++ b/unittests/Support/CMakeLists.txt @@ -21,6 +21,7 @@ add_llvm_unittest(SupportTests DebugTest.cpp EndianStreamTest.cpp EndianTest.cpp + ErrnoTest.cpp ErrorOrTest.cpp ErrorTest.cpp FileOutputBufferTest.cpp diff --git a/unittests/Support/ErrnoTest.cpp b/unittests/Support/ErrnoTest.cpp new file mode 100644 index 000000000000..67f834a938da --- /dev/null +++ b/unittests/Support/ErrnoTest.cpp @@ -0,0 +1,36 @@ +//===- ErrnoTest.cpp - Error handling unit tests --------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/Errno.h" +#include "gtest/gtest.h" + +using namespace llvm::sys; + +TEST(ErrnoTest, RetryAfterSignal) { + EXPECT_EQ(1, RetryAfterSignal(-1, [] { return 1; })); + + EXPECT_EQ(-1, RetryAfterSignal(-1, [] { + errno = EAGAIN; + return -1; + })); + EXPECT_EQ(EAGAIN, errno); + + unsigned calls = 0; + EXPECT_EQ(1, RetryAfterSignal(-1, [&calls] { + errno = EINTR; + ++calls; + return calls == 1 ? -1 : 1; + })); + EXPECT_EQ(2u, calls); + + EXPECT_EQ(1, RetryAfterSignal(-1, [](int x) { return x; }, 1)); + + std::unique_ptr<int> P(RetryAfterSignal(nullptr, [] { return new int(47); })); + EXPECT_EQ(47, *P); +} diff --git a/unittests/Support/YAMLIOTest.cpp b/unittests/Support/YAMLIOTest.cpp index 21c8430f9588..5cf0e9d0f5b3 100644 --- a/unittests/Support/YAMLIOTest.cpp +++ b/unittests/Support/YAMLIOTest.cpp @@ -1029,7 +1029,8 @@ TEST(YAMLIO, TestReadWriteBlockScalarValue) { LLVM_YAML_STRONG_TYPEDEF(int, MyNumber) LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(MyNumber) -LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::StringRef) +LLVM_YAML_STRONG_TYPEDEF(llvm::StringRef, MyString) +LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(MyString) namespace llvm { namespace yaml { @@ -1049,12 +1050,23 @@ namespace yaml { static bool mustQuote(StringRef) { return false; } }; + + template <> struct ScalarTraits<MyString> { + using Impl = ScalarTraits<StringRef>; + static void output(const MyString &V, void *Ctx, raw_ostream &OS) { + Impl::output(V, Ctx, OS); + } + static StringRef input(StringRef S, void *Ctx, MyString &V) { + return Impl::input(S, Ctx, V.value); + } + static bool mustQuote(StringRef S) { return Impl::mustQuote(S); } + }; } } struct NameAndNumbers { llvm::StringRef name; - std::vector<llvm::StringRef> strings; + std::vector<MyString> strings; std::vector<MyNumber> single; std::vector<MyNumber> numbers; }; @@ -1128,8 +1140,8 @@ TEST(YAMLIO, TestReadWriteMyFlowSequence) { EXPECT_FALSE(yin.error()); EXPECT_TRUE(map2.name.equals("hello")); EXPECT_EQ(map2.strings.size(), 2UL); - EXPECT_TRUE(map2.strings[0].equals("one")); - EXPECT_TRUE(map2.strings[1].equals("two")); + EXPECT_TRUE(map2.strings[0].value.equals("one")); + EXPECT_TRUE(map2.strings[1].value.equals("two")); EXPECT_EQ(map2.single.size(), 1UL); EXPECT_EQ(1, map2.single[0]); EXPECT_EQ(map2.numbers.size(), 3UL); @@ -1739,7 +1751,6 @@ TEST(YAMLIO, TestFlagsReadError) { // // Test error handling reading built-in uint8_t type // -LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint8_t) TEST(YAMLIO, TestReadBuiltInTypesUint8Error) { std::vector<uint8_t> seq; Input yin("---\n" @@ -1758,7 +1769,6 @@ TEST(YAMLIO, TestReadBuiltInTypesUint8Error) { // // Test error handling reading built-in uint16_t type // -LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint16_t) TEST(YAMLIO, TestReadBuiltInTypesUint16Error) { std::vector<uint16_t> seq; Input yin("---\n" @@ -1777,7 +1787,6 @@ TEST(YAMLIO, TestReadBuiltInTypesUint16Error) { // // Test error handling reading built-in uint32_t type // -LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint32_t) TEST(YAMLIO, TestReadBuiltInTypesUint32Error) { std::vector<uint32_t> seq; Input yin("---\n" @@ -1796,7 +1805,6 @@ TEST(YAMLIO, TestReadBuiltInTypesUint32Error) { // // Test error handling reading built-in uint64_t type // -LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint64_t) TEST(YAMLIO, TestReadBuiltInTypesUint64Error) { std::vector<uint64_t> seq; Input yin("---\n" @@ -1815,7 +1823,6 @@ TEST(YAMLIO, TestReadBuiltInTypesUint64Error) { // // Test error handling reading built-in int8_t type // -LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(int8_t) TEST(YAMLIO, TestReadBuiltInTypesint8OverError) { std::vector<int8_t> seq; Input yin("---\n" @@ -1853,7 +1860,6 @@ TEST(YAMLIO, TestReadBuiltInTypesint8UnderError) { // // Test error handling reading built-in int16_t type // -LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(int16_t) TEST(YAMLIO, TestReadBuiltInTypesint16UnderError) { std::vector<int16_t> seq; Input yin("---\n" @@ -1892,7 +1898,6 @@ TEST(YAMLIO, TestReadBuiltInTypesint16OverError) { // // Test error handling reading built-in int32_t type // -LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(int32_t) TEST(YAMLIO, TestReadBuiltInTypesint32UnderError) { std::vector<int32_t> seq; Input yin("---\n" @@ -1930,7 +1935,6 @@ TEST(YAMLIO, TestReadBuiltInTypesint32OverError) { // // Test error handling reading built-in int64_t type // -LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(int64_t) TEST(YAMLIO, TestReadBuiltInTypesint64UnderError) { std::vector<int64_t> seq; Input yin("---\n" @@ -1967,7 +1971,6 @@ TEST(YAMLIO, TestReadBuiltInTypesint64OverError) { // // Test error handling reading built-in float type // -LLVM_YAML_IS_SEQUENCE_VECTOR(float) TEST(YAMLIO, TestReadBuiltInTypesFloatError) { std::vector<float> seq; Input yin("---\n" @@ -1986,7 +1989,6 @@ TEST(YAMLIO, TestReadBuiltInTypesFloatError) { // // Test error handling reading built-in float type // -LLVM_YAML_IS_SEQUENCE_VECTOR(double) TEST(YAMLIO, TestReadBuiltInTypesDoubleError) { std::vector<double> seq; Input yin("---\n" |