diff options
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ADT/DenseMapTest.cpp | 12 | ||||
-rw-r--r-- | unittests/ADT/StringRefTest.cpp | 97 | ||||
-rw-r--r-- | unittests/ExecutionEngine/JIT/JITTest.cpp | 54 |
3 files changed, 159 insertions, 4 deletions
diff --git a/unittests/ADT/DenseMapTest.cpp b/unittests/ADT/DenseMapTest.cpp index 15a5379..afac651 100644 --- a/unittests/ADT/DenseMapTest.cpp +++ b/unittests/ADT/DenseMapTest.cpp @@ -164,4 +164,16 @@ TEST_F(DenseMapTest, IterationTest) { } } +// const_iterator test +TEST_F(DenseMapTest, ConstIteratorTest) { + // Check conversion from iterator to const_iterator. + DenseMap<uint32_t, uint32_t>::iterator it = uintMap.begin(); + DenseMap<uint32_t, uint32_t>::const_iterator cit(it); + EXPECT_TRUE(it == cit); + + // Check copying of const_iterators. + DenseMap<uint32_t, uint32_t>::const_iterator cit2(cit); + EXPECT_TRUE(cit == cit2); +} + } diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp index cdc476e..11545d5 100644 --- a/unittests/ADT/StringRefTest.cpp +++ b/unittests/ADT/StringRefTest.cpp @@ -9,6 +9,7 @@ #include "gtest/gtest.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; @@ -110,6 +111,92 @@ TEST(StringRefTest, Split) { Str.rsplit('o')); } +// XFAIL for PR5482, StringRef is miscompiled by Apple gcc. +#if (!defined(__llvm__) && defined(__APPLE__) && defined(__OPTIMIZE__)) +#define SKIP_SPLIT2 +#endif +#ifndef SKIP_SPLIT2 +TEST(StringRefTest, Split2) { + SmallVector<StringRef, 5> parts; + SmallVector<StringRef, 5> expected; + + expected.push_back("ab"); expected.push_back("c"); + StringRef(",ab,,c,").split(parts, ",", -1, false); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back(""); expected.push_back("ab"); expected.push_back(""); + expected.push_back("c"); expected.push_back(""); + StringRef(",ab,,c,").split(parts, ",", -1, true); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back(""); + StringRef("").split(parts, ",", -1, true); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + StringRef("").split(parts, ",", -1, false); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + StringRef(",").split(parts, ",", -1, false); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back(""); expected.push_back(""); + StringRef(",").split(parts, ",", -1, true); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back("a"); expected.push_back("b"); + StringRef("a,b").split(parts, ",", -1, true); + EXPECT_TRUE(parts == expected); + + // Test MaxSplit + expected.clear(); parts.clear(); + expected.push_back("a,,b,c"); + StringRef("a,,b,c").split(parts, ",", 0, true); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back("a,,b,c"); + StringRef("a,,b,c").split(parts, ",", 0, false); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back("a"); expected.push_back(",b,c"); + StringRef("a,,b,c").split(parts, ",", 1, true); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back("a"); expected.push_back(",b,c"); + StringRef("a,,b,c").split(parts, ",", 1, false); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back("a"); expected.push_back(""); expected.push_back("b,c"); + StringRef("a,,b,c").split(parts, ",", 2, true); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back("a"); expected.push_back("b,c"); + StringRef("a,,b,c").split(parts, ",", 2, false); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back("a"); expected.push_back(""); expected.push_back("b"); + expected.push_back("c"); + StringRef("a,,b,c").split(parts, ",", 3, true); + EXPECT_TRUE(parts == expected); + + expected.clear(); parts.clear(); + expected.push_back("a"); expected.push_back("b"); expected.push_back("c"); + StringRef("a,,b,c").split(parts, ",", 3, false); + EXPECT_TRUE(parts == expected); +} +#endif + TEST(StringRefTest, StartsWith) { StringRef Str("hello"); EXPECT_TRUE(Str.startswith("he")); @@ -125,6 +212,8 @@ TEST(StringRefTest, Find) { EXPECT_EQ(0U, Str.find("hello")); EXPECT_EQ(1U, Str.find("ello")); EXPECT_EQ(StringRef::npos, Str.find("zz")); + EXPECT_EQ(2U, Str.find("ll", 2)); + EXPECT_EQ(StringRef::npos, Str.find("ll", 3)); EXPECT_EQ(3U, Str.rfind('l')); EXPECT_EQ(StringRef::npos, Str.rfind('z')); @@ -132,6 +221,14 @@ TEST(StringRefTest, Find) { EXPECT_EQ(0U, Str.rfind("hello")); EXPECT_EQ(1U, Str.rfind("ello")); EXPECT_EQ(StringRef::npos, Str.rfind("zz")); + + EXPECT_EQ(2U, Str.find_first_of('l')); + EXPECT_EQ(1U, Str.find_first_of("el")); + EXPECT_EQ(StringRef::npos, Str.find_first_of("xyz")); + + EXPECT_EQ(1U, Str.find_first_not_of('h')); + EXPECT_EQ(4U, Str.find_first_not_of("hel")); + EXPECT_EQ(StringRef::npos, Str.find_first_not_of("hello")); } TEST(StringRefTest, Count) { diff --git a/unittests/ExecutionEngine/JIT/JITTest.cpp b/unittests/ExecutionEngine/JIT/JITTest.cpp index e0568ad..98b2922 100644 --- a/unittests/ExecutionEngine/JIT/JITTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITTest.cpp @@ -61,6 +61,7 @@ class RecordingJITMemoryManager : public JITMemoryManager { public: RecordingJITMemoryManager() : Base(JITMemoryManager::CreateDefaultMemManager()) { + stubsAllocated = 0; } virtual void setMemoryWritable() { Base->setMemoryWritable(); } @@ -68,8 +69,6 @@ public: virtual void setPoisonMemory(bool poison) { Base->setPoisonMemory(poison); } virtual void AllocateGOT() { Base->AllocateGOT(); } virtual uint8_t *getGOTBase() const { return Base->getGOTBase(); } - virtual void SetDlsymTable(void *ptr) { Base->SetDlsymTable(ptr); } - virtual void *getDlsymTable() const { return Base->getDlsymTable(); } struct StartFunctionBodyCall { StartFunctionBodyCall(uint8_t *Result, const Function *F, uintptr_t ActualSize, uintptr_t ActualSizeResult) @@ -90,8 +89,10 @@ public: StartFunctionBodyCall(Result, F, InitialActualSize, ActualSize)); return Result; } + int stubsAllocated; virtual uint8_t *allocateStub(const GlobalValue* F, unsigned StubSize, unsigned Alignment) { + stubsAllocated++; return Base->allocateStub(F, StubSize, Alignment); } struct EndFunctionBodyCall { @@ -303,7 +304,6 @@ TEST_F(JITTest, FarCallToKnownFunction) { ConstantInt::get(TypeBuilder<int, false>::get(Context), 7)); Builder.CreateRet(result); - TheJIT->EnableDlsymStubs(false); TheJIT->DisableLazyCompilation(true); int (*TestFunctionPtr)() = reinterpret_cast<int(*)()>( (intptr_t)TheJIT->getPointerToFunction(TestFunction)); @@ -437,10 +437,16 @@ TEST_F(JITTest, ModuleDeletion) { RJMM->deallocateFunctionBodyCalls.size()); SmallPtrSet<const void*, 2> ExceptionTablesDeallocated; + unsigned NumTablesDeallocated = 0; for (unsigned i = 0, e = RJMM->deallocateExceptionTableCalls.size(); i != e; ++i) { ExceptionTablesDeallocated.insert( RJMM->deallocateExceptionTableCalls[i].ET); + if (RJMM->deallocateExceptionTableCalls[i].ET != NULL) { + // If JITEmitDebugInfo is off, we'll "deallocate" NULL, which doesn't + // appear in startExceptionTableCalls. + NumTablesDeallocated++; + } } for (unsigned i = 0, e = RJMM->startExceptionTableCalls.size(); i != e; ++i) { EXPECT_TRUE(ExceptionTablesDeallocated.count( @@ -449,9 +455,49 @@ TEST_F(JITTest, ModuleDeletion) { << RJMM->startExceptionTableCalls[i].F_dump; } EXPECT_EQ(RJMM->startExceptionTableCalls.size(), - RJMM->deallocateExceptionTableCalls.size()); + NumTablesDeallocated); } +#if !defined(__arm__) && !defined(__powerpc__) && !defined(__ppc__) +typedef int (*FooPtr) (); + +TEST_F(JITTest, NoStubs) { + LoadAssembly("define void @bar() {" + "entry: " + "ret void" + "}" + " " + "define i32 @foo() {" + "entry:" + "call void @bar()" + "ret i32 undef" + "}" + " " + "define i32 @main() {" + "entry:" + "%0 = call i32 @foo()" + "call void @bar()" + "ret i32 undef" + "}"); + Function *foo = M->getFunction("foo"); + uintptr_t tmp = (uintptr_t)(TheJIT->getPointerToFunction(foo)); + FooPtr ptr = (FooPtr)(tmp); + + (ptr)(); + + // We should now allocate no more stubs, we have the code to foo + // and the existing stub for bar. + int stubsBefore = RJMM->stubsAllocated; + Function *func = M->getFunction("main"); + TheJIT->getPointerToFunction(func); + + Function *bar = M->getFunction("bar"); + TheJIT->getPointerToFunction(bar); + + ASSERT_EQ(stubsBefore, RJMM->stubsAllocated); +} +#endif + // This code is copied from JITEventListenerTest, but it only runs once for all // the tests in this directory. Everything seems fine, but that's strange // behavior. |