~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/tests/stat.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 
 10 static 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 
 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)
 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 
 50 static int test__synthesize_stat_config(struct test_suite *test __maybe_unused,
 51                                         int subtest __maybe_unused)
 52 {
 53         struct perf_stat_config stat_config = {
 54                 .aggr_mode      = AGGR_CORE,
 55                 .scale          = 1,
 56                 .interval       = 1,
 57         };
 58 
 59         TEST_ASSERT_VAL("failed to synthesize stat_config",
 60                 !perf_event__synthesize_stat_config(NULL, &stat_config, process_stat_config_event, NULL));
 61 
 62         return 0;
 63 }
 64 
 65 static int process_stat_event(struct perf_tool *tool __maybe_unused,
 66                               union perf_event *event,
 67                               struct perf_sample *sample __maybe_unused,
 68                               struct machine *machine __maybe_unused)
 69 {
 70         struct perf_record_stat *st = &event->stat;
 71 
 72         TEST_ASSERT_VAL("wrong cpu",    st->cpu    == 1);
 73         TEST_ASSERT_VAL("wrong thread", st->thread == 2);
 74         TEST_ASSERT_VAL("wrong id",     st->id     == 3);
 75         TEST_ASSERT_VAL("wrong val",    st->val    == 100);
 76         TEST_ASSERT_VAL("wrong run",    st->ena    == 200);
 77         TEST_ASSERT_VAL("wrong ena",    st->run    == 300);
 78         return 0;
 79 }
 80 
 81 static int test__synthesize_stat(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
 82 {
 83         struct perf_counts_values count;
 84 
 85         count.val = 100;
 86         count.ena = 200;
 87         count.run = 300;
 88 
 89         TEST_ASSERT_VAL("failed to synthesize stat_config",
 90                         !perf_event__synthesize_stat(NULL, (struct perf_cpu){.cpu = 1}, 2, 3,
 91                                                      &count, process_stat_event, NULL));
 92 
 93         return 0;
 94 }
 95 
 96 static int process_stat_round_event(struct perf_tool *tool __maybe_unused,
 97                                     union perf_event *event,
 98                                     struct perf_sample *sample __maybe_unused,
 99                                     struct machine *machine __maybe_unused)
100 {
101         struct perf_record_stat_round *stat_round = &event->stat_round;
102 
103         TEST_ASSERT_VAL("wrong time", stat_round->time == 0xdeadbeef);
104         TEST_ASSERT_VAL("wrong type", stat_round->type == PERF_STAT_ROUND_TYPE__INTERVAL);
105         return 0;
106 }
107 
108 static int test__synthesize_stat_round(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
109 {
110         TEST_ASSERT_VAL("failed to synthesize stat_config",
111                 !perf_event__synthesize_stat_round(NULL, 0xdeadbeef, PERF_STAT_ROUND_TYPE__INTERVAL,
112                                                    process_stat_round_event, NULL));
113 
114         return 0;
115 }
116 
117 DEFINE_SUITE("Synthesize stat config", synthesize_stat_config);
118 DEFINE_SUITE("Synthesize stat", synthesize_stat);
119 DEFINE_SUITE("Synthesize stat round", synthesize_stat_round);
120 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php