Skip to content

Commit fa6e976

Browse files
[llvm-exegesis] Use TestBase for TargetTest (#121895)
This patch makes the PPC and X86 Exegesis TargetTests use TestBase to provide initial setup rather than doing it themselves. This promotes code reuse a little bit and makes the tests a bit more consistent (with MIPS and with the initial RISC-V tests landing soon).
1 parent e98b202 commit fa6e976

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <memory>
1313

1414
#include "MCTargetDesc/PPCMCTargetDesc.h"
15+
#include "TestBase.h"
1516
#include "llvm/MC/TargetRegistry.h"
1617
#include "llvm/Support/TargetSelect.h"
1718
#include "gmock/gmock.h"
@@ -30,7 +31,7 @@ using testing::Not;
3031

3132
constexpr const char kTriple[] = "powerpc64le-unknown-linux";
3233

33-
class PowerPCTargetTest : public ::testing::Test {
34+
class PowerPCTargetTest : public PPCTestBase {
3435
protected:
3536
PowerPCTargetTest()
3637
: ExegesisTarget_(ExegesisTarget::lookup(Triple(kTriple))) {
@@ -39,12 +40,6 @@ class PowerPCTargetTest : public ::testing::Test {
3940
Target_ = TargetRegistry::lookupTarget(kTriple, error);
4041
EXPECT_THAT(Target_, NotNull());
4142
}
42-
static void SetUpTestCase() {
43-
LLVMInitializePowerPCTargetInfo();
44-
LLVMInitializePowerPCTarget();
45-
LLVMInitializePowerPCTargetMC();
46-
InitializePowerPCExegesisTarget();
47-
}
4843

4944
const Target *Target_;
5045
const ExegesisTarget *const ExegesisTarget_;

llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "MCTargetDesc/X86MCTargetDesc.h"
1515
#include "MmapUtils.h"
1616
#include "SubprocessMemory.h"
17+
#include "TestBase.h"
1718
#include "llvm/MC/TargetRegistry.h"
1819
#include "llvm/Support/TargetSelect.h"
1920
#include "gmock/gmock.h"
@@ -112,19 +113,9 @@ Matcher<MCInst> IsStackDeallocate(unsigned Size) {
112113
ElementsAre(IsReg(X86::RSP), IsReg(X86::RSP), IsImm(Size)));
113114
}
114115

115-
constexpr const char kTriple[] = "x86_64-unknown-linux";
116-
117-
class X86TargetTest : public ::testing::Test {
116+
class X86TargetTest : public X86TestBase {
118117
protected:
119-
X86TargetTest(const char *Features)
120-
: State(cantFail(LLVMState::Create(kTriple, "core2", Features))) {}
121-
122-
static void SetUpTestCase() {
123-
LLVMInitializeX86TargetInfo();
124-
LLVMInitializeX86Target();
125-
LLVMInitializeX86TargetMC();
126-
InitializeX86ExegesisTarget();
127-
}
118+
X86TargetTest(const char *Features) : X86TestBase("core2", Features) {}
128119

129120
std::vector<MCInst> setRegTo(unsigned Reg, const APInt &Value) {
130121
return State.getExegesisTarget().setRegTo(State.getSubtargetInfo(), Reg,
@@ -134,8 +125,6 @@ class X86TargetTest : public ::testing::Test {
134125
const Instruction &getInstr(unsigned OpCode) {
135126
return State.getIC().getInstr(OpCode);
136127
}
137-
138-
LLVMState State;
139128
};
140129

141130
class X86Core2TargetTest : public X86TargetTest {

llvm/unittests/tools/llvm-exegesis/X86/TestBase.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ namespace exegesis {
2222

2323
void InitializeX86ExegesisTarget();
2424

25+
constexpr const char kTriple[] = "x86_64-unknown-linux";
26+
2527
class X86TestBase : public ::testing::Test {
2628
protected:
27-
X86TestBase()
28-
: State(cantFail(LLVMState::Create("x86_64-unknown-linux", "haswell"))) {}
29+
X86TestBase(std::string CPUName = "haswell", const char *Features = "")
30+
: State(cantFail(LLVMState::Create(kTriple, CPUName, Features))) {}
2931

3032
static void SetUpTestCase() {
3133
LLVMInitializeX86TargetInfo();

0 commit comments

Comments
 (0)