Linux Audio

Check our new training course

Loading...
v5.4
 1// SPDX-License-Identifier: GPL-2.0
 2#include <test_progs.h>
 3
 4void test_reference_tracking(void)
 5{
 6	const char *file = "./test_sk_lookup_kern.o";
 
 
 
 
 
 7	struct bpf_object *obj;
 8	struct bpf_program *prog;
 9	__u32 duration = 0;
10	int err = 0;
11
12	obj = bpf_object__open(file);
13	if (CHECK_FAIL(IS_ERR(obj)))
14		return;
15
 
 
 
 
 
16	bpf_object__for_each_program(prog, obj) {
17		const char *title;
18
19		/* Ignore .text sections */
20		title = bpf_program__title(prog, false);
21		if (strstr(title, ".text") != NULL)
22			continue;
23
24		bpf_program__set_type(prog, BPF_PROG_TYPE_SCHED_CLS);
 
25
26		/* Expect verifier failure if test name has 'fail' */
27		if (strstr(title, "fail") != NULL) {
28			libbpf_print_fn_t old_print_fn;
29
30			old_print_fn = libbpf_set_print(NULL);
31			err = !bpf_program__load(prog, "GPL", 0);
32			libbpf_set_print(old_print_fn);
33		} else {
34			err = bpf_program__load(prog, "GPL", 0);
35		}
36		CHECK(err, title, "\n");
37	}
 
 
38	bpf_object__close(obj);
39}
v5.14.15
 1// SPDX-License-Identifier: GPL-2.0
 2#include <test_progs.h>
 3
 4void test_reference_tracking(void)
 5{
 6	const char *file = "test_sk_lookup_kern.o";
 7	const char *obj_name = "ref_track";
 8	DECLARE_LIBBPF_OPTS(bpf_object_open_opts, open_opts,
 9		.object_name = obj_name,
10		.relaxed_maps = true,
11	);
12	struct bpf_object *obj;
13	struct bpf_program *prog;
14	__u32 duration = 0;
15	int err = 0;
16
17	obj = bpf_object__open_file(file, &open_opts);
18	if (!ASSERT_OK_PTR(obj, "obj_open_file"))
19		return;
20
21	if (CHECK(strcmp(bpf_object__name(obj), obj_name), "obj_name",
22		  "wrong obj name '%s', expected '%s'\n",
23		  bpf_object__name(obj), obj_name))
24		goto cleanup;
25
26	bpf_object__for_each_program(prog, obj) {
27		const char *title;
28
29		/* Ignore .text sections */
30		title = bpf_program__section_name(prog);
31		if (strstr(title, ".text") != NULL)
32			continue;
33
34		if (!test__start_subtest(title))
35			continue;
36
37		/* Expect verifier failure if test name has 'fail' */
38		if (strstr(title, "fail") != NULL) {
39			libbpf_print_fn_t old_print_fn;
40
41			old_print_fn = libbpf_set_print(NULL);
42			err = !bpf_program__load(prog, "GPL", 0);
43			libbpf_set_print(old_print_fn);
44		} else {
45			err = bpf_program__load(prog, "GPL", 0);
46		}
47		CHECK(err, title, "\n");
48	}
49
50cleanup:
51	bpf_object__close(obj);
52}