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

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

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ 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 "evlist.h"
  3 #include "evsel.h"
  4 #include "parse-events.h"
  5 #include "tests.h"
  6 #include "debug.h"
  7 #include <linux/kernel.h>
  8 
  9 static int perf_evsel__roundtrip_cache_name_test(void)
 10 {
 11         int ret = TEST_OK;
 12 
 13         for (int type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
 14                 for (int op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
 15                         /* skip invalid cache type */
 16                         if (!evsel__is_cache_op_valid(type, op))
 17                                 continue;
 18 
 19                         for (int res = 0; res < PERF_COUNT_HW_CACHE_RESULT_MAX; res++) {
 20                                 char name[128];
 21                                 struct evlist *evlist = evlist__new();
 22                                 struct evsel *evsel;
 23                                 int err;
 24 
 25                                 if (evlist == NULL) {
 26                                         pr_debug("Failed to alloc evlist");
 27                                         return TEST_FAIL;
 28                                 }
 29                                 __evsel__hw_cache_type_op_res_name(type, op, res,
 30                                                                 name, sizeof(name));
 31 
 32                                 err = parse_event(evlist, name);
 33                                 if (err) {
 34                                         pr_debug("Failure to parse cache event '%s' possibly as PMUs don't support it",
 35                                                 name);
 36                                         evlist__delete(evlist);
 37                                         continue;
 38                                 }
 39                                 evlist__for_each_entry(evlist, evsel) {
 40                                         if (!evsel__name_is(evsel, name)) {
 41                                                 pr_debug("%s != %s\n", evsel__name(evsel), name);
 42                                                 ret = TEST_FAIL;
 43                                         }
 44                                 }
 45                                 evlist__delete(evlist);
 46                         }
 47                 }
 48         }
 49         return ret;
 50 }
 51 
 52 static int perf_evsel__name_array_test(const char *const names[], int nr_names)
 53 {
 54         int ret = TEST_OK;
 55 
 56         for (int i = 0; i < nr_names; ++i) {
 57                 struct evlist *evlist = evlist__new();
 58                 struct evsel *evsel;
 59                 int err;
 60 
 61                 if (evlist == NULL) {
 62                         pr_debug("Failed to alloc evlist");
 63                         return TEST_FAIL;
 64                 }
 65                 err = parse_event(evlist, names[i]);
 66                 if (err) {
 67                         pr_debug("failed to parse event '%s', err %d\n",
 68                                  names[i], err);
 69                         evlist__delete(evlist);
 70                         ret = TEST_FAIL;
 71                         continue;
 72                 }
 73                 evlist__for_each_entry(evlist, evsel) {
 74                         if (!evsel__name_is(evsel, names[i])) {
 75                                 pr_debug("%s != %s\n", evsel__name(evsel), names[i]);
 76                                 ret = TEST_FAIL;
 77                         }
 78                 }
 79                 evlist__delete(evlist);
 80         }
 81         return ret;
 82 }
 83 
 84 static int test__perf_evsel__roundtrip_name_test(struct test_suite *test __maybe_unused,
 85                                                  int subtest __maybe_unused)
 86 {
 87         int err = 0, ret = TEST_OK;
 88 
 89         err = perf_evsel__name_array_test(evsel__hw_names, PERF_COUNT_HW_MAX);
 90         if (err)
 91                 ret = err;
 92 
 93         err = perf_evsel__name_array_test(evsel__sw_names, PERF_COUNT_SW_DUMMY + 1);
 94         if (err)
 95                 ret = err;
 96 
 97         err = perf_evsel__roundtrip_cache_name_test();
 98         if (err)
 99                 ret = err;
100 
101         return ret;
102 }
103 
104 DEFINE_SUITE("Roundtrip evsel->name", perf_evsel__roundtrip_name_test);
105 

~ [ 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