Skip to content

Commit cd8a80d

Browse files
committed
[Orc] Add a unit test for asynchronous definition generation.
1 parent e5553b9 commit cd8a80d

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

llvm/include/llvm/ExecutionEngine/Orc/Core.h

+3
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,9 @@ class LookupState {
850850
friend class ExecutionSession;
851851

852852
public:
853+
LookupState();
854+
LookupState(LookupState &&);
855+
LookupState &operator=(LookupState &&);
853856
~LookupState();
854857

855858
/// Continue the lookup. This can be called by DefinitionGenerators

llvm/lib/ExecutionEngine/Orc/Core.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,10 @@ LookupState::LookupState(std::unique_ptr<InProgressLookupState> IPLS)
577577

578578
void LookupState::reset(InProgressLookupState *IPLS) { this->IPLS.reset(IPLS); }
579579

580-
LookupState::~LookupState() {}
580+
LookupState::LookupState() = default;
581+
LookupState::LookupState(LookupState &&) = default;
582+
LookupState &LookupState::operator=(LookupState &&) = default;
583+
LookupState::~LookupState() = default;
581584

582585
void LookupState::continueLookup(Error Err) {
583586
assert(IPLS && "Cannot call continueLookup on empty LookupState");

llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp

+48-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ TEST_F(CoreAPIsStandardTest, MaterializationSideEffctsOnlyBasic) {
110110

111111
ES.lookup(
112112
LookupKind::Static, makeJITDylibSearchOrder(&JD),
113-
SymbolLookupSet({Foo}, SymbolLookupFlags::WeaklyReferencedSymbol),
113+
SymbolLookupSet(Foo, SymbolLookupFlags::WeaklyReferencedSymbol),
114114
SymbolState::Ready,
115115
[&](Expected<SymbolMap> LookupResult) {
116116
if (LookupResult)
@@ -1088,6 +1088,53 @@ TEST_F(CoreAPIsStandardTest, GeneratorTest) {
10881088
<< "Expected fallback def for Bar to be equal to BarSym";
10891089
}
10901090

1091+
TEST_F(CoreAPIsStandardTest, AsynchronousGeneratorTest) {
1092+
class TestGenerator : public DefinitionGenerator {
1093+
public:
1094+
TestGenerator(LookupState &TLS) : TLS(TLS) {}
1095+
Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD,
1096+
JITDylibLookupFlags JDLookupFlags,
1097+
const SymbolLookupSet &Name) override {
1098+
TLS = std::move(LS);
1099+
return Error::success();
1100+
}
1101+
1102+
private:
1103+
LookupState &TLS;
1104+
};
1105+
1106+
LookupState LS;
1107+
JD.addGenerator(std::make_unique<TestGenerator>(LS));
1108+
1109+
bool LookupCompleted = false;
1110+
1111+
ES.lookup(
1112+
LookupKind::Static, makeJITDylibSearchOrder(&JD), SymbolLookupSet(Foo),
1113+
SymbolState::Ready,
1114+
[&](Expected<SymbolMap> Result) {
1115+
LookupCompleted = true;
1116+
if (!Result) {
1117+
ADD_FAILURE() << "Lookup failed unexpected";
1118+
logAllUnhandledErrors(Result.takeError(), errs(), "");
1119+
return;
1120+
}
1121+
1122+
EXPECT_EQ(Result->size(), 1U) << "Unexpected number of results";
1123+
EXPECT_EQ(Result->count(Foo), 1U) << "Expected result for Foo";
1124+
EXPECT_EQ((*Result)[Foo].getAddress(), FooSym.getAddress())
1125+
<< "Bad result for Foo";
1126+
},
1127+
NoDependenciesToRegister);
1128+
1129+
EXPECT_FALSE(LookupCompleted);
1130+
1131+
cantFail(JD.define(absoluteSymbols({{Foo, FooSym}})));
1132+
1133+
LS.continueLookup(Error::success());
1134+
1135+
EXPECT_TRUE(LookupCompleted);
1136+
}
1137+
10911138
TEST_F(CoreAPIsStandardTest, FailResolution) {
10921139
auto MU = std::make_unique<SimpleMaterializationUnit>(
10931140
SymbolFlagsMap({{Foo, JITSymbolFlags::Exported | JITSymbolFlags::Weak},

0 commit comments

Comments
 (0)