2018-01-22 11:00:31 +08:00
|
|
|
//===----------- CoreAPIsTest.cpp - Unit tests for Core ORC APIs ----------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "OrcTestCommon.h"
|
|
|
|
#include "llvm/ExecutionEngine/Orc/Legacy.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::orc;
|
|
|
|
|
2018-07-21 02:31:50 +08:00
|
|
|
class LegacyAPIsStandardTest : public CoreAPIsBasedStandardTest {};
|
|
|
|
|
2018-01-22 11:00:31 +08:00
|
|
|
namespace {
|
|
|
|
|
2018-07-21 02:31:50 +08:00
|
|
|
TEST_F(LegacyAPIsStandardTest, TestLambdaSymbolResolver) {
|
2018-09-02 09:28:26 +08:00
|
|
|
BarSym.setFlags(BarSym.getFlags() | JITSymbolFlags::Weak);
|
2018-08-29 05:18:05 +08:00
|
|
|
|
2018-08-18 05:18:18 +08:00
|
|
|
cantFail(JD.define(absoluteSymbols({{Foo, FooSym}, {Bar, BarSym}})));
|
2018-07-21 02:31:50 +08:00
|
|
|
|
|
|
|
auto Resolver = createSymbolResolver(
|
2018-08-29 05:18:05 +08:00
|
|
|
[&](const SymbolNameSet &Symbols) {
|
|
|
|
auto FlagsMap = JD.lookupFlags(Symbols);
|
|
|
|
SymbolNameSet Result;
|
|
|
|
for (auto &KV : FlagsMap)
|
|
|
|
if (!KV.second.isStrong())
|
|
|
|
Result.insert(KV.first);
|
|
|
|
return Result;
|
|
|
|
},
|
2018-07-21 02:31:50 +08:00
|
|
|
[&](std::shared_ptr<AsynchronousSymbolQuery> Q, SymbolNameSet Symbols) {
|
2018-08-18 05:18:18 +08:00
|
|
|
return JD.legacyLookup(std::move(Q), Symbols);
|
2018-07-21 02:31:50 +08:00
|
|
|
});
|
|
|
|
|
2018-08-29 05:18:05 +08:00
|
|
|
auto RS = Resolver->getResponsibilitySet(SymbolNameSet({Bar, Baz}));
|
2018-07-21 02:31:50 +08:00
|
|
|
|
2018-08-29 05:18:05 +08:00
|
|
|
EXPECT_EQ(RS.size(), 1U)
|
|
|
|
<< "getResponsibilitySet returned the wrong number of results";
|
|
|
|
EXPECT_EQ(RS.count(Bar), 1U)
|
|
|
|
<< "getResponsibilitySet result incorrect. Should be {'bar'}";
|
2018-07-21 02:31:50 +08:00
|
|
|
|
|
|
|
bool OnResolvedRun = false;
|
|
|
|
|
2018-07-21 06:22:19 +08:00
|
|
|
auto OnResolved = [&](Expected<SymbolMap> Result) {
|
|
|
|
OnResolvedRun = true;
|
|
|
|
EXPECT_TRUE(!!Result) << "Unexpected error";
|
|
|
|
EXPECT_EQ(Result->size(), 2U) << "Unexpected number of resolved symbols";
|
|
|
|
EXPECT_EQ(Result->count(Foo), 1U) << "Missing lookup result for foo";
|
|
|
|
EXPECT_EQ(Result->count(Bar), 1U) << "Missing lookup result for bar";
|
|
|
|
EXPECT_EQ((*Result)[Foo].getAddress(), FooSym.getAddress())
|
|
|
|
<< "Incorrect address for foo";
|
|
|
|
EXPECT_EQ((*Result)[Bar].getAddress(), BarSym.getAddress())
|
|
|
|
<< "Incorrect address for bar";
|
|
|
|
};
|
2018-07-21 02:31:50 +08:00
|
|
|
auto OnReady = [&](Error Err) {
|
|
|
|
EXPECT_FALSE(!!Err) << "Finalization should never fail in this test";
|
|
|
|
};
|
|
|
|
|
|
|
|
auto Q = std::make_shared<AsynchronousSymbolQuery>(SymbolNameSet({Foo, Bar}),
|
|
|
|
OnResolved, OnReady);
|
2018-08-29 05:18:05 +08:00
|
|
|
auto Unresolved =
|
|
|
|
Resolver->lookup(std::move(Q), SymbolNameSet({Foo, Bar, Baz}));
|
2018-07-21 02:31:50 +08:00
|
|
|
|
|
|
|
EXPECT_EQ(Unresolved.size(), 1U) << "Expected one unresolved symbol";
|
|
|
|
EXPECT_EQ(Unresolved.count(Baz), 1U) << "Expected baz to not be resolved";
|
|
|
|
EXPECT_TRUE(OnResolvedRun) << "OnResolved was never run";
|
|
|
|
}
|
|
|
|
|
2018-08-29 05:18:05 +08:00
|
|
|
TEST_F(LegacyAPIsStandardTest, LegacyLookupHelpersFn) {
|
2018-01-25 07:09:07 +08:00
|
|
|
bool BarMaterialized = false;
|
2018-09-02 09:28:26 +08:00
|
|
|
BarSym.setFlags(BarSym.getFlags() | JITSymbolFlags::Weak);
|
2018-01-25 07:09:07 +08:00
|
|
|
|
|
|
|
auto LegacyLookup = [&](const std::string &Name) -> JITSymbol {
|
|
|
|
if (Name == "foo")
|
2018-08-29 05:18:05 +08:00
|
|
|
return FooSym;
|
2018-01-25 07:09:07 +08:00
|
|
|
|
|
|
|
if (Name == "bar") {
|
|
|
|
auto BarMaterializer = [&]() -> Expected<JITTargetAddress> {
|
|
|
|
BarMaterialized = true;
|
|
|
|
return BarAddr;
|
|
|
|
};
|
|
|
|
|
2018-08-29 05:18:05 +08:00
|
|
|
return {BarMaterializer, BarSym.getFlags()};
|
2018-01-25 07:09:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
};
|
|
|
|
|
2018-08-29 05:18:05 +08:00
|
|
|
auto RS =
|
|
|
|
getResponsibilitySetWithLegacyFn(SymbolNameSet({Bar, Baz}), LegacyLookup);
|
2018-07-21 02:31:52 +08:00
|
|
|
|
2018-08-29 05:18:05 +08:00
|
|
|
EXPECT_TRUE(!!RS) << "Expected getResponsibilitySetWithLegacyFn to succeed";
|
|
|
|
EXPECT_EQ(RS->size(), 1U) << "Wrong number of symbols returned";
|
|
|
|
EXPECT_EQ(RS->count(Bar), 1U) << "Incorrect responsibility set returned";
|
2018-01-25 07:09:07 +08:00
|
|
|
EXPECT_FALSE(BarMaterialized)
|
|
|
|
<< "lookupFlags should not have materialized bar";
|
|
|
|
|
|
|
|
bool OnResolvedRun = false;
|
|
|
|
bool OnReadyRun = false;
|
2018-07-21 06:22:19 +08:00
|
|
|
auto OnResolved = [&](Expected<SymbolMap> Result) {
|
|
|
|
OnResolvedRun = true;
|
|
|
|
EXPECT_TRUE(!!Result) << "lookuWithLegacy failed to resolve";
|
|
|
|
|
|
|
|
EXPECT_EQ(Result->size(), 2U) << "Wrong number of symbols resolved";
|
|
|
|
EXPECT_EQ(Result->count(Foo), 1U) << "Result for foo missing";
|
|
|
|
EXPECT_EQ(Result->count(Bar), 1U) << "Result for bar missing";
|
|
|
|
EXPECT_EQ((*Result)[Foo].getAddress(), FooAddr) << "Wrong address for foo";
|
2018-08-29 05:18:05 +08:00
|
|
|
EXPECT_EQ((*Result)[Foo].getFlags(), FooSym.getFlags())
|
|
|
|
<< "Wrong flags for foo";
|
2018-07-21 06:22:19 +08:00
|
|
|
EXPECT_EQ((*Result)[Bar].getAddress(), BarAddr) << "Wrong address for bar";
|
2018-08-29 05:18:05 +08:00
|
|
|
EXPECT_EQ((*Result)[Bar].getFlags(), BarSym.getFlags())
|
|
|
|
<< "Wrong flags for bar";
|
2018-07-21 06:22:19 +08:00
|
|
|
};
|
2018-01-25 07:09:07 +08:00
|
|
|
auto OnReady = [&](Error Err) {
|
|
|
|
EXPECT_FALSE(!!Err) << "Finalization unexpectedly failed";
|
|
|
|
OnReadyRun = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
AsynchronousSymbolQuery Q({Foo, Bar}, OnResolved, OnReady);
|
2018-08-29 05:18:05 +08:00
|
|
|
auto Unresolved =
|
|
|
|
lookupWithLegacyFn(ES, Q, SymbolNameSet({Foo, Bar, Baz}), LegacyLookup);
|
2018-01-25 07:09:07 +08:00
|
|
|
|
|
|
|
EXPECT_TRUE(OnResolvedRun) << "OnResolved was not run";
|
|
|
|
EXPECT_TRUE(OnReadyRun) << "OnReady was not run";
|
|
|
|
EXPECT_EQ(Unresolved.size(), 1U) << "Expected one unresolved symbol";
|
|
|
|
EXPECT_EQ(Unresolved.count(Baz), 1U) << "Expected baz to be unresolved";
|
|
|
|
}
|
|
|
|
|
2018-01-22 11:00:31 +08:00
|
|
|
} // namespace
|