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