Skip to content

Commit bcdce5c

Browse files
committed
[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
1 parent dfc3a4f commit bcdce5c

File tree

3 files changed

+52
-19
lines changed

3 files changed

+52
-19
lines changed

llvm/unittests/ExecutionEngine/JITLink/JITLinkTestCommon.cpp

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
using namespace llvm::jitlink;
1616
namespace llvm {
1717

18-
JITLinkTestCommon::TestResources::TestResources(StringRef AsmSrc,
19-
StringRef TripleStr, bool PIC,
20-
bool LargeCodeModel,
21-
MCTargetOptions Options)
22-
: ObjStream(ObjBuffer), Options(std::move(Options)) {
23-
Triple TT(Triple::normalize(TripleStr));
24-
initializeTripleSpecifics(TT);
25-
initializeTestSpecifics(AsmSrc, TT, PIC, LargeCodeModel);
18+
Expected<std::unique_ptr<JITLinkTestCommon::TestResources>>
19+
JITLinkTestCommon::TestResources::Create(StringRef AsmSrc, StringRef TripleStr,
20+
bool PIC, bool LargeCodeModel,
21+
MCTargetOptions Options) {
22+
Error Err = Error::success();
23+
auto R = std::unique_ptr<TestResources>(new TestResources(
24+
AsmSrc, TripleStr, PIC, LargeCodeModel, std::move(Options), Err));
25+
if (Err)
26+
return std::move(Err);
27+
return std::move(R);
2628
}
2729

2830
MemoryBufferRef
@@ -31,12 +33,27 @@ JITLinkTestCommon::TestResources::getTestObjectBufferRef() const {
3133
"Test object");
3234
}
3335

34-
void JITLinkTestCommon::TestResources::initializeTripleSpecifics(Triple &TT) {
35-
std::string Error;
36-
TheTarget = TargetRegistry::lookupTarget("", TT, Error);
36+
JITLinkTestCommon::TestResources::TestResources(StringRef AsmSrc,
37+
StringRef TripleStr, bool PIC,
38+
bool LargeCodeModel,
39+
MCTargetOptions Options,
40+
Error &Err)
41+
: ObjStream(ObjBuffer), Options(std::move(Options)) {
42+
ErrorAsOutParameter _(&Err);
43+
Triple TT(Triple::normalize(TripleStr));
44+
if (auto Err2 = initializeTripleSpecifics(TT)) {
45+
Err = std::move(Err2);
46+
return;
47+
}
48+
initializeTestSpecifics(AsmSrc, TT, PIC, LargeCodeModel);
49+
}
50+
51+
Error JITLinkTestCommon::TestResources::initializeTripleSpecifics(Triple &TT) {
52+
std::string ErrorMsg;
53+
TheTarget = TargetRegistry::lookupTarget("", TT, ErrorMsg);
3754

3855
if (!TheTarget)
39-
report_fatal_error(Error);
56+
return make_error<StringError>(ErrorMsg, inconvertibleErrorCode());
4057

4158
MRI.reset(TheTarget->createMCRegInfo(TT.getTriple()));
4259
if (!MRI)
@@ -59,6 +76,8 @@ void JITLinkTestCommon::TestResources::initializeTripleSpecifics(Triple &TT) {
5976

6077
if (!Dis)
6178
report_fatal_error("Could not build MCDisassembler");
79+
80+
return Error::success();
6281
}
6382

6483
void JITLinkTestCommon::TestResources::initializeTestSpecifics(

llvm/unittests/ExecutionEngine/JITLink/JITLinkTestCommon.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,19 @@ class JITLinkTestCommon {
4040

4141
class TestResources {
4242
public:
43-
TestResources(StringRef AsmSrc, StringRef TripleStr, bool PIC,
44-
bool LargeCodeModel, MCTargetOptions Options);
43+
static Expected<std::unique_ptr<TestResources>>
44+
Create(StringRef AsmSrc, StringRef TripleStr, bool PIC, bool LargeCodeModel,
45+
MCTargetOptions Options);
4546

4647
MemoryBufferRef getTestObjectBufferRef() const;
4748

4849
const MCDisassembler &getDisassembler() const { return *Dis; }
4950

5051
private:
51-
void initializeTripleSpecifics(Triple &TT);
52+
TestResources(StringRef AsmSrc, StringRef TripleStr, bool PIC,
53+
bool LargeCodeModel, MCTargetOptions Options, Error &Err);
54+
55+
Error initializeTripleSpecifics(Triple &TT);
5256
void initializeTestSpecifics(StringRef AsmSource, const Triple &TT,
5357
bool PIC, bool LargeCodeModel);
5458

@@ -123,11 +127,16 @@ class JITLinkTestCommon {
123127

124128
JITLinkTestCommon();
125129

126-
std::unique_ptr<TestResources>
130+
/// Get TestResources for this target/test.
131+
///
132+
/// If this method fails it is likely because the target is not supported in
133+
/// this build. The test should bail out without failing (possibly logging a
134+
/// diagnostic).
135+
Expected<std::unique_ptr<TestResources>>
127136
getTestResources(StringRef AsmSrc, StringRef Triple, bool PIC,
128137
bool LargeCodeModel, MCTargetOptions Options) const {
129-
return llvm::make_unique<TestResources>(AsmSrc, Triple, PIC, LargeCodeModel,
130-
std::move(Options));
138+
return TestResources::Create(AsmSrc, Triple, PIC, LargeCodeModel,
139+
std::move(Options));
131140
}
132141

133142
template <typename T>

llvm/unittests/ExecutionEngine/JITLink/JITLinkTest_MachO_x86_64_Tests.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ class JITLinkTest_MachO_x86_64 : public JITLinkTestCommon,
3333
BasicVerifyGraphFunction RunGraphTest) {
3434
auto TR = getTestResources(AsmSrc, Triple, PIC, LargeCodeModel,
3535
std::move(Options));
36+
if (!TR) {
37+
dbgs() << "Skipping JITLInk unit test: " << toString(TR.takeError())
38+
<< "\n";
39+
return;
40+
}
3641

3742
auto JTCtx = llvm::make_unique<TestJITLinkContext>(
38-
*TR, [&](AtomGraph &G) { RunGraphTest(G, TR->getDisassembler()); });
43+
**TR, [&](AtomGraph &G) { RunGraphTest(G, (*TR)->getDisassembler()); });
3944

4045
JTCtx->externals() = std::move(Externals);
4146

0 commit comments

Comments
 (0)