benchmark/test/perf_counters_test.cc
Andy Christiansen 4931aefb51
Fix broken PFM-enabled tests (#1623)
* Add pfm CI actions for bazel

* Fix problems in unit test.

* Undo enabling the CI tests for pfm - github CI machines seemingly do not support performance counters.

* Remove commented code - can be revisited in github history when needed, and there's a comment explaining the rationale behind the new test code.

---------

Co-authored-by: Andy Christiansen <achristiansen@google.com>
Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-07-07 09:58:16 +01:00

38 lines
945 B
C++

#undef NDEBUG
#include "../src/perf_counters.h"
#include "../src/commandlineflags.h"
#include "benchmark/benchmark.h"
#include "output_test.h"
namespace benchmark {
BM_DECLARE_string(benchmark_perf_counters);
} // namespace benchmark
static void BM_Simple(benchmark::State& state) {
for (auto _ : state) {
auto iterations = state.iterations();
benchmark::DoNotOptimize(iterations);
}
}
BENCHMARK(BM_Simple);
ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_Simple\",$"}});
static void CheckSimple(Results const& e) {
CHECK_COUNTER_VALUE(e, double, "CYCLES", GT, 0);
CHECK_COUNTER_VALUE(e, double, "BRANCHES", GT, 0.0);
}
CHECK_BENCHMARK_RESULTS("BM_Simple", &CheckSimple);
int main(int argc, char* argv[]) {
if (!benchmark::internal::PerfCounters::kSupported) {
return 0;
}
benchmark::FLAGS_benchmark_perf_counters = "CYCLES,BRANCHES";
benchmark::internal::PerfCounters::Initialize();
RunOutputTests(argc, argv);
}