[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210727131753.10924-8-magnus.karlsson@gmail.com>
Date: Tue, 27 Jul 2021 15:17:43 +0200
From: Magnus Karlsson <magnus.karlsson@...il.com>
To: magnus.karlsson@...el.com, bjorn@...nel.org, ast@...nel.org,
daniel@...earbox.net, netdev@...r.kernel.org,
maciej.fijalkowski@...el.com
Cc: jonathan.lemon@...il.com, ciara.loftus@...el.com,
joamaki@...il.com, bpf@...r.kernel.org, yhs@...com,
andrii@...nel.org
Subject: [PATCH bpf-next 07/17] selftests: xsk: remove end-of-test packet
From: Magnus Karlsson <magnus.karlsson@...el.com>
Get rid of the end-of-test packet and just count the number of packets
received and quit when the expected number as been
received. Simplifies the code.
Signed-off-by: Magnus Karlsson <magnus.karlsson@...el.com>
---
tools/testing/selftests/bpf/xdpxceiver.c | 42 +++++++-----------------
tools/testing/selftests/bpf/xdpxceiver.h | 2 --
2 files changed, 12 insertions(+), 32 deletions(-)
diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c
index dcde73db7b29..b77ee9bb91e1 100644
--- a/tools/testing/selftests/bpf/xdpxceiver.c
+++ b/tools/testing/selftests/bpf/xdpxceiver.c
@@ -605,7 +605,7 @@ static void worker_pkt_dump(void)
void *ptr;
fprintf(stdout, "---------------------------------------\n");
- for (int iter = 0; iter < num_frames - 1; iter++) {
+ for (int iter = 0; iter < num_frames; iter++) {
ptr = pkt_buf[iter]->payload;
ethhdr = ptr;
iphdr = ptr + sizeof(*ethhdr);
@@ -632,11 +632,6 @@ static void worker_pkt_dump(void)
/*extract L5 frame */
payload = *((uint32_t *)(ptr + PKT_HDR_SIZE));
- if (payload == EOT) {
- print_verbose("End-of-transmission frame received\n");
- fprintf(stdout, "---------------------------------------\n");
- break;
- }
fprintf(stdout, "DEBUG>> L5: payload: %d\n", payload);
fprintf(stdout, "---------------------------------------\n");
}
@@ -699,28 +694,24 @@ static void worker_pkt_validate(void)
/*do not increment pktcounter if !(tos=0x9 and ipv4) */
if (iphdr->version == IP_PKT_VER && iphdr->tos == IP_PKT_TOS) {
payloadseqnum = *((uint32_t *)(pkt_node_rx_q->pkt_frame + PKT_HDR_SIZE));
- if (debug_pkt_dump && payloadseqnum != EOT) {
+ if (debug_pkt_dump) {
pkt_obj = malloc(sizeof(*pkt_obj));
pkt_obj->payload = malloc(PKT_SIZE);
memcpy(pkt_obj->payload, pkt_node_rx_q->pkt_frame, PKT_SIZE);
pkt_buf[payloadseqnum] = pkt_obj;
}
- if (payloadseqnum == EOT) {
- print_verbose("End-of-transmission frame received: PASS\n");
- sigvar = 1;
- break;
- }
-
- if (prev_pkt + 1 != payloadseqnum) {
+ if (pkt_counter % num_frames != payloadseqnum) {
ksft_test_result_fail
- ("ERROR: [%s] prev_pkt [%d], payloadseqnum [%d]\n",
- __func__, prev_pkt, payloadseqnum);
+ ("ERROR: [%s] expected counter [%d], payloadseqnum [%d]\n",
+ __func__, pkt_counter, payloadseqnum);
ksft_exit_xfail();
}
- prev_pkt = payloadseqnum;
- pkt_counter++;
+ if (++pkt_counter == opt_pkt_count) {
+ sigvar = 1;
+ break;
+ }
} else {
ksft_print_msg("Invalid frame received: ");
ksft_print_msg("[IP_PKT_VER: %02X], [IP_PKT_TOS: %02X]\n", iphdr->version,
@@ -805,11 +796,7 @@ static void *worker_testapp_validate_tx(void *arg)
thread_common_ops(ifobject, bufs);
for (int i = 0; i < num_frames; i++) {
- /*send EOT frame */
- if (i == (num_frames - 1))
- data.seqnum = -1;
- else
- data.seqnum = i;
+ data.seqnum = i;
gen_udp_hdr(&data, ifobject, udp_hdr);
gen_ip_hdr(ifobject, ip_hdr);
gen_udp_csum(udp_hdr, ip_hdr);
@@ -817,8 +804,7 @@ static void *worker_testapp_validate_tx(void *arg)
gen_eth_frame(ifobject->umem, i * XSK_UMEM__DEFAULT_FRAME_SIZE);
}
- print_verbose("Sending %d packets on interface %s\n",
- (opt_pkt_count - 1), ifobject->ifname);
+ print_verbose("Sending %d packets on interface %s\n", opt_pkt_count, ifobject->ifname);
tx_only_all(ifobject);
testapp_cleanup_xsk_res(ifobject);
@@ -893,7 +879,7 @@ static void testapp_validate(void)
if (debug_pkt_dump && test_type != TEST_TYPE_STATS) {
worker_pkt_dump();
- for (int iter = 0; iter < num_frames - 1; iter++) {
+ for (int iter = 0; iter < num_frames; iter++) {
free(pkt_buf[iter]->payload);
free(pkt_buf[iter]);
}
@@ -910,7 +896,6 @@ static void testapp_teardown(void)
for (i = 0; i < MAX_TEARDOWN_ITER; i++) {
pkt_counter = 0;
- prev_pkt = -1;
sigvar = 0;
print_verbose("Creating socket\n");
testapp_validate();
@@ -938,7 +923,6 @@ static void testapp_bidi(void)
{
for (int i = 0; i < MAX_BIDI_ITER; i++) {
pkt_counter = 0;
- prev_pkt = -1;
sigvar = 0;
print_verbose("Creating socket\n");
testapp_validate();
@@ -972,7 +956,6 @@ static void testapp_bpf_res(void)
for (i = 0; i < MAX_BPF_ITER; i++) {
pkt_counter = 0;
- prev_pkt = -1;
sigvar = 0;
print_verbose("Creating socket\n");
testapp_validate();
@@ -1048,7 +1031,6 @@ static void run_pkt_test(int mode, int type)
xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST;
pkt_counter = 0;
second_step = 0;
- prev_pkt = -1;
sigvar = 0;
stat_test_type = -1;
rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS;
diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h
index 1c94230c351a..a4371d9e2798 100644
--- a/tools/testing/selftests/bpf/xdpxceiver.h
+++ b/tools/testing/selftests/bpf/xdpxceiver.h
@@ -34,7 +34,6 @@
#define IP_PKT_TOS 0x9
#define UDP_PKT_SIZE (IP_PKT_SIZE - sizeof(struct iphdr))
#define UDP_PKT_DATA_SIZE (UDP_PKT_SIZE - sizeof(struct udphdr))
-#define EOT (-1)
#define USLEEP_MAX 10000
#define SOCK_RECONF_CTR 10
#define BATCH_SIZE 64
@@ -82,7 +81,6 @@ static u32 xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST;
static u32 xdp_bind_flags = XDP_USE_NEED_WAKEUP | XDP_COPY;
static u8 pkt_data[XSK_UMEM__DEFAULT_FRAME_SIZE];
static u32 pkt_counter;
-static long prev_pkt = -1;
static int sigvar;
static int stat_test_type;
static u32 rxqsize;
--
2.29.0
Powered by blists - more mailing lists