134
|
1 //===----------- CoreAPIsTest.cpp - Unit tests for Core ORC APIs ----------===//
|
|
2 //
|
147
|
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
|
134
|
6 //
|
|
7 //===----------------------------------------------------------------------===//
|
|
8
|
|
9 #include "OrcTestCommon.h"
|
|
10 #include "llvm/ExecutionEngine/Orc/Legacy.h"
|
|
11 #include "gtest/gtest.h"
|
|
12
|
|
13 using namespace llvm;
|
|
14 using namespace llvm::orc;
|
|
15
|
147
|
16 class LegacyAPIsStandardTest : public CoreAPIsBasedStandardTest {};
|
|
17
|
134
|
18 namespace {
|
|
19
|
147
|
20 TEST_F(LegacyAPIsStandardTest, TestLambdaSymbolResolver) {
|
|
21 BarSym.setFlags(BarSym.getFlags() | JITSymbolFlags::Weak);
|
134
|
22
|
147
|
23 cantFail(JD.define(absoluteSymbols({{Foo, FooSym}, {Bar, BarSym}})));
|
134
|
24
|
147
|
25 auto Resolver = createSymbolResolver(
|
|
26 [&](const SymbolNameSet &Symbols) {
|
|
27 auto FlagsMap = cantFail(JD.lookupFlags(Symbols));
|
|
28 SymbolNameSet Result;
|
|
29 for (auto &KV : FlagsMap)
|
|
30 if (!KV.second.isStrong())
|
|
31 Result.insert(KV.first);
|
|
32 return Result;
|
|
33 },
|
|
34 [&](std::shared_ptr<AsynchronousSymbolQuery> Q, SymbolNameSet Symbols) {
|
|
35 return cantFail(JD.legacyLookup(std::move(Q), Symbols));
|
|
36 });
|
134
|
37
|
147
|
38 auto RS = Resolver->getResponsibilitySet(SymbolNameSet({Bar, Baz}));
|
|
39
|
|
40 EXPECT_EQ(RS.size(), 1U)
|
|
41 << "getResponsibilitySet returned the wrong number of results";
|
|
42 EXPECT_EQ(RS.count(Bar), 1U)
|
|
43 << "getResponsibilitySet result incorrect. Should be {'bar'}";
|
|
44
|
|
45 bool OnCompletionRun = false;
|
134
|
46
|
147
|
47 auto OnCompletion = [&](Expected<SymbolMap> Result) {
|
|
48 OnCompletionRun = true;
|
|
49 EXPECT_TRUE(!!Result) << "Unexpected error";
|
|
50 EXPECT_EQ(Result->size(), 2U) << "Unexpected number of resolved symbols";
|
|
51 EXPECT_EQ(Result->count(Foo), 1U) << "Missing lookup result for foo";
|
|
52 EXPECT_EQ(Result->count(Bar), 1U) << "Missing lookup result for bar";
|
|
53 EXPECT_EQ((*Result)[Foo].getAddress(), FooSym.getAddress())
|
|
54 << "Incorrect address for foo";
|
|
55 EXPECT_EQ((*Result)[Bar].getAddress(), BarSym.getAddress())
|
|
56 << "Incorrect address for bar";
|
134
|
57 };
|
|
58
|
147
|
59 auto Q = std::make_shared<AsynchronousSymbolQuery>(
|
|
60 SymbolNameSet({Foo, Bar}), SymbolState::Resolved, OnCompletion);
|
|
61 auto Unresolved =
|
|
62 Resolver->lookup(std::move(Q), SymbolNameSet({Foo, Bar, Baz}));
|
134
|
63
|
147
|
64 EXPECT_EQ(Unresolved.size(), 1U) << "Expected one unresolved symbol";
|
|
65 EXPECT_EQ(Unresolved.count(Baz), 1U) << "Expected baz to not be resolved";
|
|
66 EXPECT_TRUE(OnCompletionRun) << "OnCompletion was never run";
|
134
|
67 }
|
|
68
|
147
|
69 TEST_F(LegacyAPIsStandardTest, LegacyLookupHelpersFn) {
|
134
|
70 bool BarMaterialized = false;
|
147
|
71 BarSym.setFlags(BarSym.getFlags() | JITSymbolFlags::Weak);
|
134
|
72
|
|
73 auto LegacyLookup = [&](const std::string &Name) -> JITSymbol {
|
|
74 if (Name == "foo")
|
147
|
75 return FooSym;
|
134
|
76
|
|
77 if (Name == "bar") {
|
|
78 auto BarMaterializer = [&]() -> Expected<JITTargetAddress> {
|
|
79 BarMaterialized = true;
|
|
80 return BarAddr;
|
|
81 };
|
|
82
|
147
|
83 return {BarMaterializer, BarSym.getFlags()};
|
134
|
84 }
|
|
85
|
|
86 return nullptr;
|
|
87 };
|
|
88
|
147
|
89 auto RS =
|
|
90 getResponsibilitySetWithLegacyFn(SymbolNameSet({Bar, Baz}), LegacyLookup);
|
134
|
91
|
147
|
92 EXPECT_TRUE(!!RS) << "Expected getResponsibilitySetWithLegacyFn to succeed";
|
|
93 EXPECT_EQ(RS->size(), 1U) << "Wrong number of symbols returned";
|
|
94 EXPECT_EQ(RS->count(Bar), 1U) << "Incorrect responsibility set returned";
|
134
|
95 EXPECT_FALSE(BarMaterialized)
|
|
96 << "lookupFlags should not have materialized bar";
|
|
97
|
147
|
98 bool OnCompletionRun = false;
|
|
99 auto OnCompletion = [&](Expected<SymbolMap> Result) {
|
|
100 OnCompletionRun = true;
|
134
|
101 EXPECT_TRUE(!!Result) << "lookuWithLegacy failed to resolve";
|
147
|
102
|
134
|
103 EXPECT_EQ(Result->size(), 2U) << "Wrong number of symbols resolved";
|
|
104 EXPECT_EQ(Result->count(Foo), 1U) << "Result for foo missing";
|
|
105 EXPECT_EQ(Result->count(Bar), 1U) << "Result for bar missing";
|
|
106 EXPECT_EQ((*Result)[Foo].getAddress(), FooAddr) << "Wrong address for foo";
|
147
|
107 EXPECT_EQ((*Result)[Foo].getFlags(), FooSym.getFlags())
|
|
108 << "Wrong flags for foo";
|
134
|
109 EXPECT_EQ((*Result)[Bar].getAddress(), BarAddr) << "Wrong address for bar";
|
147
|
110 EXPECT_EQ((*Result)[Bar].getFlags(), BarSym.getFlags())
|
|
111 << "Wrong flags for bar";
|
134
|
112 };
|
|
113
|
147
|
114 AsynchronousSymbolQuery Q({Foo, Bar}, SymbolState::Resolved, OnCompletion);
|
|
115 auto Unresolved =
|
|
116 lookupWithLegacyFn(ES, Q, SymbolNameSet({Foo, Bar, Baz}), LegacyLookup);
|
134
|
117
|
147
|
118 EXPECT_TRUE(OnCompletionRun) << "OnCompletion was not run";
|
134
|
119 EXPECT_EQ(Unresolved.size(), 1U) << "Expected one unresolved symbol";
|
|
120 EXPECT_EQ(Unresolved.count(Baz), 1U) << "Expected baz to be unresolved";
|
|
121 }
|
|
122
|
|
123 } // namespace
|