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

TOMOYO Linux Cross Reference
Linux/tools/perf/tests/pmu.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 "parse-events.h"
  3 #include "pmu.h"
  4 #include "tests.h"
  5 #include <errno.h>
  6 #include <stdio.h>
  7 #include <linux/kernel.h>
  8 #include <linux/limits.h>
  9 
 10 /* Simulated format definitions. */
 11 static struct test_format {
 12         const char *name;
 13         const char *value;
 14 } test_formats[] = {
 15         { "krava01", "config:0-1,62-63\n", },
 16         { "krava02", "config:10-17\n", },
 17         { "krava03", "config:5\n", },
 18         { "krava11", "config1:0,2,4,6,8,20-28\n", },
 19         { "krava12", "config1:63\n", },
 20         { "krava13", "config1:45-47\n", },
 21         { "krava21", "config2:0-3,10-13,20-23,30-33,40-43,50-53,60-63\n", },
 22         { "krava22", "config2:8,18,48,58\n", },
 23         { "krava23", "config2:28-29,38\n", },
 24 };
 25 
 26 /* Simulated users input. */
 27 static struct parse_events_term test_terms[] = {
 28         {
 29                 .config    = (char *) "krava01",
 30                 .val.num   = 15,
 31                 .type_val  = PARSE_EVENTS__TERM_TYPE_NUM,
 32                 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
 33         },
 34         {
 35                 .config    = (char *) "krava02",
 36                 .val.num   = 170,
 37                 .type_val  = PARSE_EVENTS__TERM_TYPE_NUM,
 38                 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
 39         },
 40         {
 41                 .config    = (char *) "krava03",
 42                 .val.num   = 1,
 43                 .type_val  = PARSE_EVENTS__TERM_TYPE_NUM,
 44                 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
 45         },
 46         {
 47                 .config    = (char *) "krava11",
 48                 .val.num   = 27,
 49                 .type_val  = PARSE_EVENTS__TERM_TYPE_NUM,
 50                 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
 51         },
 52         {
 53                 .config    = (char *) "krava12",
 54                 .val.num   = 1,
 55                 .type_val  = PARSE_EVENTS__TERM_TYPE_NUM,
 56                 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
 57         },
 58         {
 59                 .config    = (char *) "krava13",
 60                 .val.num   = 2,
 61                 .type_val  = PARSE_EVENTS__TERM_TYPE_NUM,
 62                 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
 63         },
 64         {
 65                 .config    = (char *) "krava21",
 66                 .val.num   = 119,
 67                 .type_val  = PARSE_EVENTS__TERM_TYPE_NUM,
 68                 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
 69         },
 70         {
 71                 .config    = (char *) "krava22",
 72                 .val.num   = 11,
 73                 .type_val  = PARSE_EVENTS__TERM_TYPE_NUM,
 74                 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
 75         },
 76         {
 77                 .config    = (char *) "krava23",
 78                 .val.num   = 2,
 79                 .type_val  = PARSE_EVENTS__TERM_TYPE_NUM,
 80                 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
 81         },
 82 };
 83 
 84 /*
 85  * Prepare format directory data, exported by kernel
 86  * at /sys/bus/event_source/devices/<dev>/format.
 87  */
 88 static char *test_format_dir_get(void)
 89 {
 90         static char dir[PATH_MAX];
 91         unsigned int i;
 92 
 93         snprintf(dir, PATH_MAX, "/tmp/perf-pmu-test-format-XXXXXX");
 94         if (!mkdtemp(dir))
 95                 return NULL;
 96 
 97         for (i = 0; i < ARRAY_SIZE(test_formats); i++) {
 98                 static char name[PATH_MAX];
 99                 struct test_format *format = &test_formats[i];
100                 FILE *file;
101 
102                 scnprintf(name, PATH_MAX, "%s/%s", dir, format->name);
103 
104                 file = fopen(name, "w");
105                 if (!file)
106                         return NULL;
107 
108                 if (1 != fwrite(format->value, strlen(format->value), 1, file))
109                         break;
110 
111                 fclose(file);
112         }
113 
114         return dir;
115 }
116 
117 /* Cleanup format directory. */
118 static int test_format_dir_put(char *dir)
119 {
120         char buf[PATH_MAX];
121         snprintf(buf, PATH_MAX, "rm -f %s/*\n", dir);
122         if (system(buf))
123                 return -1;
124 
125         snprintf(buf, PATH_MAX, "rmdir %s\n", dir);
126         return system(buf);
127 }
128 
129 static struct list_head *test_terms_list(void)
130 {
131         static LIST_HEAD(terms);
132         unsigned int i;
133 
134         for (i = 0; i < ARRAY_SIZE(test_terms); i++)
135                 list_add_tail(&test_terms[i].list, &terms);
136 
137         return &terms;
138 }
139 
140 static int test__pmu(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
141 {
142         char *format = test_format_dir_get();
143         LIST_HEAD(formats);
144         struct list_head *terms = test_terms_list();
145         int ret;
146 
147         if (!format)
148                 return -EINVAL;
149 
150         do {
151                 struct perf_event_attr attr;
152 
153                 memset(&attr, 0, sizeof(attr));
154 
155                 ret = perf_pmu__format_parse(format, &formats);
156                 if (ret)
157                         break;
158 
159                 ret = perf_pmu__config_terms("perf-pmu-test", &formats, &attr,
160                                              terms, false, NULL);
161                 if (ret)
162                         break;
163 
164                 ret = -EINVAL;
165 
166                 if (attr.config  != 0xc00000000002a823)
167                         break;
168                 if (attr.config1 != 0x8000400000000145)
169                         break;
170                 if (attr.config2 != 0x0400000020041d07)
171                         break;
172 
173                 ret = 0;
174         } while (0);
175 
176         perf_pmu__del_formats(&formats);
177         test_format_dir_put(format);
178         return ret;
179 }
180 
181 DEFINE_SUITE("Parse perf pmu format", pmu);
182 

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