Lang Hames | a4b3d4e | 2015-08-27 22:20:05 +0000 | [diff] [blame] | 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 | |
Lang Hames | 2c0403e | 2017-07-06 21:33:48 +0000 | [diff] [blame] | 20 | typedef int ModuleHandleT; |
Lang Hames | a4b3d4e | 2015-08-27 22:20:05 +0000 | [diff] [blame] | 21 | |
| 22 | JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) { |
| 23 | if (Name == "bar") |
Lang Hames | ad4a911 | 2016-08-01 20:49:11 +0000 | [diff] [blame] | 24 | return llvm::JITSymbol(0x4567, JITSymbolFlags::Exported); |
Lang Hames | a4b3d4e | 2015-08-27 22:20:05 +0000 | [diff] [blame] | 25 | return nullptr; |
| 26 | } |
| 27 | |
| 28 | }; |
| 29 | |
| 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); |
Lang Hames | 4ce9866 | 2017-07-07 02:59:13 +0000 | [diff] [blame^] | 40 | EXPECT_EQ(cantFail(BarSym.getAddress()), |
| 41 | static_cast<JITTargetAddress>(0x4567)) |
Lang Hames | a4b3d4e | 2015-08-27 22:20:05 +0000 | [diff] [blame] | 42 | << "Symbol lookup fall-through failed."; |
| 43 | |
| 44 | // Test setup of a global mapping. |
| 45 | L.setGlobalMapping("foo", 0x0123); |
| 46 | auto FooSym2 = L.findSymbol("foo", true); |
Lang Hames | 4ce9866 | 2017-07-07 02:59:13 +0000 | [diff] [blame^] | 47 | EXPECT_EQ(cantFail(FooSym2.getAddress()), |
| 48 | static_cast<JITTargetAddress>(0x0123)) |
Lang Hames | a4b3d4e | 2015-08-27 22:20:05 +0000 | [diff] [blame] | 49 | << "Symbol mapping setup failed."; |
| 50 | |
| 51 | // Test removal of a global mapping. |
| 52 | L.eraseGlobalMapping("foo"); |
| 53 | auto FooSym3 = L.findSymbol("foo", true); |
| 54 | EXPECT_FALSE(FooSym3) << "Symbol mapping removal failed."; |
| 55 | } |
| 56 | |
| 57 | } |