Skip to content

Commit 7fe1189

Browse files
committedApr 27, 2021
[ORC] Record target triple in C API testcase, print it on failure.
This will simplify identification of unsupported triples when we see builder failures in this test case.
1 parent 0bef557 commit 7fe1189

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed
 

‎llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp

+26-12
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,20 @@ class OrcCAPITestBase : public testing::Test {
4848
return;
4949
}
5050

51-
char *Triple = LLVMOrcJITTargetMachineBuilderGetTargetTriple(JTMB);
52-
if (!isSupported(Triple)) {
51+
// Capture the target triple. We'll use it for both verification that
52+
// this target is *supposed* to be supported, and error messages in
53+
// the case that it fails anyway.
54+
char *TT = LLVMOrcJITTargetMachineBuilderGetTargetTriple(JTMB);
55+
TargetTriple = TT;
56+
LLVMOrcJITTargetMachineBuilderDisposeTargetTriple(JTMB, TT);
57+
58+
if (!isSupported(TargetTriple)) {
5359
// If this triple isn't supported then bail out.
5460
TargetSupported = false;
55-
LLVMOrcJITTargetMachineBuilderDisposeTargetTriple(JTMB, Triple);
5661
LLVMOrcDisposeJITTargetMachineBuilder(JTMB);
5762
return;
5863
}
5964

60-
LLVMOrcJITTargetMachineBuilderDisposeTargetTriple(JTMB, Triple);
6165
LLVMOrcLLJITBuilderRef Builder = LLVMOrcCreateLLJITBuilder();
6266
LLVMOrcLLJITBuilderSetJITTargetMachineBuilder(Builder, JTMB);
6367
LLVMOrcLLJITRef J;
@@ -149,9 +153,11 @@ class OrcCAPITestBase : public testing::Test {
149153
return TSM;
150154
}
151155

156+
static std::string TargetTriple;
152157
static bool TargetSupported;
153158
};
154159

160+
std::string OrcCAPITestBase::TargetTriple;
155161
bool OrcCAPITestBase::TargetSupported = false;
156162

157163
TEST_F(OrcCAPITestBase, SymbolStringPoolUniquing) {
@@ -208,7 +214,8 @@ TEST_F(OrcCAPITestBase, MaterializationUnitCreation) {
208214
LLVMOrcJITDylibDefine(MainDylib, MU);
209215
LLVMOrcJITTargetAddress OutAddr;
210216
if (LLVMOrcLLJITLookup(Jit, &OutAddr, "test")) {
211-
FAIL() << "Failed to look up \"test\" symbol";
217+
FAIL() << "Failed to look up \"test\" symbol (triple = "
218+
<< TargetTriple << ")";
212219
}
213220
ASSERT_EQ(Addr, OutAddr);
214221
}
@@ -225,7 +232,8 @@ TEST_F(OrcCAPITestBase, DefinitionGenerators) {
225232
LLVMOrcJITDylibAddGenerator(MainDylib, Gen);
226233
LLVMOrcJITTargetAddress OutAddr;
227234
if (LLVMOrcLLJITLookup(Jit, &OutAddr, "test")) {
228-
FAIL() << "The DefinitionGenerator did not create symbol \"test\"";
235+
FAIL() << "The DefinitionGenerator did not create symbol \"test\" "
236+
<< "(triple = " << TargetTriple << ")";
229237
}
230238
LLVMOrcJITTargetAddress ExpectedAddr =
231239
(LLVMOrcJITTargetAddress)(&materializationUnitFn);
@@ -245,11 +253,13 @@ TEST_F(OrcCAPITestBase, ResourceTrackerDefinitionLifetime) {
245253
LLVMOrcJITDylibCreateResourceTracker(MainDylib);
246254
LLVMOrcThreadSafeModuleRef TSM = createTestModule();
247255
if (LLVMErrorRef E = LLVMOrcLLJITAddLLVMIRModuleWithRT(Jit, RT, TSM)) {
248-
FAIL() << "Failed to add LLVM IR module to LLJIT";
256+
FAIL() << "Failed to add LLVM IR module to LLJIT (triple = "
257+
<< TargetTriple << ")";
249258
}
250259
LLVMOrcJITTargetAddress TestFnAddr;
251260
if (LLVMOrcLLJITLookup(Jit, &TestFnAddr, "sum")) {
252-
FAIL() << "Symbol \"sum\" was not added into JIT";
261+
FAIL() << "Symbol \"sum\" was not added into JIT (triple = "
262+
<< TargetTriple << ")";
253263
}
254264
ASSERT_TRUE(!!TestFnAddr);
255265
LLVMOrcResourceTrackerRemove(RT);
@@ -273,11 +283,13 @@ TEST_F(OrcCAPITestBase, ResourceTrackerTransfer) {
273283
LLVMOrcJITDylibCreateResourceTracker(MainDylib);
274284
LLVMOrcThreadSafeModuleRef TSM = createTestModule();
275285
if (LLVMErrorRef E = LLVMOrcLLJITAddLLVMIRModuleWithRT(Jit, DefaultRT, TSM)) {
276-
FAIL() << "Failed to add LLVM IR module to LLJIT";
286+
FAIL() << "Failed to add LLVM IR module to LLJIT (triple = "
287+
<< TargetTriple << ")";
277288
}
278289
LLVMOrcJITTargetAddress Addr;
279290
if (LLVMOrcLLJITLookup(Jit, &Addr, "sum")) {
280-
FAIL() << "Symbol \"sum\" was not added into JIT";
291+
FAIL() << "Symbol \"sum\" was not added into JIT (triple = "
292+
<< TargetTriple << ")";
281293
}
282294
LLVMOrcResourceTrackerTransferTo(DefaultRT, RT2);
283295
LLVMErrorRef Err = LLVMOrcLLJITLookup(Jit, &Addr, "sum");
@@ -298,12 +310,14 @@ TEST_F(OrcCAPITestBase, ExecutionTest) {
298310
LLVMOrcThreadSafeModuleRef TSM = createTestModule();
299311
if (LLVMErrorRef E = LLVMOrcLLJITAddLLVMIRModule(Jit, MainDylib, TSM)) {
300312
LLVMConsumeError(E);
301-
FAIL() << "Failed to add LLVM IR module to LLJIT";
313+
FAIL() << "Failed to add LLVM IR module to LLJIT (triple = "
314+
<< TargetTriple << ")";
302315
}
303316
LLVMOrcJITTargetAddress TestFnAddr;
304317
if (LLVMErrorRef E = LLVMOrcLLJITLookup(Jit, &TestFnAddr, "sum")) {
305318
LLVMConsumeError(E);
306-
FAIL() << "Symbol \"sum\" was not added into JIT";
319+
FAIL() << "Symbol \"sum\" was not added into JIT (triple = "
320+
<< TargetTriple << ")";
307321
}
308322
auto *SumFn = (SumFunctionType)(TestFnAddr);
309323
int32_t Result = SumFn(1, 1);

0 commit comments

Comments
 (0)
Please sign in to comment.