1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2020 Facebook
3 
4 #include <test_progs.h>
5 #include <network_helpers.h>
6 
7 #include "map_ptr_kern.skel.h"
8 
9 void test_map_ptr(void)
10 {
11 	struct map_ptr_kern *skel;
12 	__u32 duration = 0, retval;
13 	char buf[128];
14 	int err;
15 	int page_size = getpagesize();
16 
17 	skel = map_ptr_kern__open();
18 	if (!ASSERT_OK_PTR(skel, "skel_open"))
19 		return;
20 
21 	err = bpf_map__set_max_entries(skel->maps.m_ringbuf, page_size);
22 	if (!ASSERT_OK(err, "bpf_map__set_max_entries"))
23 		goto cleanup;
24 
25 	err = map_ptr_kern__load(skel);
26 	if (!ASSERT_OK(err, "skel_load"))
27 		goto cleanup;
28 
29 	skel->bss->page_size = page_size;
30 
31 	err = bpf_prog_test_run(bpf_program__fd(skel->progs.cg_skb), 1, &pkt_v4,
32 				sizeof(pkt_v4), buf, NULL, &retval, NULL);
33 
34 	if (CHECK(err, "test_run", "err=%d errno=%d\n", err, errno))
35 		goto cleanup;
36 
37 	if (CHECK(!retval, "retval", "retval=%d map_type=%u line=%u\n", retval,
38 		  skel->bss->g_map_type, skel->bss->g_line))
39 		goto cleanup;
40 
41 cleanup:
42 	map_ptr_kern__destroy(skel);
43 }
44