1 //===--- GlobalMappingLayerTest.cpp - Unit test the global mapping 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 "llvm/ExecutionEngine/Orc/GlobalMappingLayer.h"
11 #include "gtest/gtest.h"
12 
13 using namespace llvm;
14 using namespace llvm::orc;
15 
16 namespace {
17 
18 struct MockBaseLayer {
19 
20   typedef int ModuleSetHandleT;
21 
findSymbol__anon150238740111::MockBaseLayer22   JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {
23     if (Name == "bar")
24       return llvm::orc::JITSymbol(0x4567, JITSymbolFlags::Exported);
25     return nullptr;
26   }
27 
28 };
29 
TEST(GlobalMappingLayerTest,Empty)30 TEST(GlobalMappingLayerTest, Empty) {
31   MockBaseLayer M;
32   GlobalMappingLayer<MockBaseLayer> L(M);
33 
34   // Test fall-through for missing symbol.
35   auto FooSym = L.findSymbol("foo", true);
36   EXPECT_FALSE(FooSym) << "Found unexpected symbol.";
37 
38   // Test fall-through for symbol in base layer.
39   auto BarSym = L.findSymbol("bar", true);
40   EXPECT_EQ(BarSym.getAddress(), static_cast<TargetAddress>(0x4567))
41     << "Symbol lookup fall-through failed.";
42 
43   // Test setup of a global mapping.
44   L.setGlobalMapping("foo", 0x0123);
45   auto FooSym2 = L.findSymbol("foo", true);
46   EXPECT_EQ(FooSym2.getAddress(), static_cast<TargetAddress>(0x0123))
47     << "Symbol mapping setup failed.";
48 
49   // Test removal of a global mapping.
50   L.eraseGlobalMapping("foo");
51   auto FooSym3 = L.findSymbol("foo", true);
52   EXPECT_FALSE(FooSym3) << "Symbol mapping removal failed.";
53 }
54 
55 }
56