1 //===-- TargetTest.cpp ------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
14 #include "MCTargetDesc/AArch64MCTargetDesc.h"
15 #include "llvm/Support/TargetRegistry.h"
16 #include "llvm/Support/TargetSelect.h"
17 #include "gmock/gmock.h"
18 #include "gtest/gtest.h"
23 void InitializeAArch64ExegesisTarget();
28 using testing::IsEmpty
;
30 using testing::NotNull
;
32 constexpr const char kTriple
[] = "aarch64-unknown-linux";
34 class AArch64TargetTest
: public ::testing::Test
{
37 : ExegesisTarget_(ExegesisTarget::lookup(Triple(kTriple
))) {
38 EXPECT_THAT(ExegesisTarget_
, NotNull());
40 Target_
= TargetRegistry::lookupTarget(kTriple
, error
);
41 EXPECT_THAT(Target_
, NotNull());
43 Target_
->createMCSubtargetInfo(kTriple
, "generic", /*no features*/ ""));
46 static void SetUpTestCase() {
47 LLVMInitializeAArch64TargetInfo();
48 LLVMInitializeAArch64Target();
49 LLVMInitializeAArch64TargetMC();
50 InitializeAArch64ExegesisTarget();
53 std::vector
<MCInst
> setRegTo(unsigned Reg
, const APInt
&Value
) {
54 return ExegesisTarget_
->setRegTo(*STI_
, Reg
, Value
);
57 const Target
*Target_
;
58 const ExegesisTarget
*const ExegesisTarget_
;
59 std::unique_ptr
<MCSubtargetInfo
> STI_
;
62 TEST_F(AArch64TargetTest
, SetRegToConstant
) {
63 // The AArch64 target currently doesn't know how to set register values.
64 const auto Insts
= setRegTo(AArch64::X0
, APInt());
65 EXPECT_THAT(Insts
, Not(IsEmpty()));
68 TEST_F(AArch64TargetTest
, DefaultPfmCounters
) {
69 const std::string Expected
= "CPU_CYCLES";
70 EXPECT_EQ(ExegesisTarget_
->getPfmCounters("").CycleCounter
, Expected
);
71 EXPECT_EQ(ExegesisTarget_
->getPfmCounters("unknown_cpu").CycleCounter
,
76 } // namespace exegesis