diff options
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ADT/APFloatTest.cpp | 17 | ||||
-rw-r--r-- | unittests/ADT/StringRefTest.cpp | 7 | ||||
-rw-r--r-- | unittests/CodeGen/MachineOperandTest.cpp | 63 | ||||
-rw-r--r-- | unittests/ExecutionEngine/Orc/CMakeLists.txt | 7 | ||||
-rw-r--r-- | unittests/Support/CachePruningTest.cpp | 4 | ||||
-rw-r--r-- | unittests/Support/MemoryBufferTest.cpp | 40 | ||||
-rw-r--r-- | unittests/Support/TargetParserTest.cpp | 6 | ||||
-rw-r--r-- | unittests/Support/YAMLIOTest.cpp | 107 |
8 files changed, 161 insertions, 90 deletions
diff --git a/unittests/ADT/APFloatTest.cpp b/unittests/ADT/APFloatTest.cpp index 84fb6fad15667..8b88c123b1975 100644 --- a/unittests/ADT/APFloatTest.cpp +++ b/unittests/ADT/APFloatTest.cpp @@ -849,6 +849,23 @@ TEST(APFloatTest, fromDecimalString) { EXPECT_EQ(2.71828, convertToDoubleFromString("2.71828")); } +TEST(APFloatTest, fromToStringSpecials) { + auto expects = [] (const char *first, const char *second) { + std::string roundtrip = convertToString(convertToDoubleFromString(second), 0, 3); + EXPECT_STREQ(first, roundtrip.c_str()); + }; + expects("+Inf", "+Inf"); + expects("+Inf", "INFINITY"); + expects("+Inf", "inf"); + expects("-Inf", "-Inf"); + expects("-Inf", "-INFINITY"); + expects("-Inf", "-inf"); + expects("NaN", "NaN"); + expects("NaN", "nan"); + expects("NaN", "-NaN"); + expects("NaN", "-nan"); +} + TEST(APFloatTest, fromHexadecimalString) { EXPECT_EQ( 1.0, APFloat(APFloat::IEEEdouble(), "0x1p0").convertToDouble()); EXPECT_EQ(+1.0, APFloat(APFloat::IEEEdouble(), "+0x1p0").convertToDouble()); diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp index 0684afe678f6d..0e0b5957f025d 100644 --- a/unittests/ADT/StringRefTest.cpp +++ b/unittests/ADT/StringRefTest.cpp @@ -875,7 +875,12 @@ struct GetDoubleStrings { {"0.0", false, false, 0.0}, {"-0.0", false, false, -0.0}, {"123.45", false, true, 123.45}, - {"123.45", true, false, 123.45}}; + {"123.45", true, false, 123.45}, + {"1.8e308", true, false, std::numeric_limits<double>::infinity()}, + {"1.8e308", false, true, std::numeric_limits<double>::infinity()}, + {"0x0.0000000000001P-1023", false, true, 0.0}, + {"0x0.0000000000001P-1023", true, false, 0.0}, + }; TEST(StringRefTest, getAsDouble) { for (const auto &Entry : DoubleStrings) { diff --git a/unittests/CodeGen/MachineOperandTest.cpp b/unittests/CodeGen/MachineOperandTest.cpp index e51207b957168..78a20b836486d 100644 --- a/unittests/CodeGen/MachineOperandTest.cpp +++ b/unittests/CodeGen/MachineOperandTest.cpp @@ -10,6 +10,7 @@ #include "llvm/CodeGen/MachineOperand.h" #include "llvm/ADT/ilist_node.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/InstrTypes.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/IR/ModuleSlotTracker.h" @@ -336,4 +337,66 @@ TEST(MachineOperandTest, PrintMCSymbol) { ASSERT_TRUE(OS.str() == "<mcsymbol foo>"); } +TEST(MachineOperandTest, PrintCFI) { + // Create a MachineOperand with a CFI index but no function and print it. + MachineOperand MO = MachineOperand::CreateCFIIndex(8); + + // Checking some preconditions on the newly created + // MachineOperand. + ASSERT_TRUE(MO.isCFIIndex()); + ASSERT_TRUE(MO.getCFIIndex() == 8); + + std::string str; + // Print a MachineOperand containing a CFI Index node but no machine function + // attached to it. + raw_string_ostream OS(str); + MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr); + ASSERT_TRUE(OS.str() == "<cfi directive>"); +} + +TEST(MachineOperandTest, PrintIntrinsicID) { + // Create a MachineOperand with a generic intrinsic ID. + MachineOperand MO = MachineOperand::CreateIntrinsicID(Intrinsic::bswap); + + // Checking some preconditions on the newly created + // MachineOperand. + ASSERT_TRUE(MO.isIntrinsicID()); + ASSERT_TRUE(MO.getIntrinsicID() == Intrinsic::bswap); + + std::string str; + { + // Print a MachineOperand containing a generic intrinsic ID. + raw_string_ostream OS(str); + MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr); + ASSERT_TRUE(OS.str() == "intrinsic(@llvm.bswap)"); + } + + str.clear(); + // Set a target-specific intrinsic. + MO = MachineOperand::CreateIntrinsicID((Intrinsic::ID)-1); + { + // Print a MachineOperand containing a target-specific intrinsic ID but not + // IntrinsicInfo. + raw_string_ostream OS(str); + MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr); + ASSERT_TRUE(OS.str() == "intrinsic(4294967295)"); + } +} + +TEST(MachineOperandTest, PrintPredicate) { + // Create a MachineOperand with a generic intrinsic ID. + MachineOperand MO = MachineOperand::CreatePredicate(CmpInst::ICMP_EQ); + + // Checking some preconditions on the newly created + // MachineOperand. + ASSERT_TRUE(MO.isPredicate()); + ASSERT_TRUE(MO.getPredicate() == CmpInst::ICMP_EQ); + + std::string str; + // Print a MachineOperand containing a int predicate ICMP_EQ. + raw_string_ostream OS(str); + MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr); + ASSERT_TRUE(OS.str() == "intpred(eq)"); +} + } // end namespace diff --git a/unittests/ExecutionEngine/Orc/CMakeLists.txt b/unittests/ExecutionEngine/Orc/CMakeLists.txt index 28e07959ac7bc..dd0281d0b73de 100644 --- a/unittests/ExecutionEngine/Orc/CMakeLists.txt +++ b/unittests/ExecutionEngine/Orc/CMakeLists.txt @@ -24,4 +24,9 @@ add_llvm_unittest(OrcJITTests SymbolStringPoolTest.cpp ) -target_link_libraries(OrcJITTests PRIVATE ${LLVM_PTHREAD_LIB}) +set(ORC_JIT_TEST_LIBS ${LLVM_PTHREAD_LIB}) +if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB) + list(APPEND ORC_JIT_TEST_LIBS atomic) +endif() + +target_link_libraries(OrcJITTests PRIVATE ${ORC_JIT_TEST_LIBS}) diff --git a/unittests/Support/CachePruningTest.cpp b/unittests/Support/CachePruningTest.cpp index 1bb57871925c2..4bc2ad19ba437 100644 --- a/unittests/Support/CachePruningTest.cpp +++ b/unittests/Support/CachePruningTest.cpp @@ -27,10 +27,10 @@ TEST(CachePruningPolicyParser, Interval) { EXPECT_EQ(std::chrono::seconds(1), P->Interval); P = parseCachePruningPolicy("prune_interval=2m"); ASSERT_TRUE(bool(P)); - EXPECT_EQ(std::chrono::minutes(2), P->Interval); + EXPECT_EQ(std::chrono::minutes(2), *P->Interval); P = parseCachePruningPolicy("prune_interval=3h"); ASSERT_TRUE(bool(P)); - EXPECT_EQ(std::chrono::hours(3), P->Interval); + EXPECT_EQ(std::chrono::hours(3), *P->Interval); } TEST(CachePruningPolicyParser, Expiration) { diff --git a/unittests/Support/MemoryBufferTest.cpp b/unittests/Support/MemoryBufferTest.cpp index 294581aeb928d..5e3c8db02791d 100644 --- a/unittests/Support/MemoryBufferTest.cpp +++ b/unittests/Support/MemoryBufferTest.cpp @@ -15,6 +15,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/FileUtilities.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" using namespace llvm; @@ -103,15 +104,15 @@ TEST_F(MemoryBufferTest, copy) { TEST_F(MemoryBufferTest, make_new) { // 0-sized buffer - OwningBuffer Zero(MemoryBuffer::getNewUninitMemBuffer(0)); + OwningBuffer Zero(WritableMemoryBuffer::getNewUninitMemBuffer(0)); EXPECT_TRUE(nullptr != Zero.get()); // uninitialized buffer with no name - OwningBuffer One(MemoryBuffer::getNewUninitMemBuffer(321)); + OwningBuffer One(WritableMemoryBuffer::getNewUninitMemBuffer(321)); EXPECT_TRUE(nullptr != One.get()); // uninitialized buffer with name - OwningBuffer Two(MemoryBuffer::getNewUninitMemBuffer(123, "bla")); + OwningBuffer Two(WritableMemoryBuffer::getNewUninitMemBuffer(123, "bla")); EXPECT_TRUE(nullptr != Two.get()); // 0-initialized buffer with no name @@ -226,4 +227,37 @@ TEST_F(MemoryBufferTest, slice) { EXPECT_TRUE(BufData2.substr(0x1800,8).equals("abcdefgh")); EXPECT_TRUE(BufData2.substr(0x2FF8,8).equals("abcdefgh")); } + +TEST_F(MemoryBufferTest, writableSlice) { + // Create a file initialized with some data + int FD; + SmallString<64> TestPath; + sys::fs::createTemporaryFile("MemoryBufferTest_WritableSlice", "temp", FD, + TestPath); + FileRemover Cleanup(TestPath); + raw_fd_ostream OF(FD, true); + for (unsigned i = 0; i < 0x1000; ++i) + OF << "0123456789abcdef"; + OF.close(); + + { + auto MBOrError = + WritableMemoryBuffer::getFileSlice(TestPath.str(), 0x6000, 0x2000); + ASSERT_FALSE(MBOrError.getError()); + // Write some data. It should be mapped private, so that upon completion + // the original file contents are not modified. + WritableMemoryBuffer &MB = **MBOrError; + ASSERT_EQ(0x6000u, MB.getBufferSize()); + char *Start = MB.getBufferStart(); + ASSERT_EQ(MB.getBufferEnd(), MB.getBufferStart() + MB.getBufferSize()); + ::memset(Start, 'x', MB.getBufferSize()); + } + + auto MBOrError = MemoryBuffer::getFile(TestPath); + ASSERT_FALSE(MBOrError.getError()); + auto &MB = **MBOrError; + ASSERT_EQ(0x10000u, MB.getBufferSize()); + for (size_t i = 0; i < MB.getBufferSize(); i += 0x10) + EXPECT_EQ("0123456789abcdef", MB.getBuffer().substr(i, 0x10)) << "i: " << i; +} } diff --git a/unittests/Support/TargetParserTest.cpp b/unittests/Support/TargetParserTest.cpp index dcef40345f050..48fffca1aa180 100644 --- a/unittests/Support/TargetParserTest.cpp +++ b/unittests/Support/TargetParserTest.cpp @@ -278,6 +278,12 @@ TEST(TargetParserTest, testARMCPU) { "7-S")); } +TEST(TargetParserTest, testInvalidARMArch) { + auto InvalidArchStrings = {"armv", "armv99", "noarm"}; + for (const char* InvalidArch : InvalidArchStrings) + EXPECT_EQ(ARM::parseArch(InvalidArch), ARM::ArchKind::INVALID); +} + bool testARMArch(StringRef Arch, StringRef DefaultCPU, StringRef SubArch, unsigned ArchAttr) { ARM::ArchKind AK = ARM::parseArch(Arch); diff --git a/unittests/Support/YAMLIOTest.cpp b/unittests/Support/YAMLIOTest.cpp index 9caff85a59639..914b22f0fcdf3 100644 --- a/unittests/Support/YAMLIOTest.cpp +++ b/unittests/Support/YAMLIOTest.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Endian.h" @@ -2450,94 +2451,34 @@ TEST(YAMLIO, TestCustomMappingStruct) { 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"); - std::vector<FooBar> Data; - yin >> Data; - EXPECT_TRUE((bool)yin.error()); -} - -TEST(YAMLIO, TestEscapedSingleQuote) { - std::string Id = "@abc@"; - - std::string out; - llvm::raw_string_ostream ostr(out); - Output xout(ostr, nullptr, 0); - - llvm::yaml::EmptyContext Ctx; - yamlize(xout, Id, true, Ctx); - - ostr.flush(); - EXPECT_EQ("'@abc@'", out); -} - -TEST(YAMLIO, TestEscapedNoQuote) { - std::string Id = "abc/"; - - std::string out; - llvm::raw_string_ostream ostr(out); - Output xout(ostr, nullptr, 0); - - llvm::yaml::EmptyContext Ctx; - yamlize(xout, Id, true, Ctx); - - ostr.flush(); - EXPECT_EQ("abc/", out); -} - -TEST(YAMLIO, TestEscapedDoubleQuoteNonPrintable) { - std::string Id = "\01@abc@"; - - std::string out; - llvm::raw_string_ostream ostr(out); - Output xout(ostr, nullptr, 0); - - llvm::yaml::EmptyContext Ctx; - yamlize(xout, Id, true, Ctx); - - ostr.flush(); - EXPECT_EQ("\"\\x01@abc@\"", out); -} - -TEST(YAMLIO, TestEscapedDoubleQuoteInsideSingleQuote) { - std::string Id = "abc\"fdf"; - - std::string out; - llvm::raw_string_ostream ostr(out); - Output xout(ostr, nullptr, 0); - - llvm::yaml::EmptyContext Ctx; - yamlize(xout, Id, true, Ctx); - - ostr.flush(); - EXPECT_EQ("'abc\"fdf'", out); -} - -TEST(YAMLIO, TestEscapedDoubleQuoteInsideDoubleQuote) { - std::string Id = "\01bc\"fdf"; - - std::string out; - llvm::raw_string_ostream ostr(out); - Output xout(ostr, nullptr, 0); - - llvm::yaml::EmptyContext Ctx; - yamlize(xout, Id, true, Ctx); - - ostr.flush(); - EXPECT_EQ("\"\\x01bc\\\"fdf\"", out); -} - -TEST(YAMLIO, TestEscapedSingleQuoteInsideSingleQuote) { - std::string Id = "abc'fdf"; - +static void TestEscaped(llvm::StringRef Input, llvm::StringRef Expected) { std::string out; llvm::raw_string_ostream ostr(out); Output xout(ostr, nullptr, 0); llvm::yaml::EmptyContext Ctx; - yamlize(xout, Id, true, Ctx); + yamlize(xout, Input, true, Ctx); ostr.flush(); - EXPECT_EQ("'abc''fdf'", out); + EXPECT_EQ(Expected, out); +} + +TEST(YAMLIO, TestEscaped) { + // Single quote + TestEscaped("@abc@", "'@abc@'"); + // No quote + TestEscaped("abc/", "abc/"); + // Double quote non-printable + TestEscaped("\01@abc@", "\"\\x01@abc@\""); + // Double quote inside single quote + TestEscaped("abc\"fdf", "'abc\"fdf'"); + // Double quote inside double quote + TestEscaped("\01bc\"fdf", "\"\\x01bc\\\"fdf\""); + // Single quote inside single quote + TestEscaped("abc'fdf", "'abc''fdf'"); + // UTF8 + TestEscaped("/*параметр*/", "\"/*параметр*/\""); + // UTF8 with single quote inside double quote + TestEscaped("parameter 'параметр' is unused", + "\"parameter 'параметр' is unused\""); } |