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
14using namespace llvm;
15using namespace llvm::orc;
16
17namespace {
18
19class DummyCallbackManager : public orc::JITCompileCallbackManager {
20public:
21  DummyCallbackManager() : JITCompileCallbackManager(0) { }
22public:
23  void grow() override { llvm_unreachable("not implemented"); }
24};
25
26class DummyStubsManager : public orc::IndirectStubsManager {
27public:
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
51TEST(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