OSDN Git Service

Add llvm-exegesis tool.
[android-x86/external-llvm.git] / unittests / tools / llvm-exegesis / PerfHelperTest.cpp
1 //===-- PerfHelperTest.cpp --------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "PerfHelper.h"
11 #include "llvm/Config/config.h"
12 #include "gmock/gmock.h"
13 #include "gtest/gtest.h"
14
15 namespace exegesis {
16 namespace pfm {
17 namespace {
18
19 using ::testing::IsEmpty;
20 using ::testing::Not;
21
22 TEST(PerfHelperTest, FunctionalTest) {
23 #ifdef HAVE_LIBPFM
24   ASSERT_FALSE(pfmInitialize());
25   const PerfEvent SingleEvent("CYCLES:u");
26   const auto &EmptyFn = []() {};
27   std::string CallbackEventName;
28   std::string CallbackEventNameFullyQualifed;
29   int64_t CallbackEventCycles;
30   Measure(llvm::makeArrayRef(SingleEvent),
31           [&](const PerfEvent &Event, int64_t Value) {
32             CallbackEventName = Event.name();
33             CallbackEventNameFullyQualifed = Event.getPfmEventString();
34             CallbackEventCycles = Value;
35           },
36           EmptyFn);
37   EXPECT_EQ(CallbackEventName, "CYCLES:u");
38   EXPECT_THAT(CallbackEventNameFullyQualifed, Not(IsEmpty()));
39   pfmTerminate();
40 #else
41   ASSERT_TRUE(PfmInitialize());
42 #endif
43 }
44
45 } // namespace
46 } // namespace pfm
47 } // namespace exegesis