xref: /linux/tools/testing/selftests/bpf/prog_tests/pinning_htab.c (revision accb9a7e87f096a12eb21256107b9c8e343f8019)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <test_progs.h>
4 #include "test_pinning_htab.skel.h"
5 
6 static void unpin_map(const char *map_name, const char *pin_path)
7 {
8 	struct test_pinning_htab *skel;
9 	struct bpf_map *map;
10 	int err;
11 
12 	skel = test_pinning_htab__open_and_load();
13 	if (!ASSERT_OK_PTR(skel, "skel open_and_load"))
14 		return;
15 
16 	map = bpf_object__find_map_by_name(skel->obj, map_name);
17 	if (!ASSERT_OK_PTR(map, "bpf_object__find_map_by_name"))
18 		goto out;
19 
20 	err = bpf_map__pin(map, pin_path);
21 	if (!ASSERT_OK(err, "bpf_map__pin"))
22 		goto out;
23 
24 	err = bpf_map__unpin(map, pin_path);
25 	ASSERT_OK(err, "bpf_map__unpin");
26 out:
27 	test_pinning_htab__destroy(skel);
28 }
29 
30 void test_pinning_htab(void)
31 {
32 	if (test__start_subtest("timer_prealloc"))
33 		unpin_map("timer_prealloc", "/sys/fs/bpf/timer_prealloc");
34 	if (test__start_subtest("timer_no_prealloc"))
35 		unpin_map("timer_no_prealloc", "/sys/fs/bpf/timer_no_prealloc");
36 }
37