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

TOMOYO Linux Cross Reference
Linux/tools/perf/tests/maps.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 <inttypes.h>
  3 #include <linux/compiler.h>
  4 #include <linux/kernel.h>
  5 #include "tests.h"
  6 #include "map.h"
  7 #include "maps.h"
  8 #include "dso.h"
  9 #include "debug.h"
 10 
 11 struct map_def {
 12         const char *name;
 13         u64 start;
 14         u64 end;
 15 };
 16 
 17 struct check_maps_cb_args {
 18         struct map_def *merged;
 19         unsigned int i;
 20 };
 21 
 22 static int check_maps_cb(struct map *map, void *data)
 23 {
 24         struct check_maps_cb_args *args = data;
 25         struct map_def *merged = &args->merged[args->i];
 26 
 27         if (map__start(map) != merged->start ||
 28             map__end(map) != merged->end ||
 29             strcmp(dso__name(map__dso(map)), merged->name) ||
 30             refcount_read(map__refcnt(map)) != 1) {
 31                 return 1;
 32         }
 33         args->i++;
 34         return 0;
 35 }
 36 
 37 static int failed_cb(struct map *map, void *data __maybe_unused)
 38 {
 39         pr_debug("\tstart: %" PRIu64 " end: %" PRIu64 " name: '%s' refcnt: %d\n",
 40                 map__start(map),
 41                 map__end(map),
 42                 dso__name(map__dso(map)),
 43                 refcount_read(map__refcnt(map)));
 44 
 45         return 0;
 46 }
 47 
 48 static int check_maps(struct map_def *merged, unsigned int size, struct maps *maps)
 49 {
 50         bool failed = false;
 51 
 52         if (maps__nr_maps(maps) != size) {
 53                 pr_debug("Expected %d maps, got %d", size, maps__nr_maps(maps));
 54                 failed = true;
 55         } else {
 56                 struct check_maps_cb_args args = {
 57                         .merged = merged,
 58                         .i = 0,
 59                 };
 60                 failed = maps__for_each_map(maps, check_maps_cb, &args);
 61         }
 62         if (failed) {
 63                 pr_debug("Expected:\n");
 64                 for (unsigned int i = 0; i < size; i++) {
 65                         pr_debug("\tstart: %" PRIu64 " end: %" PRIu64 " name: '%s' refcnt: 1\n",
 66                                 merged[i].start, merged[i].end, merged[i].name);
 67                 }
 68                 pr_debug("Got:\n");
 69                 maps__for_each_map(maps, failed_cb, NULL);
 70         }
 71         return failed ? TEST_FAIL : TEST_OK;
 72 }
 73 
 74 static int test__maps__merge_in(struct test_suite *t __maybe_unused, int subtest __maybe_unused)
 75 {
 76         unsigned int i;
 77         struct map_def bpf_progs[] = {
 78                 { "bpf_prog_1", 200, 300 },
 79                 { "bpf_prog_2", 500, 600 },
 80                 { "bpf_prog_3", 800, 900 },
 81         };
 82         struct map_def merged12[] = {
 83                 { "kcore1",     100,  200 },
 84                 { "bpf_prog_1", 200,  300 },
 85                 { "kcore1",     300,  500 },
 86                 { "bpf_prog_2", 500,  600 },
 87                 { "kcore1",     600,  800 },
 88                 { "bpf_prog_3", 800,  900 },
 89                 { "kcore1",     900, 1000 },
 90         };
 91         struct map_def merged3[] = {
 92                 { "kcore1",      100,  200 },
 93                 { "bpf_prog_1",  200,  300 },
 94                 { "kcore1",      300,  500 },
 95                 { "bpf_prog_2",  500,  600 },
 96                 { "kcore1",      600,  800 },
 97                 { "bpf_prog_3",  800,  900 },
 98                 { "kcore1",      900, 1000 },
 99                 { "kcore3",     1000, 1100 },
100         };
101         struct map *map_kcore1, *map_kcore2, *map_kcore3;
102         int ret;
103         struct maps *maps = maps__new(NULL);
104 
105         TEST_ASSERT_VAL("failed to create maps", maps);
106 
107         for (i = 0; i < ARRAY_SIZE(bpf_progs); i++) {
108                 struct map *map;
109 
110                 map = dso__new_map(bpf_progs[i].name);
111                 TEST_ASSERT_VAL("failed to create map", map);
112 
113                 map__set_start(map, bpf_progs[i].start);
114                 map__set_end(map, bpf_progs[i].end);
115                 TEST_ASSERT_VAL("failed to insert map", maps__insert(maps, map) == 0);
116                 map__put(map);
117         }
118 
119         map_kcore1 = dso__new_map("kcore1");
120         TEST_ASSERT_VAL("failed to create map", map_kcore1);
121 
122         map_kcore2 = dso__new_map("kcore2");
123         TEST_ASSERT_VAL("failed to create map", map_kcore2);
124 
125         map_kcore3 = dso__new_map("kcore3");
126         TEST_ASSERT_VAL("failed to create map", map_kcore3);
127 
128         /* kcore1 map overlaps over all bpf maps */
129         map__set_start(map_kcore1, 100);
130         map__set_end(map_kcore1, 1000);
131 
132         /* kcore2 map hides behind bpf_prog_2 */
133         map__set_start(map_kcore2, 550);
134         map__set_end(map_kcore2, 570);
135 
136         /* kcore3 map hides behind bpf_prog_3, kcore1 and adds new map */
137         map__set_start(map_kcore3, 880);
138         map__set_end(map_kcore3, 1100);
139 
140         ret = maps__merge_in(maps, map_kcore1);
141         TEST_ASSERT_VAL("failed to merge map", !ret);
142 
143         ret = check_maps(merged12, ARRAY_SIZE(merged12), maps);
144         TEST_ASSERT_VAL("merge check failed", !ret);
145 
146         ret = maps__merge_in(maps, map_kcore2);
147         TEST_ASSERT_VAL("failed to merge map", !ret);
148 
149         ret = check_maps(merged12, ARRAY_SIZE(merged12), maps);
150         TEST_ASSERT_VAL("merge check failed", !ret);
151 
152         ret = maps__merge_in(maps, map_kcore3);
153         TEST_ASSERT_VAL("failed to merge map", !ret);
154 
155         ret = check_maps(merged3, ARRAY_SIZE(merged3), maps);
156         TEST_ASSERT_VAL("merge check failed", !ret);
157 
158         maps__zput(maps);
159         map__zput(map_kcore1);
160         map__zput(map_kcore2);
161         map__zput(map_kcore3);
162         return TEST_OK;
163 }
164 
165 DEFINE_SUITE("maps__merge_in", maps__merge_in);
166 

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