[Orc] Rename IndirectStubsManagerBase to IndirectStubsManager.
[oota-llvm.git] / unittests / ExecutionEngine / Orc / CompileOnDemandLayerTest.cpp
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:
21   DummyCallbackManager() : JITCompileCallbackManager(0) { }
22 public:
23   void grow() override { llvm_unreachable("not implemented"); }
24 };
25
26 class DummyStubsManager : public orc::IndirectStubsManager {
27 public:
28   std::error_code createStub(StringRef StubName, TargetAddress InitAddr,
29                              JITSymbolFlags Flags) override {
30     llvm_unreachable("Not implemented");
31   }
32
33   std::error_code createStubs(const StubInitsMap &StubInits) override {
34     llvm_unreachable("Not implemented");
35   }
36
37   JITSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
38     llvm_unreachable("Not implemented");
39   }
40
41   JITSymbol findPointer(StringRef Name) override {
42     llvm_unreachable("Not implemented");
43   }
44
45   std::error_code updatePointer(StringRef Name,
46                                 TargetAddress NewAddr) override {
47     llvm_unreachable("Not implemented");
48   }
49 };
50
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 }