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

TOMOYO Linux Cross Reference
Linux/tools/perf/tests/evsel-roundtrip-name.c

Version: ~ [ linux-6.2-rc3 ] ~ [ linux-6.1.5 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.87 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.162 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.228 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.269 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.302 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ 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 "evlist.h"
  3 #include "evsel.h"
  4 #include "parse-events.h"
  5 #include "tests.h"
  6 #include "debug.h"
  7 #include "pmu.h"
  8 #include "pmu-hybrid.h"
  9 #include <errno.h>
 10 #include <linux/kernel.h>
 11 
 12 static int perf_evsel__roundtrip_cache_name_test(void)
 13 {
 14         char name[128];
 15         int type, op, err = 0, ret = 0, i, idx;
 16         struct evsel *evsel;
 17         struct evlist *evlist = evlist__new();
 18 
 19         if (evlist == NULL)
 20                 return -ENOMEM;
 21 
 22         for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
 23                 for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
 24                         /* skip invalid cache type */
 25                         if (!evsel__is_cache_op_valid(type, op))
 26                                 continue;
 27 
 28                         for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
 29                                 __evsel__hw_cache_type_op_res_name(type, op, i, name, sizeof(name));
 30                                 err = parse_events(evlist, name, NULL);
 31                                 if (err)
 32                                         ret = err;
 33                         }
 34                 }
 35         }
 36 
 37         idx = 0;
 38         evsel = evlist__first(evlist);
 39 
 40         for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
 41                 for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
 42                         /* skip invalid cache type */
 43                         if (!evsel__is_cache_op_valid(type, op))
 44                                 continue;
 45 
 46                         for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
 47                                 __evsel__hw_cache_type_op_res_name(type, op, i, name, sizeof(name));
 48                                 if (evsel->core.idx != idx)
 49                                         continue;
 50 
 51                                 ++idx;
 52 
 53                                 if (strcmp(evsel__name(evsel), name)) {
 54                                         pr_debug("%s != %s\n", evsel__name(evsel), name);
 55                                         ret = -1;
 56                                 }
 57 
 58                                 evsel = evsel__next(evsel);
 59                         }
 60                 }
 61         }
 62 
 63         evlist__delete(evlist);
 64         return ret;
 65 }
 66 
 67 static int __perf_evsel__name_array_test(const char *names[], int nr_names,
 68                                          int distance)
 69 {
 70         int i, err;
 71         struct evsel *evsel;
 72         struct evlist *evlist = evlist__new();
 73 
 74         if (evlist == NULL)
 75                 return -ENOMEM;
 76 
 77         for (i = 0; i < nr_names; ++i) {
 78                 err = parse_events(evlist, names[i], NULL);
 79                 if (err) {
 80                         pr_debug("failed to parse event '%s', err %d\n",
 81                                  names[i], err);
 82                         goto out_delete_evlist;
 83                 }
 84         }
 85 
 86         err = 0;
 87         evlist__for_each_entry(evlist, evsel) {
 88                 if (strcmp(evsel__name(evsel), names[evsel->core.idx / distance])) {
 89                         --err;
 90                         pr_debug("%s != %s\n", evsel__name(evsel), names[evsel->core.idx / distance]);
 91                 }
 92         }
 93 
 94 out_delete_evlist:
 95         evlist__delete(evlist);
 96         return err;
 97 }
 98 
 99 #define perf_evsel__name_array_test(names, distance) \
100         __perf_evsel__name_array_test(names, ARRAY_SIZE(names), distance)
101 
102 static int test__perf_evsel__roundtrip_name_test(struct test_suite *test __maybe_unused,
103                                                  int subtest __maybe_unused)
104 {
105         int err = 0, ret = 0;
106 
107         if (perf_pmu__has_hybrid() && perf_pmu__hybrid_mounted("cpu_atom"))
108                 return perf_evsel__name_array_test(evsel__hw_names, 2);
109 
110         err = perf_evsel__name_array_test(evsel__hw_names, 1);
111         if (err)
112                 ret = err;
113 
114         err = __perf_evsel__name_array_test(evsel__sw_names, PERF_COUNT_SW_DUMMY + 1, 1);
115         if (err)
116                 ret = err;
117 
118         err = perf_evsel__roundtrip_cache_name_test();
119         if (err)
120                 ret = err;
121 
122         return ret;
123 }
124 
125 DEFINE_SUITE("Roundtrip evsel->name", perf_evsel__roundtrip_name_test);
126 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp