1 // SPDX-License-Identifier: GPL-2.0
2 #include <test_progs.h>
10 struct rdonly_map_subtest {
11 const char *subtest_name;
12 const char *prog_name;
17 void test_rdonly_maps(void)
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 },
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;
32 obj = bpf_object__open_file(file, NULL);
33 if (!ASSERT_OK_PTR(obj, "obj_open"))
36 err = bpf_object__load(obj);
37 if (CHECK(err, "obj_load", "err %d errno %d\n", err, errno))
40 bss_map = bpf_object__find_map_by_name(obj, ".bss");
41 if (CHECK(!bss_map, "find_bss_map", "failed\n"))
44 for (i = 0; i < ARRAY_SIZE(subtests); i++) {
45 const struct rdonly_map_subtest *t = &subtests[i];
47 if (!test__start_subtest(t->subtest_name))
50 prog = bpf_object__find_program_by_name(obj, t->prog_name);
51 if (CHECK(!prog, "find_prog", "prog '%s' not found\n",
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))
60 link = bpf_program__attach_raw_tracepoint(prog, "sys_enter");
61 if (!ASSERT_OK_PTR(link, "attach_prog"))
67 bpf_link__destroy(link);
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))
73 if (CHECK(bss.did_run == 0, "check_run",
74 "prog '%s' didn't run?\n", t->prog_name))
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))
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))
87 bpf_link__destroy(link);
88 bpf_object__close(obj);