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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/rdonly_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 <test_progs.h>
  3 
  4 struct bss {
  5         unsigned did_run;
  6         unsigned iters;
  7         unsigned sum;
  8 };
  9 
 10 struct rdonly_map_subtest {
 11         const char *subtest_name;
 12         const char *prog_name;
 13         unsigned exp_iters;
 14         unsigned exp_sum;
 15 };
 16 
 17 void test_rdonly_maps(void)
 18 {
 19         const char *file = "test_rdonly_maps.bpf.o";
 20         struct rdonly_map_subtest subtests[] = {
 21                 { "skip loop", "skip_loop", 0, 0 },
 22                 { "part loop", "part_loop", 3, 2 + 3 + 4 },
 23                 { "full loop", "full_loop", 4, 2 + 3 + 4 + 5 },
 24         };
 25         int i, err, zero = 0, duration = 0;
 26         struct bpf_link *link = NULL;
 27         struct bpf_program *prog;
 28         struct bpf_map *bss_map;
 29         struct bpf_object *obj;
 30         struct bss bss;
 31 
 32         obj = bpf_object__open_file(file, NULL);
 33         if (!ASSERT_OK_PTR(obj, "obj_open"))
 34                 return;
 35 
 36         err = bpf_object__load(obj);
 37         if (CHECK(err, "obj_load", "err %d errno %d\n", err, errno))
 38                 goto cleanup;
 39 
 40         bss_map = bpf_object__find_map_by_name(obj, ".bss");
 41         if (CHECK(!bss_map, "find_bss_map", "failed\n"))
 42                 goto cleanup;
 43 
 44         for (i = 0; i < ARRAY_SIZE(subtests); i++) {
 45                 const struct rdonly_map_subtest *t = &subtests[i];
 46 
 47                 if (!test__start_subtest(t->subtest_name))
 48                         continue;
 49 
 50                 prog = bpf_object__find_program_by_name(obj, t->prog_name);
 51                 if (CHECK(!prog, "find_prog", "prog '%s' not found\n",
 52                           t->prog_name))
 53                         goto cleanup;
 54 
 55                 memset(&bss, 0, sizeof(bss));
 56                 err = bpf_map_update_elem(bpf_map__fd(bss_map), &zero, &bss, 0);
 57                 if (CHECK(err, "set_bss", "failed to set bss data: %d\n", err))
 58                         goto cleanup;
 59 
 60                 link = bpf_program__attach_raw_tracepoint(prog, "sys_enter");
 61                 if (!ASSERT_OK_PTR(link, "attach_prog"))
 62                         goto cleanup;
 63 
 64                 /* trigger probe */
 65                 usleep(1);
 66 
 67                 bpf_link__destroy(link);
 68                 link = NULL;
 69 
 70                 err = bpf_map_lookup_elem(bpf_map__fd(bss_map), &zero, &bss);
 71                 if (CHECK(err, "get_bss", "failed to get bss data: %d\n", err))
 72                         goto cleanup;
 73                 if (CHECK(bss.did_run == 0, "check_run",
 74                           "prog '%s' didn't run?\n", t->prog_name))
 75                         goto cleanup;
 76                 if (CHECK(bss.iters != t->exp_iters, "check_iters",
 77                           "prog '%s' iters: %d, expected: %d\n",
 78                           t->prog_name, bss.iters, t->exp_iters))
 79                         goto cleanup;
 80                 if (CHECK(bss.sum != t->exp_sum, "check_sum",
 81                           "prog '%s' sum: %d, expected: %d\n",
 82                           t->prog_name, bss.sum, t->exp_sum))
 83                         goto cleanup;
 84         }
 85 
 86 cleanup:
 87         bpf_link__destroy(link);
 88         bpf_object__close(obj);
 89 }
 90 

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