• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23 public:
grow()24   void grow() override { llvm_unreachable("not implemented"); }
25 };
26 
27 class DummyStubsManager : public orc::IndirectStubsManager {
28 public:
createStub(StringRef StubName,TargetAddress InitAddr,JITSymbolFlags Flags)29   Error createStub(StringRef StubName, TargetAddress InitAddr,
30                    JITSymbolFlags Flags) override {
31     llvm_unreachable("Not implemented");
32   }
33 
createStubs(const StubInitsMap & StubInits)34   Error createStubs(const StubInitsMap &StubInits) override {
35     llvm_unreachable("Not implemented");
36   }
37 
findStub(StringRef Name,bool ExportedStubsOnly)38   JITSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
39     llvm_unreachable("Not implemented");
40   }
41 
findPointer(StringRef Name)42   JITSymbol findPointer(StringRef Name) override {
43     llvm_unreachable("Not implemented");
44   }
45 
updatePointer(StringRef Name,TargetAddress NewAddr)46   Error updatePointer(StringRef Name, TargetAddress NewAddr) override {
47     llvm_unreachable("Not implemented");
48   }
49 };
50 
TEST(CompileOnDemandLayerTest,FindSymbol)51 TEST(CompileOnDemandLayerTest, FindSymbol) {
52   auto MockBaseLayer = createMockBaseLayer<int>(
53       DoNothingAndReturn<int>(0), DoNothingAndReturn<void>(),
54       [](const std::string &Name, bool) {
55         if (Name == "foo")
56           return JITSymbol(1, JITSymbolFlags::Exported);
57         return JITSymbol(nullptr);
58       },
59       DoNothingAndReturn<JITSymbol>(nullptr));
60 
61   typedef decltype(MockBaseLayer) MockBaseLayerT;
62   DummyCallbackManager CallbackMgr;
63 
64   llvm::orc::CompileOnDemandLayer<MockBaseLayerT> COD(
65       MockBaseLayer, [](Function &F) { return std::set<Function *>{&F}; },
66       CallbackMgr, [] { return llvm::make_unique<DummyStubsManager>(); }, true);
67 
68   auto Sym = COD.findSymbol("foo", true);
69 
70   EXPECT_TRUE(!!Sym) << "CompileOnDemand::findSymbol should call findSymbol in "
71                         "the base layer.";
72 }
73 }
74