Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 1 | //===-- PerfHelperTest.cpp --------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "PerfHelper.h" |
| 10 | #include "llvm/Config/config.h" |
| 11 | #include "gmock/gmock.h" |
| 12 | #include "gtest/gtest.h" |
| 13 | |
Fangrui Song | 32401af | 2018-10-22 17:10:47 +0000 | [diff] [blame] | 14 | namespace llvm { |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 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; |
Clement Courbet | d422d3a | 2019-10-09 11:29:21 +0000 | [diff] [blame^] | 30 | Measure( |
| 31 | makeArrayRef(SingleEvent), |
| 32 | [&](const PerfEvent &Event, int64_t Value) { |
| 33 | CallbackEventName = Event.name(); |
| 34 | CallbackEventNameFullyQualifed = Event.getPfmEventString(); |
| 35 | CallbackEventCycles = Value; |
| 36 | }, |
| 37 | EmptyFn); |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 38 | EXPECT_EQ(CallbackEventName, "CYCLES:u"); |
| 39 | EXPECT_THAT(CallbackEventNameFullyQualifed, Not(IsEmpty())); |
| 40 | pfmTerminate(); |
| 41 | #else |
Clement Courbet | 5988842 | 2018-04-04 11:48:15 +0000 | [diff] [blame] | 42 | ASSERT_TRUE(pfmInitialize()); |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 43 | #endif |
| 44 | } |
| 45 | |
| 46 | } // namespace |
| 47 | } // namespace pfm |
| 48 | } // namespace exegesis |
Fangrui Song | 32401af | 2018-10-22 17:10:47 +0000 | [diff] [blame] | 49 | } // namespace llvm |