1 //===----- CompileOnDemandLayerTest.cpp - Unit tests for the COD layer ----===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "OrcTestCommon.h"
11 #include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
12 #include "gtest/gtest.h"
13
14 using namespace llvm;
15 using namespace llvm::orc;
16
17 namespace {
18
19 class DummyCallbackManager : public orc::JITCompileCallbackManager {
20 public:
DummyCallbackManager()21 DummyCallbackManager() : JITCompileCallbackManager(0) { }
22 public:
grow()23 void grow() override { llvm_unreachable("not implemented"); }
24 };
25
26 class DummyStubsManager : public orc::IndirectStubsManager {
27 public:
createStub(StringRef StubName,TargetAddress InitAddr,JITSymbolFlags Flags)28 std::error_code createStub(StringRef StubName, TargetAddress InitAddr,
29 JITSymbolFlags Flags) override {
30 llvm_unreachable("Not implemented");
31 }
32
createStubs(const StubInitsMap & StubInits)33 std::error_code createStubs(const StubInitsMap &StubInits) override {
34 llvm_unreachable("Not implemented");
35 }
36
findStub(StringRef Name,bool ExportedStubsOnly)37 JITSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
38 llvm_unreachable("Not implemented");
39 }
40
findPointer(StringRef Name)41 JITSymbol findPointer(StringRef Name) override {
42 llvm_unreachable("Not implemented");
43 }
44
updatePointer(StringRef Name,TargetAddress NewAddr)45 std::error_code updatePointer(StringRef Name,
46 TargetAddress NewAddr) override {
47 llvm_unreachable("Not implemented");
48 }
49 };
50
TEST(CompileOnDemandLayerTest,FindSymbol)51 TEST(CompileOnDemandLayerTest, FindSymbol) {
52 auto MockBaseLayer =
53 createMockBaseLayer<int>(DoNothingAndReturn<int>(0),
54 DoNothingAndReturn<void>(),
55 [](const std::string &Name, bool) {
56 if (Name == "foo")
57 return JITSymbol(1, JITSymbolFlags::Exported);
58 return JITSymbol(nullptr);
59 },
60 DoNothingAndReturn<JITSymbol>(nullptr));
61
62 typedef decltype(MockBaseLayer) MockBaseLayerT;
63 DummyCallbackManager CallbackMgr;
64
65 llvm::orc::CompileOnDemandLayer<MockBaseLayerT> COD(
66 MockBaseLayer, [](Function &F) { return std::set<Function *>{&F}; },
67 CallbackMgr, [] { return llvm::make_unique<DummyStubsManager>(); }, true);
68
69 auto Sym = COD.findSymbol("foo", true);
70
71 EXPECT_TRUE(!!Sym)
72 << "CompileOnDemand::findSymbol should call findSymbol in the base layer.";
73 }
74
75 }
76