1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/compiler.h>
8 #include "util/synthetic-events.h"
10 static bool has_term(struct perf_record_stat_config *config,
15 for (i = 0; i < config->nr; i++) {
16 if ((config->data[i].tag == tag) &&
17 (config->data[i].val == val))
24 static int process_stat_config_event(struct perf_tool *tool __maybe_unused,
25 union perf_event *event,
26 struct perf_sample *sample __maybe_unused,
27 struct machine *machine __maybe_unused)
29 struct perf_record_stat_config *config = &event->stat_config;
30 struct perf_stat_config stat_config;
32 #define HAS(term, val) \
33 has_term(config, PERF_STAT_CONFIG_TERM__##term, val)
35 TEST_ASSERT_VAL("wrong nr", config->nr == PERF_STAT_CONFIG_TERM__MAX);
36 TEST_ASSERT_VAL("wrong aggr_mode", HAS(AGGR_MODE, AGGR_CORE));
37 TEST_ASSERT_VAL("wrong scale", HAS(SCALE, 1));
38 TEST_ASSERT_VAL("wrong interval", HAS(INTERVAL, 1));
42 perf_event__read_stat_config(&stat_config, config);
44 TEST_ASSERT_VAL("wrong aggr_mode", stat_config.aggr_mode == AGGR_CORE);
45 TEST_ASSERT_VAL("wrong scale", stat_config.scale == 1);
46 TEST_ASSERT_VAL("wrong interval", stat_config.interval == 1);
50 int test__synthesize_stat_config(struct test *test __maybe_unused, int subtest __maybe_unused)
52 struct perf_stat_config stat_config = {
53 .aggr_mode = AGGR_CORE,
58 TEST_ASSERT_VAL("failed to synthesize stat_config",
59 !perf_event__synthesize_stat_config(NULL, &stat_config, process_stat_config_event, NULL));
64 static int process_stat_event(struct perf_tool *tool __maybe_unused,
65 union perf_event *event,
66 struct perf_sample *sample __maybe_unused,
67 struct machine *machine __maybe_unused)
69 struct perf_record_stat *st = &event->stat;
71 TEST_ASSERT_VAL("wrong cpu", st->cpu == 1);
72 TEST_ASSERT_VAL("wrong thread", st->thread == 2);
73 TEST_ASSERT_VAL("wrong id", st->id == 3);
74 TEST_ASSERT_VAL("wrong val", st->val == 100);
75 TEST_ASSERT_VAL("wrong run", st->ena == 200);
76 TEST_ASSERT_VAL("wrong ena", st->run == 300);
80 int test__synthesize_stat(struct test *test __maybe_unused, int subtest __maybe_unused)
82 struct perf_counts_values count;
88 TEST_ASSERT_VAL("failed to synthesize stat_config",
89 !perf_event__synthesize_stat(NULL, 1, 2, 3, &count, process_stat_event, NULL));
94 static int process_stat_round_event(struct perf_tool *tool __maybe_unused,
95 union perf_event *event,
96 struct perf_sample *sample __maybe_unused,
97 struct machine *machine __maybe_unused)
99 struct perf_record_stat_round *stat_round = &event->stat_round;
101 TEST_ASSERT_VAL("wrong time", stat_round->time == 0xdeadbeef);
102 TEST_ASSERT_VAL("wrong type", stat_round->type == PERF_STAT_ROUND_TYPE__INTERVAL);
106 int test__synthesize_stat_round(struct test *test __maybe_unused, int subtest __maybe_unused)
108 TEST_ASSERT_VAL("failed to synthesize stat_config",
109 !perf_event__synthesize_stat_round(NULL, 0xdeadbeef, PERF_STAT_ROUND_TYPE__INTERVAL,
110 process_stat_round_event, NULL));