1 change: 1 addition & 0 deletions llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ add_llvm_unittest(OrcJITTests
IndirectionUtilsTest.cpp
JITTargetMachineBuilderTest.cpp
LazyCallThroughAndReexportsTest.cpp
LookupAndRecordAddrsTest.cpp
ObjectLinkingLayerTest.cpp
OrcCAPITest.cpp
OrcTestCommon.cpp
Expand Down
108 changes: 108 additions & 0 deletions llvm/unittests/ExecutionEngine/Orc/LookupAndRecordAddrsTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//===- LookupAndRecordAddrsTest.cpp - Unit tests for LookupAndRecordAddrs -===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "OrcTestCommon.h"

#include "llvm/ExecutionEngine/Orc/LookupAndRecordAddrs.h"
#include "llvm/Support/MSVCErrorWorkarounds.h"
#include "llvm/Testing/Support/Error.h"

#include <future>

using namespace llvm;
using namespace llvm::orc;

class LookupAndRecordAddrsTest : public CoreAPIsBasedStandardTest {};

namespace {

TEST_F(LookupAndRecordAddrsTest, AsyncRequiredSuccess) {
cantFail(JD.define(absoluteSymbols({{Foo, FooSym}, {Bar, BarSym}})));

ExecutorAddress FooAddress, BarAddress;
std::promise<MSVCPError> ErrP;

lookupAndRecordAddrs([&](Error Err) { ErrP.set_value(std::move(Err)); }, ES,
LookupKind::Static, makeJITDylibSearchOrder(&JD),
{{Foo, &FooAddress}, {Bar, &BarAddress}});

Error Err = ErrP.get_future().get();

EXPECT_THAT_ERROR(std::move(Err), Succeeded());
EXPECT_EQ(FooAddress.getValue(), FooAddr);
EXPECT_EQ(BarAddress.getValue(), BarAddr);
}

TEST_F(LookupAndRecordAddrsTest, AsyncRequiredFailure) {
ExecutorAddress FooAddress, BarAddress;
std::promise<MSVCPError> ErrP;

lookupAndRecordAddrs([&](Error Err) { ErrP.set_value(std::move(Err)); }, ES,
LookupKind::Static, makeJITDylibSearchOrder(&JD),
{{Foo, &FooAddress}, {Bar, &BarAddress}});

Error Err = ErrP.get_future().get();

EXPECT_THAT_ERROR(std::move(Err), Failed());
}

TEST_F(LookupAndRecordAddrsTest, AsyncWeakReference) {
cantFail(JD.define(absoluteSymbols({{Foo, FooSym}})));

ExecutorAddress FooAddress, BarAddress;
std::promise<MSVCPError> ErrP;

lookupAndRecordAddrs([&](Error Err) { ErrP.set_value(std::move(Err)); }, ES,
LookupKind::Static, makeJITDylibSearchOrder(&JD),
{{Foo, &FooAddress}, {Bar, &BarAddress}},
SymbolLookupFlags::WeaklyReferencedSymbol);

Error Err = ErrP.get_future().get();

EXPECT_THAT_ERROR(std::move(Err), Succeeded());
EXPECT_EQ(FooAddress.getValue(), FooAddr);
EXPECT_EQ(BarAddress.getValue(), 0U);
}

TEST_F(LookupAndRecordAddrsTest, BlockingRequiredSuccess) {
cantFail(JD.define(absoluteSymbols({{Foo, FooSym}, {Bar, BarSym}})));

ExecutorAddress FooAddress, BarAddress;
auto Err =
lookupAndRecordAddrs(ES, LookupKind::Static, makeJITDylibSearchOrder(&JD),
{{Foo, &FooAddress}, {Bar, &BarAddress}});

EXPECT_THAT_ERROR(std::move(Err), Succeeded());
EXPECT_EQ(FooAddress.getValue(), FooAddr);
EXPECT_EQ(BarAddress.getValue(), BarAddr);
}

TEST_F(LookupAndRecordAddrsTest, BlockingRequiredFailure) {
ExecutorAddress FooAddress, BarAddress;
auto Err =
lookupAndRecordAddrs(ES, LookupKind::Static, makeJITDylibSearchOrder(&JD),
{{Foo, &FooAddress}, {Bar, &BarAddress}});

EXPECT_THAT_ERROR(std::move(Err), Failed());
}

TEST_F(LookupAndRecordAddrsTest, BlockingWeakReference) {
cantFail(JD.define(absoluteSymbols({{Foo, FooSym}})));

ExecutorAddress FooAddress, BarAddress;
auto Err =
lookupAndRecordAddrs(ES, LookupKind::Static, makeJITDylibSearchOrder(&JD),
{{Foo, &FooAddress}, {Bar, &BarAddress}},
SymbolLookupFlags::WeaklyReferencedSymbol);

EXPECT_THAT_ERROR(std::move(Err), Succeeded());
EXPECT_EQ(FooAddress.getValue(), FooAddr);
EXPECT_EQ(BarAddress.getValue(), 0U);
}

} // namespace