summaryrefslogtreecommitdiff
path: root/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp')
-rw-r--r--unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp60
1 files changed, 31 insertions, 29 deletions
diff --git a/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp b/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
index 7c821bc2c34b3..e4b61d855c5f4 100644
--- a/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
+++ b/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
@@ -45,9 +45,9 @@ public:
};
TEST(RTDyldObjectLinkingLayerTest, TestSetProcessAllSections) {
- class SectionMemoryManagerWrapper : public SectionMemoryManager {
+ class MemoryManagerWrapper : public SectionMemoryManager {
public:
- SectionMemoryManagerWrapper(bool &DebugSeen) : DebugSeen(DebugSeen) {}
+ MemoryManagerWrapper(bool &DebugSeen) : DebugSeen(DebugSeen) {}
uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
unsigned SectionID,
StringRef SectionName,
@@ -63,7 +63,10 @@ TEST(RTDyldObjectLinkingLayerTest, TestSetProcessAllSections) {
bool &DebugSeen;
};
- RTDyldObjectLinkingLayer ObjLayer;
+ bool DebugSectionSeen = false;
+ auto MM = std::make_shared<MemoryManagerWrapper>(DebugSectionSeen);
+
+ RTDyldObjectLinkingLayer ObjLayer([&MM]() { return MM; });
LLVMContext Context;
auto M = llvm::make_unique<Module>("", Context);
@@ -89,9 +92,6 @@ TEST(RTDyldObjectLinkingLayerTest, TestSetProcessAllSections) {
std::make_shared<object::OwningBinary<object::ObjectFile>>(
SimpleCompiler(*TM)(*M));
- bool DebugSectionSeen = false;
- auto SMMW =
- std::make_shared<SectionMemoryManagerWrapper>(DebugSectionSeen);
auto Resolver =
createLambdaResolver(
[](const std::string &Name) {
@@ -103,21 +103,21 @@ TEST(RTDyldObjectLinkingLayerTest, TestSetProcessAllSections) {
{
// Test with ProcessAllSections = false (the default).
- auto H = ObjLayer.addObject(Obj, SMMW, &*Resolver);
- ObjLayer.emitAndFinalize(H);
+ auto H = cantFail(ObjLayer.addObject(Obj, Resolver));
+ cantFail(ObjLayer.emitAndFinalize(H));
EXPECT_EQ(DebugSectionSeen, false)
<< "Unexpected debug info section";
- ObjLayer.removeObject(H);
+ cantFail(ObjLayer.removeObject(H));
}
{
// Test with ProcessAllSections = true.
ObjLayer.setProcessAllSections(true);
- auto H = ObjLayer.addObject(Obj, SMMW, &*Resolver);
- ObjLayer.emitAndFinalize(H);
+ auto H = cantFail(ObjLayer.addObject(Obj, Resolver));
+ cantFail(ObjLayer.emitAndFinalize(H));
EXPECT_EQ(DebugSectionSeen, true)
<< "Expected debug info section not seen";
- ObjLayer.removeObject(H);
+ cantFail(ObjLayer.removeObject(H));
}
}
@@ -125,7 +125,9 @@ TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoDuplicateFinalization) {
if (!TM)
return;
- RTDyldObjectLinkingLayer ObjLayer;
+ auto MM = std::make_shared<SectionMemoryManagerWrapper>();
+
+ RTDyldObjectLinkingLayer ObjLayer([&MM]() { return MM; });
SimpleCompiler Compile(*TM);
// Create a pair of modules that will trigger recursive finalization:
@@ -179,15 +181,14 @@ TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoDuplicateFinalization) {
return JITSymbol(nullptr);
});
- auto SMMW = std::make_shared<SectionMemoryManagerWrapper>();
- ObjLayer.addObject(std::move(Obj1), SMMW, &*Resolver);
- auto H = ObjLayer.addObject(std::move(Obj2), SMMW, &*Resolver);
- ObjLayer.emitAndFinalize(H);
- ObjLayer.removeObject(H);
-
+ cantFail(ObjLayer.addObject(std::move(Obj1), Resolver));
+ auto H = cantFail(ObjLayer.addObject(std::move(Obj2), Resolver));
+ cantFail(ObjLayer.emitAndFinalize(H));
+ cantFail(ObjLayer.removeObject(H));
+
// Finalization of module 2 should trigger finalization of module 1.
// Verify that finalize on SMMW is only called once.
- EXPECT_EQ(SMMW->FinalizationCount, 1)
+ EXPECT_EQ(MM->FinalizationCount, 1)
<< "Extra call to finalize";
}
@@ -195,7 +196,9 @@ TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoPrematureAllocation) {
if (!TM)
return;
- RTDyldObjectLinkingLayer ObjLayer;
+ auto MM = std::make_shared<SectionMemoryManagerWrapper>();
+
+ RTDyldObjectLinkingLayer ObjLayer([&MM]() { return MM; });
SimpleCompiler Compile(*TM);
// Create a pair of unrelated modules:
@@ -240,15 +243,14 @@ TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoPrematureAllocation) {
std::make_shared<object::OwningBinary<object::ObjectFile>>(
Compile(*MB2.getModule()));
- auto SMMW = std::make_shared<SectionMemoryManagerWrapper>();
- NullResolver NR;
- auto H = ObjLayer.addObject(std::move(Obj1), SMMW, &NR);
- ObjLayer.addObject(std::move(Obj2), SMMW, &NR);
- ObjLayer.emitAndFinalize(H);
- ObjLayer.removeObject(H);
-
+ auto NR = std::make_shared<NullResolver>();
+ auto H = cantFail(ObjLayer.addObject(std::move(Obj1), NR));
+ cantFail(ObjLayer.addObject(std::move(Obj2), NR));
+ cantFail(ObjLayer.emitAndFinalize(H));
+ cantFail(ObjLayer.removeObject(H));
+
// Only one call to needsToReserveAllocationSpace should have been made.
- EXPECT_EQ(SMMW->NeedsToReserveAllocationSpaceCount, 1)
+ EXPECT_EQ(MM->NeedsToReserveAllocationSpaceCount, 1)
<< "More than one call to needsToReserveAllocationSpace "
"(multiple unrelated objects loaded prior to finalization)";
}