Home | History | Annotate | Download | only in test
      1 #include <memory>
      2 
      3 #include "../src/check.h"
      4 #include "benchmark/benchmark.h"
      5 #include "output_test.h"
      6 
      7 class TestMemoryManager : public benchmark::MemoryManager {
      8   void Start() {}
      9   void Stop(Result* result) {
     10     result->num_allocs = 42;
     11     result->max_bytes_used = 42000;
     12   }
     13 };
     14 
     15 void BM_empty(benchmark::State& state) {
     16   for (auto _ : state) {
     17     benchmark::DoNotOptimize(state.iterations());
     18   }
     19 }
     20 BENCHMARK(BM_empty);
     21 
     22 ADD_CASES(TC_ConsoleOut, {{"^BM_empty %console_report$"}});
     23 ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_empty\",$"},
     24                        {"\"run_name\": \"BM_empty\",$", MR_Next},
     25                        {"\"run_type\": \"iteration\",$", MR_Next},
     26                        {"\"iterations\": %int,$", MR_Next},
     27                        {"\"real_time\": %float,$", MR_Next},
     28                        {"\"cpu_time\": %float,$", MR_Next},
     29                        {"\"time_unit\": \"ns\",$", MR_Next},
     30                        {"\"allocs_per_iter\": %float,$", MR_Next},
     31                        {"\"max_bytes_used\": 42000$", MR_Next},
     32                        {"}", MR_Next}});
     33 ADD_CASES(TC_CSVOut, {{"^\"BM_empty\",%csv_report$"}});
     34 
     35 
     36 int main(int argc, char *argv[]) {
     37   std::unique_ptr<benchmark::MemoryManager> mm(new TestMemoryManager());
     38 
     39   benchmark::RegisterMemoryManager(mm.get());
     40   RunOutputTests(argc, argv);
     41   benchmark::RegisterMemoryManager(nullptr);
     42 }
     43