]> git.karo-electronics.de Git - karo-tx-linux.git/blob - tools/perf/tests/stat.c
perf tools: Add stat config event read function
[karo-tx-linux.git] / tools / perf / tests / stat.c
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         struct perf_stat_config stat_config;
28
29 #define HAS(term, val) \
30         has_term(config, PERF_STAT_CONFIG_TERM__##term, val)
31
32         TEST_ASSERT_VAL("wrong nr",        config->nr == PERF_STAT_CONFIG_TERM__MAX);
33         TEST_ASSERT_VAL("wrong aggr_mode", HAS(AGGR_MODE, AGGR_CORE));
34         TEST_ASSERT_VAL("wrong scale",     HAS(SCALE, 1));
35         TEST_ASSERT_VAL("wrong interval",  HAS(INTERVAL, 1));
36
37 #undef HAS
38
39         perf_event__read_stat_config(&stat_config, config);
40
41         TEST_ASSERT_VAL("wrong aggr_mode", stat_config.aggr_mode == AGGR_CORE);
42         TEST_ASSERT_VAL("wrong scale",     stat_config.scale == 1);
43         TEST_ASSERT_VAL("wrong interval",  stat_config.interval == 1);
44         return 0;
45 }
46
47 int test__synthesize_stat_config(int subtest __maybe_unused)
48 {
49         struct perf_stat_config stat_config = {
50                 .aggr_mode      = AGGR_CORE,
51                 .scale          = 1,
52                 .interval       = 1,
53         };
54
55         TEST_ASSERT_VAL("failed to synthesize stat_config",
56                 !perf_event__synthesize_stat_config(NULL, &stat_config, process_event, NULL));
57
58         return 0;
59 }