blob: aa35d28294a0c538678ee5fef201bbca392b3bb8 [file] [log] [blame]
Jiri Olsa67424342015-10-25 15:51:28 +01001#include <linux/compiler.h>
2#include "event.h"
3#include "tests.h"
4#include "stat.h"
5#include "debug.h"
6
7static 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
21static 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;
Jiri Olsa8e381592015-10-25 15:51:29 +010027 struct perf_stat_config stat_config;
Jiri Olsa67424342015-10-25 15:51:28 +010028
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
Jiri Olsa8e381592015-10-25 15:51:29 +010039 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);
Jiri Olsa67424342015-10-25 15:51:28 +010044 return 0;
45}
46
47int 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}