@@ -54,27 +54,32 @@ class MIR2VecVocabTestFixture : public ::testing::Test {
54
54
std::unique_ptr<TargetMachine> TM;
55
55
const TargetInstrInfo *TII;
56
56
57
+ static void SetUpTestCase () {
58
+ InitializeAllTargets ();
59
+ InitializeAllTargetMCs ();
60
+ }
61
+
57
62
void SetUp () override {
58
- LLVMInitializeX86TargetInfo ();
59
- LLVMInitializeX86Target ();
60
- LLVMInitializeX86TargetMC ();
63
+ Triple TargetTriple (" x86_64-unknown-linux-gnu" );
64
+ std::string Error;
65
+ const Target *T = TargetRegistry::lookupTarget (" " , TargetTriple, Error);
66
+ if (!T) {
67
+ GTEST_SKIP () << " x86_64-unknown-linux-gnu target triple not available; "
68
+ " Skipping test" ;
69
+ return ;
70
+ }
61
71
62
72
Ctx = std::make_unique<LLVMContext>();
63
73
M = std::make_unique<Module>(" test" , *Ctx);
64
-
65
- // Set up X86 target
66
- Triple TargetTriple (" x86_64-unknown-linux-gnu" );
67
74
M->setTargetTriple (TargetTriple);
68
75
69
- std::string Error;
70
- const Target *TheTarget =
71
- TargetRegistry::lookupTarget (M->getTargetTriple (), Error);
72
- ASSERT_TRUE (TheTarget) << " Failed to lookup target: " << Error;
73
-
74
76
TargetOptions Options;
75
- TM = std::unique_ptr<TargetMachine>(TheTarget->createTargetMachine (
76
- M->getTargetTriple (), " " , " " , Options, Reloc::Model::Static));
77
- ASSERT_TRUE (TM);
77
+ TM = std::unique_ptr<TargetMachine>(
78
+ T->createTargetMachine (TargetTriple, " " , " " , Options, std::nullopt ));
79
+ if (!TM) {
80
+ GTEST_SKIP () << " Failed to create X86 target machine; Skipping test" ;
81
+ return ;
82
+ }
78
83
79
84
// Create a dummy function to get subtarget info
80
85
FunctionType *FT = FunctionType::get (Type::getVoidTy (*Ctx), false );
@@ -83,7 +88,10 @@ class MIR2VecVocabTestFixture : public ::testing::Test {
83
88
84
89
// Get the target instruction info
85
90
TII = TM->getSubtargetImpl (*F)->getInstrInfo ();
86
- ASSERT_TRUE (TII);
91
+ if (!TII) {
92
+ GTEST_SKIP () << " Failed to get target instruction info; Skipping test" ;
93
+ return ;
94
+ }
87
95
}
88
96
};
89
97
0 commit comments