1 //===--- GlobalMappingLayerTest.cpp - Unit test the global mapping layer --===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ExecutionEngine/Orc/GlobalMappingLayer.h"
10 #include "OrcTestCommon.h"
11 #include "gtest/gtest.h"
14 using namespace llvm::orc
;
18 TEST(GlobalMappingLayerTest
, Empty
) {
19 MockBaseLayer
<int, std::shared_ptr
<Module
>> TestBaseLayer
;
21 TestBaseLayer
.addModuleImpl
=
22 [](std::shared_ptr
<Module
> M
, std::shared_ptr
<JITSymbolResolver
> R
) {
26 TestBaseLayer
.findSymbolImpl
=
27 [](const std::string
&Name
, bool ExportedSymbolsOnly
) -> JITSymbol
{
29 return llvm::JITSymbol(0x4567, JITSymbolFlags::Exported
);
33 GlobalMappingLayer
<decltype(TestBaseLayer
)> L(TestBaseLayer
);
35 // Test addModule interface.
36 int H
= cantFail(L
.addModule(nullptr, nullptr));
37 EXPECT_EQ(H
, 42) << "Incorrect result from addModule";
39 // Test fall-through for missing symbol.
40 auto FooSym
= L
.findSymbol("foo", true);
41 EXPECT_FALSE(FooSym
) << "Found unexpected symbol.";
43 // Test fall-through for symbol in base layer.
44 auto BarSym
= L
.findSymbol("bar", true);
45 EXPECT_EQ(cantFail(BarSym
.getAddress()),
46 static_cast<JITTargetAddress
>(0x4567))
47 << "Symbol lookup fall-through failed.";
49 // Test setup of a global mapping.
50 L
.setGlobalMapping("foo", 0x0123);
51 auto FooSym2
= L
.findSymbol("foo", true);
52 EXPECT_EQ(cantFail(FooSym2
.getAddress()),
53 static_cast<JITTargetAddress
>(0x0123))
54 << "Symbol mapping setup failed.";
56 // Test removal of a global mapping.
57 L
.eraseGlobalMapping("foo");
58 auto FooSym3
= L
.findSymbol("foo", true);
59 EXPECT_FALSE(FooSym3
) << "Symbol mapping removal failed.";