Index: llvm/unittests/tools/llvm-exegesis/Mips/BenchmarkResultTest.cpp =================================================================== --- llvm/unittests/tools/llvm-exegesis/Mips/BenchmarkResultTest.cpp +++ 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,10 @@ namespace { -TEST(BenchmarkResultTest, WriteToAndReadFromDisk) { - LLVMInitializeMipsTargetInfo(); - LLVMInitializeMipsTarget(); - LLVMInitializeMipsTargetMC(); - InitializeMipsExegesisTarget(); +class BenchmarkResultTest : public MipsTestBase {}; +TEST_F(BenchmarkResultTest, WriteToAndReadFromDisk) { // Read benchmarks. - const LLVMState State("mips-unknown-linux", "mips32"); - ExitOnError ExitOnErr; InstructionBenchmark ToDisk; @@ -126,7 +120,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}); Index: llvm/unittests/tools/llvm-exegesis/Mips/CMakeLists.txt =================================================================== --- llvm/unittests/tools/llvm-exegesis/Mips/CMakeLists.txt +++ llvm/unittests/tools/llvm-exegesis/Mips/CMakeLists.txt @@ -15,6 +15,7 @@ add_llvm_unittest(LLVMExegesisMipsTests BenchmarkResultTest.cpp + RegisterAliasingTest.cpp SnippetGeneratorTest.cpp TargetTest.cpp ) Index: llvm/unittests/tools/llvm-exegesis/Mips/SnippetGeneratorTest.cpp =================================================================== --- llvm/unittests/tools/llvm-exegesis/Mips/SnippetGeneratorTest.cpp +++ 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 { Index: llvm/unittests/tools/llvm-exegesis/Mips/TargetTest.cpp =================================================================== --- llvm/unittests/tools/llvm-exegesis/Mips/TargetTest.cpp +++ 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; @@ -49,25 +47,12 @@ ElementsAre(IsReg(Reg), IsReg(Mips::ZERO), IsImm(Value))); } -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, SetRegToConstant) { Index: llvm/unittests/tools/llvm-exegesis/Mips/TestBase.h =================================================================== --- /dev/null +++ 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