reference_tracking.c 1.2 KB
Newer Older
1 2 3 4 5
// SPDX-License-Identifier: GPL-2.0
#include <test_progs.h>

void test_reference_tracking(void)
{
6 7
	const char *file = "test_sk_lookup_kern.o";
	const char *obj_name = "ref_track";
8
	DECLARE_LIBBPF_OPTS(bpf_object_open_opts, open_opts,
9 10 11
		.object_name = obj_name,
		.relaxed_maps = true,
	);
12 13 14 15 16
	struct bpf_object *obj;
	struct bpf_program *prog;
	__u32 duration = 0;
	int err = 0;

17
	obj = bpf_object__open_file(file, &open_opts);
18
	if (CHECK_FAIL(IS_ERR(obj)))
19 20
		return;

21 22 23 24 25
	if (CHECK(strcmp(bpf_object__name(obj), obj_name), "obj_name",
		  "wrong obj name '%s', expected '%s'\n",
		  bpf_object__name(obj), obj_name))
		goto cleanup;

26 27 28 29
	bpf_object__for_each_program(prog, obj) {
		const char *title;

		/* Ignore .text sections */
30
		title = bpf_program__section_name(prog);
31 32 33
		if (strstr(title, ".text") != NULL)
			continue;

34 35
		if (!test__start_subtest(title))
			continue;
36 37 38

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

			old_print_fn = libbpf_set_print(NULL);
42
			err = !bpf_program__load(prog, "GPL", 0);
43
			libbpf_set_print(old_print_fn);
44 45 46 47 48
		} else {
			err = bpf_program__load(prog, "GPL", 0);
		}
		CHECK(err, title, "\n");
	}
49 50

cleanup:
51 52
	bpf_object__close(obj);
}