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