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

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

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ 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.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/perf/tests/cpumap.c (Version linux-6.12-rc7) and /tools/perf/tests/cpumap.c (Version linux-5.9.16)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 #include "tests.h"                                  2 #include "tests.h"
  3 #include <stdio.h>                                  3 #include <stdio.h>
  4 #include "cpumap.h"                                 4 #include "cpumap.h"
  5 #include "event.h"                                  5 #include "event.h"
  6 #include "util/synthetic-events.h"                  6 #include "util/synthetic-events.h"
  7 #include <string.h>                                 7 #include <string.h>
  8 #include <linux/bitops.h>                           8 #include <linux/bitops.h>
  9 #include <internal/cpumap.h>                   !!   9 #include <perf/cpumap.h>
 10 #include "debug.h"                                 10 #include "debug.h"
 11                                                    11 
 12 struct machine;                                    12 struct machine;
 13                                                    13 
 14 static int process_event_mask(const struct per !!  14 static int process_event_mask(struct perf_tool *tool __maybe_unused,
 15                          union perf_event *eve     15                          union perf_event *event,
 16                          struct perf_sample *s     16                          struct perf_sample *sample __maybe_unused,
 17                          struct machine *machi     17                          struct machine *machine __maybe_unused)
 18 {                                                  18 {
 19         struct perf_record_cpu_map *map_event      19         struct perf_record_cpu_map *map_event = &event->cpu_map;
                                                   >>  20         struct perf_record_record_cpu_map *mask;
 20         struct perf_record_cpu_map_data *data;     21         struct perf_record_cpu_map_data *data;
 21         struct perf_cpu_map *map;                  22         struct perf_cpu_map *map;
 22         unsigned int long_size;                !!  23         int i;
 23                                                    24 
 24         data = &map_event->data;                   25         data = &map_event->data;
 25                                                    26 
 26         TEST_ASSERT_VAL("wrong type", data->ty     27         TEST_ASSERT_VAL("wrong type", data->type == PERF_CPU_MAP__MASK);
 27                                                    28 
 28         long_size = data->mask32_data.long_siz !!  29         mask = (struct perf_record_record_cpu_map *)data->data;
 29                                                    30 
 30         TEST_ASSERT_VAL("wrong long_size", lon !!  31         TEST_ASSERT_VAL("wrong nr",   mask->nr == 1);
 31                                                    32 
 32         TEST_ASSERT_VAL("wrong nr",   data->ma !!  33         for (i = 0; i < 20; i++) {
 33                                                !!  34                 TEST_ASSERT_VAL("wrong cpu", test_bit(i, mask->mask));
 34         TEST_ASSERT_VAL("wrong cpu", perf_reco !!  35         }
 35         TEST_ASSERT_VAL("wrong cpu", !perf_rec << 
 36         for (int i = 2; i <= 20; i++)          << 
 37                 TEST_ASSERT_VAL("wrong cpu", p << 
 38                                                    36 
 39         map = cpu_map__new_data(data);             37         map = cpu_map__new_data(data);
 40         TEST_ASSERT_VAL("wrong nr",  perf_cpu_ !!  38         TEST_ASSERT_VAL("wrong nr",  map->nr == 20);
 41                                                    39 
 42         TEST_ASSERT_VAL("wrong cpu", perf_cpu_ !!  40         for (i = 0; i < 20; i++) {
 43         for (int i = 2; i <= 20; i++)          !!  41                 TEST_ASSERT_VAL("wrong cpu", map->map[i] == i);
 44                 TEST_ASSERT_VAL("wrong cpu", p !!  42         }
 45                                                    43 
 46         perf_cpu_map__put(map);                    44         perf_cpu_map__put(map);
 47         return 0;                                  45         return 0;
 48 }                                                  46 }
 49                                                    47 
 50 static int process_event_cpus(const struct per !!  48 static int process_event_cpus(struct perf_tool *tool __maybe_unused,
 51                          union perf_event *eve     49                          union perf_event *event,
 52                          struct perf_sample *s     50                          struct perf_sample *sample __maybe_unused,
 53                          struct machine *machi     51                          struct machine *machine __maybe_unused)
 54 {                                                  52 {
 55         struct perf_record_cpu_map *map_event      53         struct perf_record_cpu_map *map_event = &event->cpu_map;
                                                   >>  54         struct cpu_map_entries *cpus;
 56         struct perf_record_cpu_map_data *data;     55         struct perf_record_cpu_map_data *data;
 57         struct perf_cpu_map *map;                  56         struct perf_cpu_map *map;
 58                                                    57 
 59         data = &map_event->data;                   58         data = &map_event->data;
 60                                                    59 
 61         TEST_ASSERT_VAL("wrong type", data->ty     60         TEST_ASSERT_VAL("wrong type", data->type == PERF_CPU_MAP__CPUS);
 62                                                    61 
 63         TEST_ASSERT_VAL("wrong nr",   data->cp !!  62         cpus = (struct cpu_map_entries *)data->data;
 64         TEST_ASSERT_VAL("wrong cpu",  data->cp << 
 65         TEST_ASSERT_VAL("wrong cpu",  data->cp << 
 66                                                    63 
 67         map = cpu_map__new_data(data);         !!  64         TEST_ASSERT_VAL("wrong nr",   cpus->nr == 2);
 68         TEST_ASSERT_VAL("wrong nr",  perf_cpu_ !!  65         TEST_ASSERT_VAL("wrong cpu",  cpus->cpu[0] == 1);
 69         TEST_ASSERT_VAL("wrong cpu", perf_cpu_ !!  66         TEST_ASSERT_VAL("wrong cpu",  cpus->cpu[1] == 256);
 70         TEST_ASSERT_VAL("wrong cpu", perf_cpu_ << 
 71         TEST_ASSERT_VAL("wrong refcnt", refcou << 
 72         perf_cpu_map__put(map);                << 
 73         return 0;                              << 
 74 }                                              << 
 75                                                << 
 76 static int process_event_range_cpus(const stru << 
 77                                 union perf_eve << 
 78                                 struct perf_sa << 
 79                                 struct machine << 
 80 {                                              << 
 81         struct perf_record_cpu_map *map_event  << 
 82         struct perf_record_cpu_map_data *data; << 
 83         struct perf_cpu_map *map;              << 
 84                                                << 
 85         data = &map_event->data;               << 
 86                                                << 
 87         TEST_ASSERT_VAL("wrong type", data->ty << 
 88                                                << 
 89         TEST_ASSERT_VAL("wrong any_cpu",   dat << 
 90         TEST_ASSERT_VAL("wrong start_cpu", dat << 
 91         TEST_ASSERT_VAL("wrong end_cpu",   dat << 
 92                                                    67 
 93         map = cpu_map__new_data(data);             68         map = cpu_map__new_data(data);
 94         TEST_ASSERT_VAL("wrong nr",  perf_cpu_ !!  69         TEST_ASSERT_VAL("wrong nr",  map->nr == 2);
 95         TEST_ASSERT_VAL("wrong cpu", perf_cpu_ !!  70         TEST_ASSERT_VAL("wrong cpu", map->map[0] == 1);
 96         TEST_ASSERT_VAL("wrong cpu", perf_cpu_ !!  71         TEST_ASSERT_VAL("wrong cpu", map->map[1] == 256);
 97         TEST_ASSERT_VAL("wrong refcnt", refcou !!  72         TEST_ASSERT_VAL("wrong refcnt", refcount_read(&map->refcnt) == 1);
 98         perf_cpu_map__put(map);                    73         perf_cpu_map__put(map);
 99         return 0;                                  74         return 0;
100 }                                                  75 }
101                                                    76 
102                                                    77 
103 static int test__cpu_map_synthesize(struct tes !!  78 int test__cpu_map_synthesize(struct test *test __maybe_unused, int subtest __maybe_unused)
104 {                                                  79 {
105         struct perf_cpu_map *cpus;                 80         struct perf_cpu_map *cpus;
106                                                    81 
107         /* This one is better stored in a mask !!  82         /* This one is better stores in mask. */
108         cpus = perf_cpu_map__new("0,2-20");    !!  83         cpus = perf_cpu_map__new("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19");
109                                                    84 
110         TEST_ASSERT_VAL("failed to synthesize      85         TEST_ASSERT_VAL("failed to synthesize map",
111                 !perf_event__synthesize_cpu_ma     86                 !perf_event__synthesize_cpu_map(NULL, cpus, process_event_mask, NULL));
112                                                    87 
113         perf_cpu_map__put(cpus);                   88         perf_cpu_map__put(cpus);
114                                                    89 
115         /* This one is better stored in cpu va !!  90         /* This one is better stores in cpu values. */
116         cpus = perf_cpu_map__new("1,256");         91         cpus = perf_cpu_map__new("1,256");
117                                                    92 
118         TEST_ASSERT_VAL("failed to synthesize      93         TEST_ASSERT_VAL("failed to synthesize map",
119                 !perf_event__synthesize_cpu_ma     94                 !perf_event__synthesize_cpu_map(NULL, cpus, process_event_cpus, NULL));
120                                                    95 
121         perf_cpu_map__put(cpus);                   96         perf_cpu_map__put(cpus);
122                                                << 
123         /* This one is better stored as a rang << 
124         cpus = perf_cpu_map__new("1-256");     << 
125                                                << 
126         TEST_ASSERT_VAL("failed to synthesize  << 
127                 !perf_event__synthesize_cpu_ma << 
128                                                << 
129         perf_cpu_map__put(cpus);               << 
130         return 0;                                  97         return 0;
131 }                                                  98 }
132                                                    99 
133 static int cpu_map_print(const char *str)         100 static int cpu_map_print(const char *str)
134 {                                                 101 {
135         struct perf_cpu_map *map = perf_cpu_ma    102         struct perf_cpu_map *map = perf_cpu_map__new(str);
136         char buf[100];                            103         char buf[100];
137                                                   104 
138         if (!map)                                 105         if (!map)
139                 return -1;                        106                 return -1;
140                                                   107 
141         cpu_map__snprint(map, buf, sizeof(buf)    108         cpu_map__snprint(map, buf, sizeof(buf));
142         perf_cpu_map__put(map);                << 
143                                                << 
144         return !strcmp(buf, str);                 109         return !strcmp(buf, str);
145 }                                                 110 }
146                                                   111 
147 static int test__cpu_map_print(struct test_sui !! 112 int test__cpu_map_print(struct test *test __maybe_unused, int subtest __maybe_unused)
148 {                                                 113 {
149         TEST_ASSERT_VAL("failed to convert map    114         TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1"));
150         TEST_ASSERT_VAL("failed to convert map    115         TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1,5"));
151         TEST_ASSERT_VAL("failed to convert map    116         TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1,3,5,7,9,11,13,15,17,19,21-40"));
152         TEST_ASSERT_VAL("failed to convert map    117         TEST_ASSERT_VAL("failed to convert map", cpu_map_print("2-5"));
153         TEST_ASSERT_VAL("failed to convert map    118         TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1,3-6,8-10,24,35-37"));
154         TEST_ASSERT_VAL("failed to convert map    119         TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1,3-6,8-10,24,35-37"));
155         TEST_ASSERT_VAL("failed to convert map    120         TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1-10,12-20,22-30,32-40"));
156         return 0;                                 121         return 0;
157 }                                                 122 }
158                                                   123 
159 static int test__cpu_map_merge(struct test_sui !! 124 int test__cpu_map_merge(struct test *test __maybe_unused, int subtest __maybe_unused)
160 {                                                 125 {
161         struct perf_cpu_map *a = perf_cpu_map_    126         struct perf_cpu_map *a = perf_cpu_map__new("4,2,1");
162         struct perf_cpu_map *b = perf_cpu_map_    127         struct perf_cpu_map *b = perf_cpu_map__new("4,5,7");
163         struct perf_cpu_map *c = perf_cpu_map_    128         struct perf_cpu_map *c = perf_cpu_map__merge(a, b);
164         char buf[100];                            129         char buf[100];
165                                                   130 
166         TEST_ASSERT_VAL("failed to merge map:  !! 131         TEST_ASSERT_VAL("failed to merge map: bad nr", c->nr == 5);
167         cpu_map__snprint(c, buf, sizeof(buf));    132         cpu_map__snprint(c, buf, sizeof(buf));
168         TEST_ASSERT_VAL("failed to merge map:     133         TEST_ASSERT_VAL("failed to merge map: bad result", !strcmp(buf, "1-2,4-5,7"));
169         perf_cpu_map__put(b);                     134         perf_cpu_map__put(b);
170         perf_cpu_map__put(c);                     135         perf_cpu_map__put(c);
171         return 0;                                 136         return 0;
172 }                                                 137 }
173                                                << 
174 static int __test__cpu_map_intersect(const cha << 
175 {                                              << 
176         struct perf_cpu_map *a = perf_cpu_map_ << 
177         struct perf_cpu_map *b = perf_cpu_map_ << 
178         struct perf_cpu_map *c = perf_cpu_map_ << 
179         char buf[100];                         << 
180                                                << 
181         TEST_ASSERT_EQUAL("failed to intersect << 
182         cpu_map__snprint(c, buf, sizeof(buf)); << 
183         TEST_ASSERT_VAL("failed to intersect m << 
184         perf_cpu_map__put(a);                  << 
185         perf_cpu_map__put(b);                  << 
186         perf_cpu_map__put(c);                  << 
187         return 0;                              << 
188 }                                              << 
189                                                << 
190 static int test__cpu_map_intersect(struct test << 
191                                    int subtest << 
192 {                                              << 
193         int ret;                               << 
194                                                << 
195         ret = __test__cpu_map_intersect("4,2,1 << 
196         if (ret)                               << 
197                 return ret;                    << 
198         ret = __test__cpu_map_intersect("1-8", << 
199         if (ret)                               << 
200                 return ret;                    << 
201         ret = __test__cpu_map_intersect("1-8,1 << 
202         if (ret)                               << 
203                 return ret;                    << 
204         ret = __test__cpu_map_intersect("4,2,1 << 
205         if (ret)                               << 
206                 return ret;                    << 
207         ret = __test__cpu_map_intersect("1", " << 
208         if (ret)                               << 
209                 return ret;                    << 
210         ret = __test__cpu_map_intersect("1", " << 
211         return ret;                            << 
212 }                                              << 
213                                                << 
214 static int test__cpu_map_equal(struct test_sui << 
215 {                                              << 
216         struct perf_cpu_map *any = perf_cpu_ma << 
217         struct perf_cpu_map *one = perf_cpu_ma << 
218         struct perf_cpu_map *two = perf_cpu_ma << 
219         struct perf_cpu_map *empty = perf_cpu_ << 
220         struct perf_cpu_map *pair = perf_cpu_m << 
221         struct perf_cpu_map *tmp;              << 
222         struct perf_cpu_map *maps[] = {empty,  << 
223                                                << 
224         for (size_t i = 0; i < ARRAY_SIZE(maps << 
225                 /* Maps equal themself. */     << 
226                 TEST_ASSERT_VAL("equal", perf_ << 
227                 for (size_t j = 0; j < ARRAY_S << 
228                         /* Maps dont't equal e << 
229                         if (i == j)            << 
230                                 continue;      << 
231                         TEST_ASSERT_VAL("not e << 
232                 }                              << 
233         }                                      << 
234                                                << 
235         /* Maps equal made maps. */            << 
236         tmp = perf_cpu_map__merge(perf_cpu_map << 
237         TEST_ASSERT_VAL("pair", perf_cpu_map__ << 
238         perf_cpu_map__put(tmp);                << 
239                                                << 
240         tmp = perf_cpu_map__intersect(pair, on << 
241         TEST_ASSERT_VAL("one", perf_cpu_map__e << 
242         perf_cpu_map__put(tmp);                << 
243                                                << 
244         for (size_t i = 0; i < ARRAY_SIZE(maps << 
245                 perf_cpu_map__put(maps[i]);    << 
246                                                << 
247         return TEST_OK;                        << 
248 }                                              << 
249                                                << 
250 static struct test_case tests__cpu_map[] = {   << 
251         TEST_CASE("Synthesize cpu map", cpu_ma << 
252         TEST_CASE("Print cpu map", cpu_map_pri << 
253         TEST_CASE("Merge cpu map", cpu_map_mer << 
254         TEST_CASE("Intersect cpu map", cpu_map << 
255         TEST_CASE("Equal cpu map", cpu_map_equ << 
256         {       .name = NULL, }                << 
257 };                                             << 
258                                                << 
259 struct test_suite suite__cpu_map = {           << 
260         .desc = "CPU map",                     << 
261         .test_cases = tests__cpu_map,          << 
262 };                                             << 
263                                                   138 

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