[ORC] Fix typo in LogicalDylib, add unit test.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279892 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Lang Hames 2016-08-27 00:19:05 +00:00
parent c47e5db5f7
commit fd6bad6c38
3 changed files with 78 additions and 1 deletions

View File

@ -130,7 +130,7 @@ public:
for (typename LogicalModuleList::size_type I = 0, E = LogicalModules.size();
I != E; ++I)
if (auto Sym = LogicalModules[I].Resources.findSymbol(Name, ExportedSymbolsOnly))
return &LogicalModules[I]->Resources;
return &LogicalModules[I].Resources;
return nullptr;
}

View File

@ -14,6 +14,7 @@ add_llvm_unittest(OrcJITTests
IndirectionUtilsTest.cpp
GlobalMappingLayerTest.cpp
LazyEmittingLayerTest.cpp
LogicalDylibTest.cpp
ObjectLinkingLayerTest.cpp
ObjectTransformLayerTest.cpp
OrcCAPITest.cpp

View File

@ -0,0 +1,76 @@
//===----- CompileOnDemandLayerTest.cpp - Unit tests for the COD layer ----===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "OrcTestCommon.h"
#include "llvm/ExecutionEngine/Orc/LogicalDylib.h"
#include "gtest/gtest.h"
using namespace llvm;
using namespace llvm::orc;
namespace {
TEST(LogicalDylibTest, getLogicalModuleResourcesForSymbol) {
std::map<int, std::set<std::string>> ModuleSymbols;
ModuleSymbols[0] = { "foo", "dummy" };
ModuleSymbols[1] = { "bar" };
ModuleSymbols[2] = { "baz", "dummy" };
auto MockBaseLayer = createMockBaseLayer<int>(
DoNothingAndReturn<int>(0),
DoNothingAndReturn<void>(),
[&](const std::string &Name, bool) {
for (auto &S : ModuleSymbols)
if (S.second.count(Name))
return JITSymbol(1, JITSymbolFlags::Exported);
return JITSymbol(nullptr);
},
[&](int H, const std::string &Name, bool) {
if (ModuleSymbols[H].count(Name))
return JITSymbol(1, JITSymbolFlags::Exported);
return JITSymbol(nullptr);
});
struct LDResources { };
struct LMResources {
public:
int ID;
std::set<std::string> *Symbols;
LMResources() : ID(0), Symbols(nullptr) {}
LMResources(int ID, std::set<std::string> &Symbols)
: ID(ID), Symbols(&Symbols) {}
JITSymbol findSymbol(const std::string &Name, bool) {
assert(Symbols);
if (Symbols->count(Name))
return JITSymbol(ID, JITSymbolFlags::Exported);
return JITSymbol(nullptr);
}
};
LogicalDylib<decltype(MockBaseLayer), LMResources, LDResources>
LD(MockBaseLayer);
// Add logical module resources for each of our dummy modules.
for (int I = 0; I < 3; ++I) {
auto H = LD.createLogicalModule();
LD.addToLogicalModule(H, I);
LD.getLogicalModuleResources(H) = LMResources(I, ModuleSymbols[I]);
}
{
auto LMR = LD.getLogicalModuleResourcesForSymbol("bar", true);
EXPECT_TRUE(LMR->ID == 1) << "getLogicalModuleResourcesForSymbol failed";
}
}
}