forked from OSchip/llvm-project
[JITLink] Add check to JITLink unit test to bail out for unsupported targets.
This should prevent spurious JITLink unit test failures for builds that do not support the target(s) required by the tests. llvm-svn: 358825
This commit is contained in:
parent
dfc3a4f6ff
commit
bcdce5cd41
|
@ -15,14 +15,16 @@
|
||||||
using namespace llvm::jitlink;
|
using namespace llvm::jitlink;
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
JITLinkTestCommon::TestResources::TestResources(StringRef AsmSrc,
|
Expected<std::unique_ptr<JITLinkTestCommon::TestResources>>
|
||||||
StringRef TripleStr, bool PIC,
|
JITLinkTestCommon::TestResources::Create(StringRef AsmSrc, StringRef TripleStr,
|
||||||
bool LargeCodeModel,
|
bool PIC, bool LargeCodeModel,
|
||||||
MCTargetOptions Options)
|
MCTargetOptions Options) {
|
||||||
: ObjStream(ObjBuffer), Options(std::move(Options)) {
|
Error Err = Error::success();
|
||||||
Triple TT(Triple::normalize(TripleStr));
|
auto R = std::unique_ptr<TestResources>(new TestResources(
|
||||||
initializeTripleSpecifics(TT);
|
AsmSrc, TripleStr, PIC, LargeCodeModel, std::move(Options), Err));
|
||||||
initializeTestSpecifics(AsmSrc, TT, PIC, LargeCodeModel);
|
if (Err)
|
||||||
|
return std::move(Err);
|
||||||
|
return std::move(R);
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryBufferRef
|
MemoryBufferRef
|
||||||
|
@ -31,12 +33,27 @@ JITLinkTestCommon::TestResources::getTestObjectBufferRef() const {
|
||||||
"Test object");
|
"Test object");
|
||||||
}
|
}
|
||||||
|
|
||||||
void JITLinkTestCommon::TestResources::initializeTripleSpecifics(Triple &TT) {
|
JITLinkTestCommon::TestResources::TestResources(StringRef AsmSrc,
|
||||||
std::string Error;
|
StringRef TripleStr, bool PIC,
|
||||||
TheTarget = TargetRegistry::lookupTarget("", TT, Error);
|
bool LargeCodeModel,
|
||||||
|
MCTargetOptions Options,
|
||||||
|
Error &Err)
|
||||||
|
: ObjStream(ObjBuffer), Options(std::move(Options)) {
|
||||||
|
ErrorAsOutParameter _(&Err);
|
||||||
|
Triple TT(Triple::normalize(TripleStr));
|
||||||
|
if (auto Err2 = initializeTripleSpecifics(TT)) {
|
||||||
|
Err = std::move(Err2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
initializeTestSpecifics(AsmSrc, TT, PIC, LargeCodeModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
Error JITLinkTestCommon::TestResources::initializeTripleSpecifics(Triple &TT) {
|
||||||
|
std::string ErrorMsg;
|
||||||
|
TheTarget = TargetRegistry::lookupTarget("", TT, ErrorMsg);
|
||||||
|
|
||||||
if (!TheTarget)
|
if (!TheTarget)
|
||||||
report_fatal_error(Error);
|
return make_error<StringError>(ErrorMsg, inconvertibleErrorCode());
|
||||||
|
|
||||||
MRI.reset(TheTarget->createMCRegInfo(TT.getTriple()));
|
MRI.reset(TheTarget->createMCRegInfo(TT.getTriple()));
|
||||||
if (!MRI)
|
if (!MRI)
|
||||||
|
@ -59,6 +76,8 @@ void JITLinkTestCommon::TestResources::initializeTripleSpecifics(Triple &TT) {
|
||||||
|
|
||||||
if (!Dis)
|
if (!Dis)
|
||||||
report_fatal_error("Could not build MCDisassembler");
|
report_fatal_error("Could not build MCDisassembler");
|
||||||
|
|
||||||
|
return Error::success();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JITLinkTestCommon::TestResources::initializeTestSpecifics(
|
void JITLinkTestCommon::TestResources::initializeTestSpecifics(
|
||||||
|
|
|
@ -40,15 +40,19 @@ public:
|
||||||
|
|
||||||
class TestResources {
|
class TestResources {
|
||||||
public:
|
public:
|
||||||
TestResources(StringRef AsmSrc, StringRef TripleStr, bool PIC,
|
static Expected<std::unique_ptr<TestResources>>
|
||||||
bool LargeCodeModel, MCTargetOptions Options);
|
Create(StringRef AsmSrc, StringRef TripleStr, bool PIC, bool LargeCodeModel,
|
||||||
|
MCTargetOptions Options);
|
||||||
|
|
||||||
MemoryBufferRef getTestObjectBufferRef() const;
|
MemoryBufferRef getTestObjectBufferRef() const;
|
||||||
|
|
||||||
const MCDisassembler &getDisassembler() const { return *Dis; }
|
const MCDisassembler &getDisassembler() const { return *Dis; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initializeTripleSpecifics(Triple &TT);
|
TestResources(StringRef AsmSrc, StringRef TripleStr, bool PIC,
|
||||||
|
bool LargeCodeModel, MCTargetOptions Options, Error &Err);
|
||||||
|
|
||||||
|
Error initializeTripleSpecifics(Triple &TT);
|
||||||
void initializeTestSpecifics(StringRef AsmSource, const Triple &TT,
|
void initializeTestSpecifics(StringRef AsmSource, const Triple &TT,
|
||||||
bool PIC, bool LargeCodeModel);
|
bool PIC, bool LargeCodeModel);
|
||||||
|
|
||||||
|
@ -123,11 +127,16 @@ public:
|
||||||
|
|
||||||
JITLinkTestCommon();
|
JITLinkTestCommon();
|
||||||
|
|
||||||
std::unique_ptr<TestResources>
|
/// Get TestResources for this target/test.
|
||||||
|
///
|
||||||
|
/// If this method fails it is likely because the target is not supported in
|
||||||
|
/// this build. The test should bail out without failing (possibly logging a
|
||||||
|
/// diagnostic).
|
||||||
|
Expected<std::unique_ptr<TestResources>>
|
||||||
getTestResources(StringRef AsmSrc, StringRef Triple, bool PIC,
|
getTestResources(StringRef AsmSrc, StringRef Triple, bool PIC,
|
||||||
bool LargeCodeModel, MCTargetOptions Options) const {
|
bool LargeCodeModel, MCTargetOptions Options) const {
|
||||||
return llvm::make_unique<TestResources>(AsmSrc, Triple, PIC, LargeCodeModel,
|
return TestResources::Create(AsmSrc, Triple, PIC, LargeCodeModel,
|
||||||
std::move(Options));
|
std::move(Options));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
|
@ -33,9 +33,14 @@ public:
|
||||||
BasicVerifyGraphFunction RunGraphTest) {
|
BasicVerifyGraphFunction RunGraphTest) {
|
||||||
auto TR = getTestResources(AsmSrc, Triple, PIC, LargeCodeModel,
|
auto TR = getTestResources(AsmSrc, Triple, PIC, LargeCodeModel,
|
||||||
std::move(Options));
|
std::move(Options));
|
||||||
|
if (!TR) {
|
||||||
|
dbgs() << "Skipping JITLInk unit test: " << toString(TR.takeError())
|
||||||
|
<< "\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto JTCtx = llvm::make_unique<TestJITLinkContext>(
|
auto JTCtx = llvm::make_unique<TestJITLinkContext>(
|
||||||
*TR, [&](AtomGraph &G) { RunGraphTest(G, TR->getDisassembler()); });
|
**TR, [&](AtomGraph &G) { RunGraphTest(G, (*TR)->getDisassembler()); });
|
||||||
|
|
||||||
JTCtx->externals() = std::move(Externals);
|
JTCtx->externals() = std::move(Externals);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue