[memprof] Move YAML support to MemProfYAML.h (NFC) (#119515)
[llvm-project.git] / llvm / unittests / ExecutionEngine / Orc / LookupAndRecordAddrsTest.cpp
blobf62151de77a4bc670ecaa5954b7bcb8a03fc56a2
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 //===----------------------------------------------------------------------===//
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"
15 #include <future>
17 using namespace llvm;
18 using namespace llvm::orc;
20 class LookupAndRecordAddrsTest : public CoreAPIsBasedStandardTest {};
22 namespace {
24 TEST_F(LookupAndRecordAddrsTest, AsyncRequiredSuccess) {
25 cantFail(JD.define(absoluteSymbols({{Foo, FooSym}, {Bar, BarSym}})));
27 ExecutorAddr ReturnedFooAddr, ReturnedBarAddr;
28 std::promise<MSVCPError> ErrP;
30 lookupAndRecordAddrs([&](Error Err) { ErrP.set_value(std::move(Err)); }, ES,
31 LookupKind::Static, makeJITDylibSearchOrder(&JD),
32 {{Foo, &ReturnedFooAddr}, {Bar, &ReturnedBarAddr}});
34 Error Err = ErrP.get_future().get();
36 EXPECT_THAT_ERROR(std::move(Err), Succeeded());
37 EXPECT_EQ(ReturnedFooAddr, FooAddr);
38 EXPECT_EQ(ReturnedBarAddr, BarAddr);
41 TEST_F(LookupAndRecordAddrsTest, AsyncRequiredFailure) {
42 ExecutorAddr RecordedFooAddr, RecordedBarAddr;
43 std::promise<MSVCPError> ErrP;
45 lookupAndRecordAddrs([&](Error Err) { ErrP.set_value(std::move(Err)); }, ES,
46 LookupKind::Static, makeJITDylibSearchOrder(&JD),
47 {{Foo, &RecordedFooAddr}, {Bar, &RecordedBarAddr}});
49 Error Err = ErrP.get_future().get();
51 EXPECT_THAT_ERROR(std::move(Err), Failed());
54 TEST_F(LookupAndRecordAddrsTest, AsyncWeakReference) {
55 cantFail(JD.define(absoluteSymbols({{Foo, FooSym}})));
57 ExecutorAddr RecordedFooAddr, RecordedBarAddr;
58 std::promise<MSVCPError> ErrP;
60 lookupAndRecordAddrs([&](Error Err) { ErrP.set_value(std::move(Err)); }, ES,
61 LookupKind::Static, makeJITDylibSearchOrder(&JD),
62 {{Foo, &RecordedFooAddr}, {Bar, &RecordedBarAddr}},
63 SymbolLookupFlags::WeaklyReferencedSymbol);
65 Error Err = ErrP.get_future().get();
67 EXPECT_THAT_ERROR(std::move(Err), Succeeded());
68 EXPECT_EQ(RecordedFooAddr, FooAddr);
69 EXPECT_EQ(RecordedBarAddr, ExecutorAddr());
72 TEST_F(LookupAndRecordAddrsTest, BlockingRequiredSuccess) {
73 cantFail(JD.define(absoluteSymbols({{Foo, FooSym}, {Bar, BarSym}})));
75 ExecutorAddr RecordedFooAddr, RecordedBarAddr;
76 auto Err =
77 lookupAndRecordAddrs(ES, LookupKind::Static, makeJITDylibSearchOrder(&JD),
78 {{Foo, &RecordedFooAddr}, {Bar, &RecordedBarAddr}});
80 EXPECT_THAT_ERROR(std::move(Err), Succeeded());
81 EXPECT_EQ(RecordedFooAddr, FooAddr);
82 EXPECT_EQ(RecordedBarAddr, BarAddr);
85 TEST_F(LookupAndRecordAddrsTest, BlockingRequiredFailure) {
86 ExecutorAddr RecordedFooAddr, RecordedBarAddr;
87 auto Err =
88 lookupAndRecordAddrs(ES, LookupKind::Static, makeJITDylibSearchOrder(&JD),
89 {{Foo, &RecordedFooAddr}, {Bar, &RecordedBarAddr}});
91 EXPECT_THAT_ERROR(std::move(Err), Failed());
94 TEST_F(LookupAndRecordAddrsTest, BlockingWeakReference) {
95 cantFail(JD.define(absoluteSymbols({{Foo, FooSym}})));
97 ExecutorAddr RecordedFooAddr, RecordedBarAddr;
98 auto Err =
99 lookupAndRecordAddrs(ES, LookupKind::Static, makeJITDylibSearchOrder(&JD),
100 {{Foo, &RecordedFooAddr}, {Bar, &RecordedBarAddr}},
101 SymbolLookupFlags::WeaklyReferencedSymbol);
103 EXPECT_THAT_ERROR(std::move(Err), Succeeded());
104 EXPECT_EQ(RecordedFooAddr, FooAddr);
105 EXPECT_EQ(RecordedBarAddr, ExecutorAddr());
108 } // namespace