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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ 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 <test_progs.h>
  3 #include "test_stacktrace_build_id.skel.h"
  4 
  5 void test_stacktrace_build_id(void)
  6 {
  7 
  8         int control_map_fd, stackid_hmap_fd, stackmap_fd, stack_amap_fd;
  9         struct test_stacktrace_build_id *skel;
 10         int err, stack_trace_len, build_id_size;
 11         __u32 key, prev_key, val, duration = 0;
 12         char buf[BPF_BUILD_ID_SIZE];
 13         struct bpf_stack_build_id id_offs[PERF_MAX_STACK_DEPTH];
 14         int build_id_matches = 0;
 15         int i, retry = 1;
 16 
 17 retry:
 18         skel = test_stacktrace_build_id__open_and_load();
 19         if (CHECK(!skel, "skel_open_and_load", "skeleton open/load failed\n"))
 20                 return;
 21 
 22         err = test_stacktrace_build_id__attach(skel);
 23         if (CHECK(err, "attach_tp", "err %d\n", err))
 24                 goto cleanup;
 25 
 26         /* find map fds */
 27         control_map_fd = bpf_map__fd(skel->maps.control_map);
 28         stackid_hmap_fd = bpf_map__fd(skel->maps.stackid_hmap);
 29         stackmap_fd = bpf_map__fd(skel->maps.stackmap);
 30         stack_amap_fd = bpf_map__fd(skel->maps.stack_amap);
 31 
 32         if (CHECK_FAIL(system("dd if=/dev/urandom of=/dev/zero count=4 2> /dev/null")))
 33                 goto cleanup;
 34         if (CHECK_FAIL(system("./urandom_read")))
 35                 goto cleanup;
 36         /* disable stack trace collection */
 37         key = 0;
 38         val = 1;
 39         bpf_map_update_elem(control_map_fd, &key, &val, 0);
 40 
 41         /* for every element in stackid_hmap, we can find a corresponding one
 42          * in stackmap, and vise versa.
 43          */
 44         err = compare_map_keys(stackid_hmap_fd, stackmap_fd);
 45         if (CHECK(err, "compare_map_keys stackid_hmap vs. stackmap",
 46                   "err %d errno %d\n", err, errno))
 47                 goto cleanup;
 48 
 49         err = compare_map_keys(stackmap_fd, stackid_hmap_fd);
 50         if (CHECK(err, "compare_map_keys stackmap vs. stackid_hmap",
 51                   "err %d errno %d\n", err, errno))
 52                 goto cleanup;
 53 
 54         build_id_size = read_build_id("urandom_read", buf, sizeof(buf));
 55         err = build_id_size < 0 ? build_id_size : 0;
 56 
 57         if (CHECK(err, "read_build_id",
 58                   "err %d errno %d\n", err, errno))
 59                 goto cleanup;
 60 
 61         err = bpf_map__get_next_key(skel->maps.stackmap, NULL, &key, sizeof(key));
 62         if (CHECK(err, "get_next_key from stackmap",
 63                   "err %d, errno %d\n", err, errno))
 64                 goto cleanup;
 65 
 66         do {
 67                 err = bpf_map_lookup_elem(stackmap_fd, &key, id_offs);
 68                 if (CHECK(err, "lookup_elem from stackmap",
 69                           "err %d, errno %d\n", err, errno))
 70                         goto cleanup;
 71                 for (i = 0; i < PERF_MAX_STACK_DEPTH; ++i)
 72                         if (id_offs[i].status == BPF_STACK_BUILD_ID_VALID &&
 73                             id_offs[i].offset != 0) {
 74                                 if (memcmp(buf, id_offs[i].build_id, build_id_size) == 0)
 75                                         build_id_matches = 1;
 76                         }
 77                 prev_key = key;
 78         } while (bpf_map__get_next_key(skel->maps.stackmap, &prev_key, &key, sizeof(key)) == 0);
 79 
 80         /* stack_map_get_build_id_offset() is racy and sometimes can return
 81          * BPF_STACK_BUILD_ID_IP instead of BPF_STACK_BUILD_ID_VALID;
 82          * try it one more time.
 83          */
 84         if (build_id_matches < 1 && retry--) {
 85                 test_stacktrace_build_id__destroy(skel);
 86                 printf("%s:WARN:Didn't find expected build ID from the map, retrying\n",
 87                        __func__);
 88                 goto retry;
 89         }
 90 
 91         if (CHECK(build_id_matches < 1, "build id match",
 92                   "Didn't find expected build ID from the map\n"))
 93                 goto cleanup;
 94 
 95         stack_trace_len = PERF_MAX_STACK_DEPTH *
 96                           sizeof(struct bpf_stack_build_id);
 97         err = compare_stack_ips(stackmap_fd, stack_amap_fd, stack_trace_len);
 98         CHECK(err, "compare_stack_ips stackmap vs. stack_amap",
 99               "err %d errno %d\n", err, errno);
100 
101 cleanup:
102         test_stacktrace_build_id__destroy(skel);
103 }
104 

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