| 1 |
//===- LookupAndRecordAddrsTest.cpp - Unit tests for LookupAndRecordAddrs -===// |
| 2 |
// |
| 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 |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#include "OrcTestCommon.h" |
| 10 |
|
| 11 |
#include "llvm/ExecutionEngine/Orc/LookupAndRecordAddrs.h" |
| 12 |
#include "llvm/Support/MSVCErrorWorkarounds.h" |
| 13 |
#include "llvm/Testing/Support/Error.h" |
| 14 |
|
| 15 |
#include <future> |
| 16 |
|
| 17 |
using namespace llvm; |
| 18 |
using namespace llvm::orc; |
| 19 |
|
| 20 |
class LookupAndRecordAddrsTest : public CoreAPIsBasedStandardTest {}; |
| 21 |
|
| 22 |
namespace { |
| 23 |
|
| 24 |
TEST_F(LookupAndRecordAddrsTest, AsyncRequiredSuccess) { |
| 25 |
cantFail(JD.define(absoluteSymbols({{Foo, FooSym}, {Bar, BarSym}}))); |
| 26 |
|
| 27 |
ExecutorAddr FooAddress, BarAddress; |
| 28 |
std::promise<MSVCPError> ErrP; |
| 29 |
|
| 30 |
lookupAndRecordAddrs([&](Error Err) { ErrP.set_value(std::move(Err)); }, ES, |
| 31 |
LookupKind::Static, makeJITDylibSearchOrder(&JD), |
| 32 |
{{Foo, &FooAddress}, {Bar, &BarAddress}}); |
| 33 |
|
| 34 |
Error Err = ErrP.get_future().get(); |
| 35 |
|
| 36 |
EXPECT_THAT_ERROR(std::move(Err), Succeeded()); |
| 37 |
EXPECT_EQ(FooAddress.getValue(), FooAddr); |
| 38 |
EXPECT_EQ(BarAddress.getValue(), BarAddr); |
| 39 |
} |
| 40 |
|
| 41 |
TEST_F(LookupAndRecordAddrsTest, AsyncRequiredFailure) { |
| 42 |
ExecutorAddr FooAddress, BarAddress; |
| 43 |
std::promise<MSVCPError> ErrP; |
| 44 |
|
| 45 |
lookupAndRecordAddrs([&](Error Err) { ErrP.set_value(std::move(Err)); }, ES, |
| 46 |
LookupKind::Static, makeJITDylibSearchOrder(&JD), |
| 47 |
{{Foo, &FooAddress}, {Bar, &BarAddress}}); |
| 48 |
|
| 49 |
Error Err = ErrP.get_future().get(); |
| 50 |
|
| 51 |
EXPECT_THAT_ERROR(std::move(Err), Failed()); |
| 52 |
} |
| 53 |
|
| 54 |
TEST_F(LookupAndRecordAddrsTest, AsyncWeakReference) { |
| 55 |
cantFail(JD.define(absoluteSymbols({{Foo, FooSym}}))); |
| 56 |
|
| 57 |
ExecutorAddr FooAddress, BarAddress; |
| 58 |
std::promise<MSVCPError> ErrP; |
| 59 |
|
| 60 |
lookupAndRecordAddrs([&](Error Err) { ErrP.set_value(std::move(Err)); }, ES, |
| 61 |
LookupKind::Static, makeJITDylibSearchOrder(&JD), |
| 62 |
{{Foo, &FooAddress}, {Bar, &BarAddress}}, |
| 63 |
SymbolLookupFlags::WeaklyReferencedSymbol); |
| 64 |
|
| 65 |
Error Err = ErrP.get_future().get(); |
| 66 |
|
| 67 |
EXPECT_THAT_ERROR(std::move(Err), Succeeded()); |
| 68 |
EXPECT_EQ(FooAddress.getValue(), FooAddr); |
| 69 |
EXPECT_EQ(BarAddress.getValue(), 0U); |
| 70 |
} |
| 71 |
|
| 72 |
TEST_F(LookupAndRecordAddrsTest, BlockingRequiredSuccess) { |
| 73 |
cantFail(JD.define(absoluteSymbols({{Foo, FooSym}, {Bar, BarSym}}))); |
| 74 |
|
| 75 |
ExecutorAddr FooAddress, BarAddress; |
| 76 |
auto Err = |
| 77 |
lookupAndRecordAddrs(ES, LookupKind::Static, makeJITDylibSearchOrder(&JD), |
| 78 |
{{Foo, &FooAddress}, {Bar, &BarAddress}}); |
| 79 |
|
| 80 |
EXPECT_THAT_ERROR(std::move(Err), Succeeded()); |
| 81 |
EXPECT_EQ(FooAddress.getValue(), FooAddr); |
| 82 |
EXPECT_EQ(BarAddress.getValue(), BarAddr); |
| 83 |
} |
| 84 |
|
| 85 |
TEST_F(LookupAndRecordAddrsTest, BlockingRequiredFailure) { |
| 86 |
ExecutorAddr FooAddress, BarAddress; |
| 87 |
auto Err = |
| 88 |
lookupAndRecordAddrs(ES, LookupKind::Static, makeJITDylibSearchOrder(&JD), |
| 89 |
{{Foo, &FooAddress}, {Bar, &BarAddress}}); |
| 90 |
|
| 91 |
EXPECT_THAT_ERROR(std::move(Err), Failed()); |
| 92 |
} |
| 93 |
|
| 94 |
TEST_F(LookupAndRecordAddrsTest, BlockingWeakReference) { |
| 95 |
cantFail(JD.define(absoluteSymbols({{Foo, FooSym}}))); |
| 96 |
|
| 97 |
ExecutorAddr FooAddress, BarAddress; |
| 98 |
auto Err = |
| 99 |
lookupAndRecordAddrs(ES, LookupKind::Static, makeJITDylibSearchOrder(&JD), |
| 100 |
{{Foo, &FooAddress}, {Bar, &BarAddress}}, |
| 101 |
SymbolLookupFlags::WeaklyReferencedSymbol); |
| 102 |
|
| 103 |
EXPECT_THAT_ERROR(std::move(Err), Succeeded()); |
| 104 |
EXPECT_EQ(FooAddress.getValue(), FooAddr); |
| 105 |
EXPECT_EQ(BarAddress.getValue(), 0U); |
| 106 |
} |
| 107 |
|
| 108 |
} // namespace |