mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-25 12:50:00 +00:00
[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:
parent
c47e5db5f7
commit
fd6bad6c38
@ -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;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ add_llvm_unittest(OrcJITTests
|
||||
IndirectionUtilsTest.cpp
|
||||
GlobalMappingLayerTest.cpp
|
||||
LazyEmittingLayerTest.cpp
|
||||
LogicalDylibTest.cpp
|
||||
ObjectLinkingLayerTest.cpp
|
||||
ObjectTransformLayerTest.cpp
|
||||
OrcCAPITest.cpp
|
||||
|
76
unittests/ExecutionEngine/Orc/LogicalDylibTest.cpp
Normal file
76
unittests/ExecutionEngine/Orc/LogicalDylibTest.cpp
Normal 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";
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user