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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/pe_preserve_elems.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-only
  2 /* Copyright (c) 2019 Facebook */
  3 #include <test_progs.h>
  4 #include <linux/bpf.h>
  5 #include "test_pe_preserve_elems.skel.h"
  6 
  7 static int duration;
  8 
  9 static void test_one_map(struct bpf_map *map, struct bpf_program *prog,
 10                          bool has_share_pe)
 11 {
 12         int err, key = 0, pfd = -1, mfd = bpf_map__fd(map);
 13         DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts);
 14         struct perf_event_attr attr = {
 15                 .size = sizeof(struct perf_event_attr),
 16                 .type = PERF_TYPE_SOFTWARE,
 17                 .config = PERF_COUNT_SW_CPU_CLOCK,
 18         };
 19 
 20         pfd = syscall(__NR_perf_event_open, &attr, 0 /* pid */,
 21                       -1 /* cpu 0 */, -1 /* group id */, 0 /* flags */);
 22         if (CHECK(pfd < 0, "perf_event_open", "failed\n"))
 23                 return;
 24 
 25         err = bpf_map_update_elem(mfd, &key, &pfd, BPF_ANY);
 26         close(pfd);
 27         if (CHECK(err < 0, "bpf_map_update_elem", "failed\n"))
 28                 return;
 29 
 30         err = bpf_prog_test_run_opts(bpf_program__fd(prog), &opts);
 31         if (CHECK(err < 0, "bpf_prog_test_run_opts", "failed\n"))
 32                 return;
 33         if (CHECK(opts.retval != 0, "bpf_perf_event_read_value",
 34                   "failed with %d\n", opts.retval))
 35                 return;
 36 
 37         /* closing mfd, prog still holds a reference on map */
 38         close(mfd);
 39 
 40         err = bpf_prog_test_run_opts(bpf_program__fd(prog), &opts);
 41         if (CHECK(err < 0, "bpf_prog_test_run_opts", "failed\n"))
 42                 return;
 43 
 44         if (has_share_pe) {
 45                 CHECK(opts.retval != 0, "bpf_perf_event_read_value",
 46                       "failed with %d\n", opts.retval);
 47         } else {
 48                 CHECK(opts.retval != -ENOENT, "bpf_perf_event_read_value",
 49                       "should have failed with %d, but got %d\n", -ENOENT,
 50                       opts.retval);
 51         }
 52 }
 53 
 54 void test_pe_preserve_elems(void)
 55 {
 56         struct test_pe_preserve_elems *skel;
 57 
 58         skel = test_pe_preserve_elems__open_and_load();
 59         if (CHECK(!skel, "skel_open", "failed to open skeleton\n"))
 60                 return;
 61 
 62         test_one_map(skel->maps.array_1, skel->progs.read_array_1, false);
 63         test_one_map(skel->maps.array_2, skel->progs.read_array_2, true);
 64 
 65         test_pe_preserve_elems__destroy(skel);
 66 }
 67 

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