1 // SPDX-License-Identifier: GPL-2.0
2 #include <test_progs.h>
4 void test_xdp_noinline(void)
6 const char *file
= "./test_xdp_noinline.o";
7 unsigned int nr_cpus
= bpf_num_possible_cpus();
8 struct vip key
= {.protocol
= 6};
12 } value
= {.vip_num
= VIP_NUM
};
13 __u32 stats_key
= VIP_NUM
;
18 struct real_definition
{
24 } real_def
= {.dst
= MAGIC_VAL
};
25 __u32 ch_key
= 11, real_num
= 3;
26 __u32 duration
, retval
, size
;
27 int err
, i
, prog_fd
, map_fd
;
28 __u64 bytes
= 0, pkts
= 0;
29 struct bpf_object
*obj
;
31 u32
*magic
= (u32
*)buf
;
33 err
= bpf_prog_load(file
, BPF_PROG_TYPE_XDP
, &obj
, &prog_fd
);
39 map_fd
= bpf_find_map(__func__
, obj
, "vip_map");
42 bpf_map_update_elem(map_fd
, &key
, &value
, 0);
44 map_fd
= bpf_find_map(__func__
, obj
, "ch_rings");
47 bpf_map_update_elem(map_fd
, &ch_key
, &real_num
, 0);
49 map_fd
= bpf_find_map(__func__
, obj
, "reals");
52 bpf_map_update_elem(map_fd
, &real_num
, &real_def
, 0);
54 err
= bpf_prog_test_run(prog_fd
, NUM_ITER
, &pkt_v4
, sizeof(pkt_v4
),
55 buf
, &size
, &retval
, &duration
);
56 CHECK(err
|| retval
!= 1 || size
!= 54 ||
57 *magic
!= MAGIC_VAL
, "ipv4",
58 "err %d errno %d retval %d size %d magic %x\n",
59 err
, errno
, retval
, size
, *magic
);
61 err
= bpf_prog_test_run(prog_fd
, NUM_ITER
, &pkt_v6
, sizeof(pkt_v6
),
62 buf
, &size
, &retval
, &duration
);
63 CHECK(err
|| retval
!= 1 || size
!= 74 ||
64 *magic
!= MAGIC_VAL
, "ipv6",
65 "err %d errno %d retval %d size %d magic %x\n",
66 err
, errno
, retval
, size
, *magic
);
68 map_fd
= bpf_find_map(__func__
, obj
, "stats");
71 bpf_map_lookup_elem(map_fd
, &stats_key
, stats
);
72 for (i
= 0; i
< nr_cpus
; i
++) {
73 bytes
+= stats
[i
].bytes
;
74 pkts
+= stats
[i
].pkts
;
76 if (bytes
!= MAGIC_BYTES
* NUM_ITER
* 2 || pkts
!= NUM_ITER
* 2) {
78 printf("test_xdp_noinline:FAIL:stats %lld %lld\n", bytes
, pkts
);
81 bpf_object__close(obj
);