Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Jiri Olsa | 6742434 | 2015-10-25 15:51:28 +0100 | [diff] [blame] | 2 | #include <linux/compiler.h> |
| 3 | #include "event.h" |
| 4 | #include "tests.h" |
| 5 | #include "stat.h" |
Jiri Olsa | 5796f8f | 2015-10-25 15:51:31 +0100 | [diff] [blame] | 6 | #include "counts.h" |
Jiri Olsa | 6742434 | 2015-10-25 15:51:28 +0100 | [diff] [blame] | 7 | #include "debug.h" |
| 8 | |
| 9 | static bool has_term(struct stat_config_event *config, |
| 10 | u64 tag, u64 val) |
| 11 | { |
| 12 | unsigned i; |
| 13 | |
| 14 | for (i = 0; i < config->nr; i++) { |
| 15 | if ((config->data[i].tag == tag) && |
| 16 | (config->data[i].val == val)) |
| 17 | return true; |
| 18 | } |
| 19 | |
| 20 | return false; |
| 21 | } |
| 22 | |
Jiri Olsa | 5796f8f | 2015-10-25 15:51:31 +0100 | [diff] [blame] | 23 | static int process_stat_config_event(struct perf_tool *tool __maybe_unused, |
| 24 | union perf_event *event, |
| 25 | struct perf_sample *sample __maybe_unused, |
| 26 | struct machine *machine __maybe_unused) |
Jiri Olsa | 6742434 | 2015-10-25 15:51:28 +0100 | [diff] [blame] | 27 | { |
| 28 | struct stat_config_event *config = &event->stat_config; |
Jiri Olsa | 8e38159 | 2015-10-25 15:51:29 +0100 | [diff] [blame] | 29 | struct perf_stat_config stat_config; |
Jiri Olsa | 6742434 | 2015-10-25 15:51:28 +0100 | [diff] [blame] | 30 | |
| 31 | #define HAS(term, val) \ |
| 32 | has_term(config, PERF_STAT_CONFIG_TERM__##term, val) |
| 33 | |
| 34 | TEST_ASSERT_VAL("wrong nr", config->nr == PERF_STAT_CONFIG_TERM__MAX); |
| 35 | TEST_ASSERT_VAL("wrong aggr_mode", HAS(AGGR_MODE, AGGR_CORE)); |
| 36 | TEST_ASSERT_VAL("wrong scale", HAS(SCALE, 1)); |
| 37 | TEST_ASSERT_VAL("wrong interval", HAS(INTERVAL, 1)); |
| 38 | |
| 39 | #undef HAS |
| 40 | |
Jiri Olsa | 8e38159 | 2015-10-25 15:51:29 +0100 | [diff] [blame] | 41 | perf_event__read_stat_config(&stat_config, config); |
| 42 | |
| 43 | TEST_ASSERT_VAL("wrong aggr_mode", stat_config.aggr_mode == AGGR_CORE); |
| 44 | TEST_ASSERT_VAL("wrong scale", stat_config.scale == 1); |
| 45 | TEST_ASSERT_VAL("wrong interval", stat_config.interval == 1); |
Jiri Olsa | 6742434 | 2015-10-25 15:51:28 +0100 | [diff] [blame] | 46 | return 0; |
| 47 | } |
| 48 | |
Arnaldo Carvalho de Melo | 81f17c9 | 2017-08-03 15:16:31 -0300 | [diff] [blame] | 49 | int test__synthesize_stat_config(struct test *test __maybe_unused, int subtest __maybe_unused) |
Jiri Olsa | 6742434 | 2015-10-25 15:51:28 +0100 | [diff] [blame] | 50 | { |
| 51 | struct perf_stat_config stat_config = { |
| 52 | .aggr_mode = AGGR_CORE, |
| 53 | .scale = 1, |
| 54 | .interval = 1, |
| 55 | }; |
| 56 | |
| 57 | TEST_ASSERT_VAL("failed to synthesize stat_config", |
Jiri Olsa | 5796f8f | 2015-10-25 15:51:31 +0100 | [diff] [blame] | 58 | !perf_event__synthesize_stat_config(NULL, &stat_config, process_stat_config_event, NULL)); |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | static int process_stat_event(struct perf_tool *tool __maybe_unused, |
| 64 | union perf_event *event, |
| 65 | struct perf_sample *sample __maybe_unused, |
| 66 | struct machine *machine __maybe_unused) |
| 67 | { |
| 68 | struct stat_event *st = &event->stat; |
| 69 | |
| 70 | TEST_ASSERT_VAL("wrong cpu", st->cpu == 1); |
| 71 | TEST_ASSERT_VAL("wrong thread", st->thread == 2); |
| 72 | TEST_ASSERT_VAL("wrong id", st->id == 3); |
| 73 | TEST_ASSERT_VAL("wrong val", st->val == 100); |
| 74 | TEST_ASSERT_VAL("wrong run", st->ena == 200); |
| 75 | TEST_ASSERT_VAL("wrong ena", st->run == 300); |
| 76 | return 0; |
| 77 | } |
| 78 | |
Arnaldo Carvalho de Melo | 81f17c9 | 2017-08-03 15:16:31 -0300 | [diff] [blame] | 79 | int test__synthesize_stat(struct test *test __maybe_unused, int subtest __maybe_unused) |
Jiri Olsa | 5796f8f | 2015-10-25 15:51:31 +0100 | [diff] [blame] | 80 | { |
| 81 | struct perf_counts_values count; |
| 82 | |
| 83 | count.val = 100; |
| 84 | count.ena = 200; |
| 85 | count.run = 300; |
| 86 | |
| 87 | TEST_ASSERT_VAL("failed to synthesize stat_config", |
| 88 | !perf_event__synthesize_stat(NULL, 1, 2, 3, &count, process_stat_event, NULL)); |
Jiri Olsa | 6742434 | 2015-10-25 15:51:28 +0100 | [diff] [blame] | 89 | |
| 90 | return 0; |
| 91 | } |
Jiri Olsa | d4c2259 | 2015-10-25 15:51:34 +0100 | [diff] [blame] | 92 | |
| 93 | static int process_stat_round_event(struct perf_tool *tool __maybe_unused, |
| 94 | union perf_event *event, |
| 95 | struct perf_sample *sample __maybe_unused, |
| 96 | struct machine *machine __maybe_unused) |
| 97 | { |
| 98 | struct stat_round_event *stat_round = &event->stat_round; |
| 99 | |
| 100 | TEST_ASSERT_VAL("wrong time", stat_round->time == 0xdeadbeef); |
| 101 | TEST_ASSERT_VAL("wrong type", stat_round->type == PERF_STAT_ROUND_TYPE__INTERVAL); |
| 102 | return 0; |
| 103 | } |
| 104 | |
Arnaldo Carvalho de Melo | 81f17c9 | 2017-08-03 15:16:31 -0300 | [diff] [blame] | 105 | int test__synthesize_stat_round(struct test *test __maybe_unused, int subtest __maybe_unused) |
Jiri Olsa | d4c2259 | 2015-10-25 15:51:34 +0100 | [diff] [blame] | 106 | { |
| 107 | TEST_ASSERT_VAL("failed to synthesize stat_config", |
| 108 | !perf_event__synthesize_stat_round(NULL, 0xdeadbeef, PERF_STAT_ROUND_TYPE__INTERVAL, |
| 109 | process_stat_round_event, NULL)); |
| 110 | |
| 111 | return 0; |
| 112 | } |