diff --git a/llvm/unittests/tools/llvm-exegesis/Mips/BenchmarkResultTest.cpp b/llvm/unittests/tools/llvm-exegesis/Mips/BenchmarkResultTest.cpp --- a/llvm/unittests/tools/llvm-exegesis/Mips/BenchmarkResultTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/Mips/BenchmarkResultTest.cpp @@ -8,6 +8,7 @@ #include "BenchmarkResult.h" #include "MipsInstrInfo.h" +#include "TestBase.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/Error.h" #include "llvm/Support/Path.h" @@ -27,8 +28,6 @@ namespace llvm { namespace exegesis { -void InitializeMipsExegesisTarget(); - bool operator==(const BenchmarkMeasure &A, const BenchmarkMeasure &B) { return std::tie(A.Key, A.PerInstructionValue, A.PerSnippetValue) == std::tie(B.Key, B.PerInstructionValue, B.PerSnippetValue); @@ -53,15 +52,9 @@ namespace { -TEST(BenchmarkResultTest, WriteToAndReadFromDisk) { - LLVMInitializeMipsTargetInfo(); - LLVMInitializeMipsTarget(); - LLVMInitializeMipsTargetMC(); - InitializeMipsExegesisTarget(); - - // Read benchmarks. - const LLVMState State("mips-unknown-linux", "mips32"); +class BenchmarkResultTest : public MipsTestBase {}; +TEST_F(BenchmarkResultTest, WriteToAndReadFromDisk) { ExitOnError ExitOnErr; InstructionBenchmark ToDisk; @@ -126,7 +119,7 @@ } } -TEST(BenchmarkResultTest, PerInstructionStats) { +TEST_F(BenchmarkResultTest, PerInstructionStats) { PerInstructionStats Stats; Stats.push(BenchmarkMeasure{"a", 0.5, 0.0}); Stats.push(BenchmarkMeasure{"a", 1.5, 0.0}); diff --git a/llvm/unittests/tools/llvm-exegesis/Mips/SnippetGeneratorTest.cpp b/llvm/unittests/tools/llvm-exegesis/Mips/SnippetGeneratorTest.cpp --- a/llvm/unittests/tools/llvm-exegesis/Mips/SnippetGeneratorTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/Mips/SnippetGeneratorTest.cpp @@ -10,16 +10,14 @@ #include "Latency.h" #include "LlvmState.h" #include "MCInstrDescView.h" -#include "RegisterAliasing.h" #include "MipsInstrInfo.h" +#include "RegisterAliasing.h" +#include "TestBase.h" #include namespace llvm { namespace exegesis { - -void InitializeMipsExegesisTarget(); - namespace { using testing::AnyOf; @@ -29,21 +27,7 @@ MATCHER(IsInvalid, "") { return !arg.isValid(); } MATCHER(IsReg, "") { return arg.isReg(); } -class MipsSnippetGeneratorTest : public ::testing::Test { -protected: - MipsSnippetGeneratorTest() : State("mips-unknown-linux", "mips32"), - InstrInfo(State.getInstrInfo()) {} - - static void SetUpTestCase() { - LLVMInitializeMipsTargetInfo(); - LLVMInitializeMipsTarget(); - LLVMInitializeMipsTargetMC(); - InitializeMipsExegesisTarget(); - } - - LLVMState State; - const MCInstrInfo &InstrInfo; -}; +class MipsSnippetGeneratorTest : public MipsTestBase {}; template class SnippetGeneratorTest : public MipsSnippetGeneratorTest { diff --git a/llvm/unittests/tools/llvm-exegesis/Mips/TargetTest.cpp b/llvm/unittests/tools/llvm-exegesis/Mips/TargetTest.cpp --- a/llvm/unittests/tools/llvm-exegesis/Mips/TargetTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/Mips/TargetTest.cpp @@ -12,6 +12,7 @@ #include #include "MCTargetDesc/MipsMCTargetDesc.h" +#include "TestBase.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "gmock/gmock.h" @@ -19,9 +20,6 @@ namespace llvm { namespace exegesis { - -void InitializeMipsExegesisTarget(); - namespace { using testing::AllOf; @@ -62,25 +60,12 @@ ElementsAre(IsReg(Reg), IsReg(Reg), IsImm(Amount))); } -constexpr const char kTriple[] = "mips-unknown-linux"; - -class MipsTargetTest : public ::testing::Test { +class MipsTargetTest : public MipsTestBase { protected: - MipsTargetTest() : State(kTriple, "mips32", "") {} - - static void SetUpTestCase() { - LLVMInitializeMipsTargetInfo(); - LLVMInitializeMipsTarget(); - LLVMInitializeMipsTargetMC(); - InitializeMipsExegesisTarget(); - } - std::vector setRegTo(unsigned Reg, const APInt &Value) { return State.getExegesisTarget().setRegTo(State.getSubtargetInfo(), Reg, Value); } - - LLVMState State; }; TEST_F(MipsTargetTest, SetGPR32RegTo16BitValue) { diff --git a/llvm/unittests/tools/llvm-exegesis/Mips/TestBase.h b/llvm/unittests/tools/llvm-exegesis/Mips/TestBase.h new file mode 100644 --- /dev/null +++ b/llvm/unittests/tools/llvm-exegesis/Mips/TestBase.h @@ -0,0 +1,42 @@ +//===-- TestBase.h ----------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// Test fixture common to all Mips tests. +//===----------------------------------------------------------------------===// + +#ifndef LLVM_UNITTESTS_TOOLS_LLVMEXEGESIS_MIPS_TESTBASE_H +#define LLVM_UNITTESTS_TOOLS_LLVMEXEGESIS_MIPS_TESTBASE_H + +#include "LlvmState.h" +#include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/TargetSelect.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +namespace llvm { +namespace exegesis { + +void InitializeMipsExegesisTarget(); + +class MipsTestBase : public ::testing::Test { +protected: + MipsTestBase() : State("mips-unknown-linux", "mips32") {} + + static void SetUpTestCase() { + LLVMInitializeMipsTargetInfo(); + LLVMInitializeMipsTargetMC(); + LLVMInitializeMipsTarget(); + InitializeMipsExegesisTarget(); + } + + const LLVMState State; +}; + +} // namespace exegesis +} // namespace llvm + +#endif