[Orc] Add a unit test for asynchronous definition generation.
This commit is contained in:
parent
e5553b9a6a
commit
cd8a80de96
@ -850,6 +850,9 @@ class LookupState {
|
||||
friend class ExecutionSession;
|
||||
|
||||
public:
|
||||
LookupState();
|
||||
LookupState(LookupState &&);
|
||||
LookupState &operator=(LookupState &&);
|
||||
~LookupState();
|
||||
|
||||
/// Continue the lookup. This can be called by DefinitionGenerators
|
||||
|
||||
@ -577,7 +577,10 @@ LookupState::LookupState(std::unique_ptr<InProgressLookupState> IPLS)
|
||||
|
||||
void LookupState::reset(InProgressLookupState *IPLS) { this->IPLS.reset(IPLS); }
|
||||
|
||||
LookupState::~LookupState() {}
|
||||
LookupState::LookupState() = default;
|
||||
LookupState::LookupState(LookupState &&) = default;
|
||||
LookupState &LookupState::operator=(LookupState &&) = default;
|
||||
LookupState::~LookupState() = default;
|
||||
|
||||
void LookupState::continueLookup(Error Err) {
|
||||
assert(IPLS && "Cannot call continueLookup on empty LookupState");
|
||||
|
||||
@ -110,7 +110,7 @@ TEST_F(CoreAPIsStandardTest, MaterializationSideEffctsOnlyBasic) {
|
||||
|
||||
ES.lookup(
|
||||
LookupKind::Static, makeJITDylibSearchOrder(&JD),
|
||||
SymbolLookupSet({Foo}, SymbolLookupFlags::WeaklyReferencedSymbol),
|
||||
SymbolLookupSet(Foo, SymbolLookupFlags::WeaklyReferencedSymbol),
|
||||
SymbolState::Ready,
|
||||
[&](Expected<SymbolMap> LookupResult) {
|
||||
if (LookupResult)
|
||||
@ -1088,6 +1088,53 @@ TEST_F(CoreAPIsStandardTest, GeneratorTest) {
|
||||
<< "Expected fallback def for Bar to be equal to BarSym";
|
||||
}
|
||||
|
||||
TEST_F(CoreAPIsStandardTest, AsynchronousGeneratorTest) {
|
||||
class TestGenerator : public DefinitionGenerator {
|
||||
public:
|
||||
TestGenerator(LookupState &TLS) : TLS(TLS) {}
|
||||
Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD,
|
||||
JITDylibLookupFlags JDLookupFlags,
|
||||
const SymbolLookupSet &Name) override {
|
||||
TLS = std::move(LS);
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
private:
|
||||
LookupState &TLS;
|
||||
};
|
||||
|
||||
LookupState LS;
|
||||
JD.addGenerator(std::make_unique<TestGenerator>(LS));
|
||||
|
||||
bool LookupCompleted = false;
|
||||
|
||||
ES.lookup(
|
||||
LookupKind::Static, makeJITDylibSearchOrder(&JD), SymbolLookupSet(Foo),
|
||||
SymbolState::Ready,
|
||||
[&](Expected<SymbolMap> Result) {
|
||||
LookupCompleted = true;
|
||||
if (!Result) {
|
||||
ADD_FAILURE() << "Lookup failed unexpected";
|
||||
logAllUnhandledErrors(Result.takeError(), errs(), "");
|
||||
return;
|
||||
}
|
||||
|
||||
EXPECT_EQ(Result->size(), 1U) << "Unexpected number of results";
|
||||
EXPECT_EQ(Result->count(Foo), 1U) << "Expected result for Foo";
|
||||
EXPECT_EQ((*Result)[Foo].getAddress(), FooSym.getAddress())
|
||||
<< "Bad result for Foo";
|
||||
},
|
||||
NoDependenciesToRegister);
|
||||
|
||||
EXPECT_FALSE(LookupCompleted);
|
||||
|
||||
cantFail(JD.define(absoluteSymbols({{Foo, FooSym}})));
|
||||
|
||||
LS.continueLookup(Error::success());
|
||||
|
||||
EXPECT_TRUE(LookupCompleted);
|
||||
}
|
||||
|
||||
TEST_F(CoreAPIsStandardTest, FailResolution) {
|
||||
auto MU = std::make_unique<SimpleMaterializationUnit>(
|
||||
SymbolFlagsMap({{Foo, JITSymbolFlags::Exported | JITSymbolFlags::Weak},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user