[llvm-exegesis][NFC] Refactor Mips tests fixtures into a base class.

Differential Revision: https://reviews.llvm.org/D72003
This commit is contained in:
Miloš Stojanović 2019-12-30 15:50:51 +01:00
parent 4ca1ad85b7
commit 31458a9fee
4 changed files with 51 additions and 47 deletions

View File

@ -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 @@ using ::testing::Property;
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 @@ MATCHER(EqMCInst, "") {
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, WriteToAndReadFromDisk) {
}
}
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});

View File

@ -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 <unordered_set>
namespace llvm {
namespace exegesis {
void InitializeMipsExegesisTarget();
namespace {
using testing::AnyOf;
@ -29,21 +27,7 @@ using testing::SizeIs;
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 <typename SnippetGeneratorT>
class SnippetGeneratorTest : public MipsSnippetGeneratorTest {

View File

@ -12,6 +12,7 @@
#include <memory>
#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 @@ Matcher<MCInst> IsShift(unsigned Reg, uint16_t Amount, bool IsGPR32) {
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<MCInst> setRegTo(unsigned Reg, const APInt &Value) {
return State.getExegesisTarget().setRegTo(State.getSubtargetInfo(), Reg,
Value);
}
LLVMState State;
};
TEST_F(MipsTargetTest, SetGPR32RegTo16BitValue) {

View File

@ -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