1 //===----- CompileOnDemandLayerTest.cpp - Unit tests for the COD layer ----===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "OrcTestCommon.h"
11 #include "llvm/ExecutionEngine/Orc/LogicalDylib.h"
12 #include "gtest/gtest.h"
15 using namespace llvm::orc;
20 TEST(LogicalDylibTest, getLogicalModuleResourcesForSymbol) {
22 std::map<int, std::set<std::string>> ModuleSymbols;
24 ModuleSymbols[0] = std::set<std::string>({ "foo", "dummy" });
25 ModuleSymbols[1] = std::set<std::string>({ "bar" });
26 ModuleSymbols[2] = std::set<std::string>({ "baz", "dummy" });
28 auto MockBaseLayer = createMockBaseLayer<int>(
29 DoNothingAndReturn<int>(0),
30 DoNothingAndReturn<void>(),
31 [&](const std::string &Name, bool) {
32 for (auto &S : ModuleSymbols)
33 if (S.second.count(Name))
34 return JITSymbol(1, JITSymbolFlags::Exported);
35 return JITSymbol(nullptr);
37 [&](int H, const std::string &Name, bool) {
38 if (ModuleSymbols[H].count(Name))
39 return JITSymbol(1, JITSymbolFlags::Exported);
40 return JITSymbol(nullptr);
43 struct LDResources { };
47 std::set<std::string> *Symbols;
49 LMResources() : ID(0), Symbols(nullptr) {}
50 LMResources(int ID, std::set<std::string> &Symbols)
51 : ID(ID), Symbols(&Symbols) {}
53 JITSymbol findSymbol(const std::string &Name, bool) {
55 if (Symbols->count(Name))
56 return JITSymbol(ID, JITSymbolFlags::Exported);
57 return JITSymbol(nullptr);
61 LogicalDylib<decltype(MockBaseLayer), LMResources, LDResources>
64 // Add logical module resources for each of our dummy modules.
65 for (int I = 0; I < 3; ++I) {
66 auto H = LD.createLogicalModule();
67 LD.addToLogicalModule(H, I);
68 LD.getLogicalModuleResources(H) = LMResources(I, ModuleSymbols[I]);
72 auto LMR = LD.getLogicalModuleResourcesForSymbol("bar", true);
73 EXPECT_TRUE(LMR->ID == 1) << "getLogicalModuleResourcesForSymbol failed";