[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:
Lang Hames 2019-04-20 18:30:17 +00:00
parent dfc3a4f6ff
commit bcdce5cd41
3 changed files with 52 additions and 19 deletions

View File

@ -15,14 +15,16 @@
using namespace llvm::jitlink;
namespace llvm {
JITLinkTestCommon::TestResources::TestResources(StringRef AsmSrc,
StringRef TripleStr, bool PIC,
bool LargeCodeModel,
MCTargetOptions Options)
: ObjStream(ObjBuffer), Options(std::move(Options)) {
Triple TT(Triple::normalize(TripleStr));
initializeTripleSpecifics(TT);
initializeTestSpecifics(AsmSrc, TT, PIC, LargeCodeModel);
Expected<std::unique_ptr<JITLinkTestCommon::TestResources>>
JITLinkTestCommon::TestResources::Create(StringRef AsmSrc, StringRef TripleStr,
bool PIC, bool LargeCodeModel,
MCTargetOptions Options) {
Error Err = Error::success();
auto R = std::unique_ptr<TestResources>(new TestResources(
AsmSrc, TripleStr, PIC, LargeCodeModel, std::move(Options), Err));
if (Err)
return std::move(Err);
return std::move(R);
}
MemoryBufferRef
@ -31,12 +33,27 @@ JITLinkTestCommon::TestResources::getTestObjectBufferRef() const {
"Test object");
}
void JITLinkTestCommon::TestResources::initializeTripleSpecifics(Triple &TT) {
std::string Error;
TheTarget = TargetRegistry::lookupTarget("", TT, Error);
JITLinkTestCommon::TestResources::TestResources(StringRef AsmSrc,
StringRef TripleStr, bool PIC,
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)
report_fatal_error(Error);
return make_error<StringError>(ErrorMsg, inconvertibleErrorCode());
MRI.reset(TheTarget->createMCRegInfo(TT.getTriple()));
if (!MRI)
@ -59,6 +76,8 @@ void JITLinkTestCommon::TestResources::initializeTripleSpecifics(Triple &TT) {
if (!Dis)
report_fatal_error("Could not build MCDisassembler");
return Error::success();
}
void JITLinkTestCommon::TestResources::initializeTestSpecifics(

View File

@ -40,15 +40,19 @@ public:
class TestResources {
public:
TestResources(StringRef AsmSrc, StringRef TripleStr, bool PIC,
bool LargeCodeModel, MCTargetOptions Options);
static Expected<std::unique_ptr<TestResources>>
Create(StringRef AsmSrc, StringRef TripleStr, bool PIC, bool LargeCodeModel,
MCTargetOptions Options);
MemoryBufferRef getTestObjectBufferRef() const;
const MCDisassembler &getDisassembler() const { return *Dis; }
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,
bool PIC, bool LargeCodeModel);
@ -123,11 +127,16 @@ public:
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,
bool LargeCodeModel, MCTargetOptions Options) const {
return llvm::make_unique<TestResources>(AsmSrc, Triple, PIC, LargeCodeModel,
std::move(Options));
return TestResources::Create(AsmSrc, Triple, PIC, LargeCodeModel,
std::move(Options));
}
template <typename T>

View File

@ -33,9 +33,14 @@ public:
BasicVerifyGraphFunction RunGraphTest) {
auto TR = getTestResources(AsmSrc, Triple, PIC, LargeCodeModel,
std::move(Options));
if (!TR) {
dbgs() << "Skipping JITLInk unit test: " << toString(TR.takeError())
<< "\n";
return;
}
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);