reference_tracking.c 921 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
// SPDX-License-Identifier: GPL-2.0
#include <test_progs.h>

void test_reference_tracking(void)
{
	const char *file = "./test_sk_lookup_kern.o";
	struct bpf_object *obj;
	struct bpf_program *prog;
	__u32 duration = 0;
	int err = 0;

	obj = bpf_object__open(file);
13
	if (CHECK_FAIL(IS_ERR(obj)))
14 15 16 17 18 19 20 21 22 23 24 25 26 27
		return;

	bpf_object__for_each_program(prog, obj) {
		const char *title;

		/* Ignore .text sections */
		title = bpf_program__title(prog, false);
		if (strstr(title, ".text") != NULL)
			continue;

		bpf_program__set_type(prog, BPF_PROG_TYPE_SCHED_CLS);

		/* Expect verifier failure if test name has 'fail' */
		if (strstr(title, "fail") != NULL) {
28 29 30
			libbpf_print_fn_t old_print_fn;

			old_print_fn = libbpf_set_print(NULL);
31
			err = !bpf_program__load(prog, "GPL", 0);
32
			libbpf_set_print(old_print_fn);
33 34 35 36 37 38 39
		} else {
			err = bpf_program__load(prog, "GPL", 0);
		}
		CHECK(err, title, "\n");
	}
	bpf_object__close(obj);
}