Jiri Olsa | 6742434 | 2015-10-25 15:51:28 +0100 | [diff] [blame^] | 1 | #include <linux/compiler.h> |
| 2 | #include "event.h" |
| 3 | #include "tests.h" |
| 4 | #include "stat.h" |
| 5 | #include "debug.h" |
| 6 | |
| 7 | static bool has_term(struct stat_config_event *config, |
| 8 | u64 tag, u64 val) |
| 9 | { |
| 10 | unsigned i; |
| 11 | |
| 12 | for (i = 0; i < config->nr; i++) { |
| 13 | if ((config->data[i].tag == tag) && |
| 14 | (config->data[i].val == val)) |
| 15 | return true; |
| 16 | } |
| 17 | |
| 18 | return false; |
| 19 | } |
| 20 | |
| 21 | static int process_event(struct perf_tool *tool __maybe_unused, |
| 22 | union perf_event *event, |
| 23 | struct perf_sample *sample __maybe_unused, |
| 24 | struct machine *machine __maybe_unused) |
| 25 | { |
| 26 | struct stat_config_event *config = &event->stat_config; |
| 27 | |
| 28 | #define HAS(term, val) \ |
| 29 | has_term(config, PERF_STAT_CONFIG_TERM__##term, val) |
| 30 | |
| 31 | TEST_ASSERT_VAL("wrong nr", config->nr == PERF_STAT_CONFIG_TERM__MAX); |
| 32 | TEST_ASSERT_VAL("wrong aggr_mode", HAS(AGGR_MODE, AGGR_CORE)); |
| 33 | TEST_ASSERT_VAL("wrong scale", HAS(SCALE, 1)); |
| 34 | TEST_ASSERT_VAL("wrong interval", HAS(INTERVAL, 1)); |
| 35 | |
| 36 | #undef HAS |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | int test__synthesize_stat_config(int subtest __maybe_unused) |
| 42 | { |
| 43 | struct perf_stat_config stat_config = { |
| 44 | .aggr_mode = AGGR_CORE, |
| 45 | .scale = 1, |
| 46 | .interval = 1, |
| 47 | }; |
| 48 | |
| 49 | TEST_ASSERT_VAL("failed to synthesize stat_config", |
| 50 | !perf_event__synthesize_stat_config(NULL, &stat_config, process_event, NULL)); |
| 51 | |
| 52 | return 0; |
| 53 | } |