1 // SPDX-License-Identifier: GPL-2.0
2 #include <test_progs.h>
3 #include <network_helpers.h>
4 #include "test_xdp_noinline.skel.h"
6 void test_xdp_noinline(void)
8 unsigned int nr_cpus
= bpf_num_possible_cpus();
9 struct test_xdp_noinline
*skel
;
10 struct vip key
= {.protocol
= 6};
14 } value
= {.vip_num
= VIP_NUM
};
15 __u32 stats_key
= VIP_NUM
;
20 struct real_definition
{
26 } real_def
= {.dst
= MAGIC_VAL
};
27 __u32 ch_key
= 11, real_num
= 3;
28 __u32 duration
= 0, retval
, size
;
30 __u64 bytes
= 0, pkts
= 0;
32 u32
*magic
= (u32
*)buf
;
34 skel
= test_xdp_noinline__open_and_load();
35 if (CHECK(!skel
, "skel_open_and_load", "failed\n"))
38 bpf_map_update_elem(bpf_map__fd(skel
->maps
.vip_map
), &key
, &value
, 0);
39 bpf_map_update_elem(bpf_map__fd(skel
->maps
.ch_rings
), &ch_key
, &real_num
, 0);
40 bpf_map_update_elem(bpf_map__fd(skel
->maps
.reals
), &real_num
, &real_def
, 0);
42 err
= bpf_prog_test_run(bpf_program__fd(skel
->progs
.balancer_ingress_v4
),
43 NUM_ITER
, &pkt_v4
, sizeof(pkt_v4
),
44 buf
, &size
, &retval
, &duration
);
45 CHECK(err
|| retval
!= 1 || size
!= 54 ||
46 *magic
!= MAGIC_VAL
, "ipv4",
47 "err %d errno %d retval %d size %d magic %x\n",
48 err
, errno
, retval
, size
, *magic
);
50 err
= bpf_prog_test_run(bpf_program__fd(skel
->progs
.balancer_ingress_v6
),
51 NUM_ITER
, &pkt_v6
, sizeof(pkt_v6
),
52 buf
, &size
, &retval
, &duration
);
53 CHECK(err
|| retval
!= 1 || size
!= 74 ||
54 *magic
!= MAGIC_VAL
, "ipv6",
55 "err %d errno %d retval %d size %d magic %x\n",
56 err
, errno
, retval
, size
, *magic
);
58 bpf_map_lookup_elem(bpf_map__fd(skel
->maps
.stats
), &stats_key
, stats
);
59 for (i
= 0; i
< nr_cpus
; i
++) {
60 bytes
+= stats
[i
].bytes
;
61 pkts
+= stats
[i
].pkts
;
63 CHECK(bytes
!= MAGIC_BYTES
* NUM_ITER
* 2 || pkts
!= NUM_ITER
* 2,
64 "stats", "bytes %lld pkts %lld\n",
65 (unsigned long long)bytes
, (unsigned long long)pkts
);
66 test_xdp_noinline__destroy(skel
);