167424342SJiri Olsa #include <linux/compiler.h> 267424342SJiri Olsa #include "event.h" 367424342SJiri Olsa #include "tests.h" 467424342SJiri Olsa #include "stat.h" 55796f8f0SJiri Olsa #include "counts.h" 667424342SJiri Olsa #include "debug.h" 767424342SJiri Olsa 867424342SJiri Olsa static bool has_term(struct stat_config_event *config, 967424342SJiri Olsa u64 tag, u64 val) 1067424342SJiri Olsa { 1167424342SJiri Olsa unsigned i; 1267424342SJiri Olsa 1367424342SJiri Olsa for (i = 0; i < config->nr; i++) { 1467424342SJiri Olsa if ((config->data[i].tag == tag) && 1567424342SJiri Olsa (config->data[i].val == val)) 1667424342SJiri Olsa return true; 1767424342SJiri Olsa } 1867424342SJiri Olsa 1967424342SJiri Olsa return false; 2067424342SJiri Olsa } 2167424342SJiri Olsa 225796f8f0SJiri Olsa static int process_stat_config_event(struct perf_tool *tool __maybe_unused, 2367424342SJiri Olsa union perf_event *event, 2467424342SJiri Olsa struct perf_sample *sample __maybe_unused, 2567424342SJiri Olsa struct machine *machine __maybe_unused) 2667424342SJiri Olsa { 2767424342SJiri Olsa struct stat_config_event *config = &event->stat_config; 288e381596SJiri Olsa struct perf_stat_config stat_config; 2967424342SJiri Olsa 3067424342SJiri Olsa #define HAS(term, val) \ 3167424342SJiri Olsa has_term(config, PERF_STAT_CONFIG_TERM__##term, val) 3267424342SJiri Olsa 3367424342SJiri Olsa TEST_ASSERT_VAL("wrong nr", config->nr == PERF_STAT_CONFIG_TERM__MAX); 3467424342SJiri Olsa TEST_ASSERT_VAL("wrong aggr_mode", HAS(AGGR_MODE, AGGR_CORE)); 3567424342SJiri Olsa TEST_ASSERT_VAL("wrong scale", HAS(SCALE, 1)); 3667424342SJiri Olsa TEST_ASSERT_VAL("wrong interval", HAS(INTERVAL, 1)); 3767424342SJiri Olsa 3867424342SJiri Olsa #undef HAS 3967424342SJiri Olsa 408e381596SJiri Olsa perf_event__read_stat_config(&stat_config, config); 418e381596SJiri Olsa 428e381596SJiri Olsa TEST_ASSERT_VAL("wrong aggr_mode", stat_config.aggr_mode == AGGR_CORE); 438e381596SJiri Olsa TEST_ASSERT_VAL("wrong scale", stat_config.scale == 1); 448e381596SJiri Olsa TEST_ASSERT_VAL("wrong interval", stat_config.interval == 1); 4567424342SJiri Olsa return 0; 4667424342SJiri Olsa } 4767424342SJiri Olsa 4867424342SJiri Olsa int test__synthesize_stat_config(int subtest __maybe_unused) 4967424342SJiri Olsa { 5067424342SJiri Olsa struct perf_stat_config stat_config = { 5167424342SJiri Olsa .aggr_mode = AGGR_CORE, 5267424342SJiri Olsa .scale = 1, 5367424342SJiri Olsa .interval = 1, 5467424342SJiri Olsa }; 5567424342SJiri Olsa 5667424342SJiri Olsa TEST_ASSERT_VAL("failed to synthesize stat_config", 575796f8f0SJiri Olsa !perf_event__synthesize_stat_config(NULL, &stat_config, process_stat_config_event, NULL)); 585796f8f0SJiri Olsa 595796f8f0SJiri Olsa return 0; 605796f8f0SJiri Olsa } 615796f8f0SJiri Olsa 625796f8f0SJiri Olsa static int process_stat_event(struct perf_tool *tool __maybe_unused, 635796f8f0SJiri Olsa union perf_event *event, 645796f8f0SJiri Olsa struct perf_sample *sample __maybe_unused, 655796f8f0SJiri Olsa struct machine *machine __maybe_unused) 665796f8f0SJiri Olsa { 675796f8f0SJiri Olsa struct stat_event *st = &event->stat; 685796f8f0SJiri Olsa 695796f8f0SJiri Olsa TEST_ASSERT_VAL("wrong cpu", st->cpu == 1); 705796f8f0SJiri Olsa TEST_ASSERT_VAL("wrong thread", st->thread == 2); 715796f8f0SJiri Olsa TEST_ASSERT_VAL("wrong id", st->id == 3); 725796f8f0SJiri Olsa TEST_ASSERT_VAL("wrong val", st->val == 100); 735796f8f0SJiri Olsa TEST_ASSERT_VAL("wrong run", st->ena == 200); 745796f8f0SJiri Olsa TEST_ASSERT_VAL("wrong ena", st->run == 300); 755796f8f0SJiri Olsa return 0; 765796f8f0SJiri Olsa } 775796f8f0SJiri Olsa 785796f8f0SJiri Olsa int test__synthesize_stat(int subtest __maybe_unused) 795796f8f0SJiri Olsa { 805796f8f0SJiri Olsa struct perf_counts_values count; 815796f8f0SJiri Olsa 825796f8f0SJiri Olsa count.val = 100; 835796f8f0SJiri Olsa count.ena = 200; 845796f8f0SJiri Olsa count.run = 300; 855796f8f0SJiri Olsa 865796f8f0SJiri Olsa TEST_ASSERT_VAL("failed to synthesize stat_config", 875796f8f0SJiri Olsa !perf_event__synthesize_stat(NULL, 1, 2, 3, &count, process_stat_event, NULL)); 8867424342SJiri Olsa 8967424342SJiri Olsa return 0; 9067424342SJiri Olsa } 91*d4c22591SJiri Olsa 92*d4c22591SJiri Olsa static int process_stat_round_event(struct perf_tool *tool __maybe_unused, 93*d4c22591SJiri Olsa union perf_event *event, 94*d4c22591SJiri Olsa struct perf_sample *sample __maybe_unused, 95*d4c22591SJiri Olsa struct machine *machine __maybe_unused) 96*d4c22591SJiri Olsa { 97*d4c22591SJiri Olsa struct stat_round_event *stat_round = &event->stat_round; 98*d4c22591SJiri Olsa 99*d4c22591SJiri Olsa TEST_ASSERT_VAL("wrong time", stat_round->time == 0xdeadbeef); 100*d4c22591SJiri Olsa TEST_ASSERT_VAL("wrong type", stat_round->type == PERF_STAT_ROUND_TYPE__INTERVAL); 101*d4c22591SJiri Olsa return 0; 102*d4c22591SJiri Olsa } 103*d4c22591SJiri Olsa 104*d4c22591SJiri Olsa int test__synthesize_stat_round(int subtest __maybe_unused) 105*d4c22591SJiri Olsa { 106*d4c22591SJiri Olsa TEST_ASSERT_VAL("failed to synthesize stat_config", 107*d4c22591SJiri Olsa !perf_event__synthesize_stat_round(NULL, 0xdeadbeef, PERF_STAT_ROUND_TYPE__INTERVAL, 108*d4c22591SJiri Olsa process_stat_round_event, NULL)); 109*d4c22591SJiri Olsa 110*d4c22591SJiri Olsa return 0; 111*d4c22591SJiri Olsa } 112