Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Magnus Karlsson <magnus.karlsson@gmail.com>
To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org,
	daniel@iogearbox.net, netdev@vger.kernel.org,
	maciej.fijalkowski@intel.com
Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com,
	joamaki@gmail.com, bpf@vger.kernel.org, yhs@fb.com,
	andrii@kernel.org
Subject: [PATCH bpf-next 07/17] selftests: xsk: remove end-of-test packet
Date: Tue, 27 Jul 2021 15:17:43 +0200	[thread overview]
Message-ID: <20210727131753.10924-8-magnus.karlsson@gmail.com> (raw)
In-Reply-To: <20210727131753.10924-1-magnus.karlsson@gmail.com>

From: Magnus Karlsson <magnus.karlsson@intel.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@intel.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


  parent reply	other threads:[~2021-07-27 13:18 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-27 13:17 [PATCH bpf-next 00/17] selftests: xsk: various simplifications Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 01/17] selftests: xsk: remove color mode Magnus Karlsson
2021-07-27 16:43   ` Yonghong Song
2021-07-28  6:12     ` Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 02/17] selftests: xsk: remove the num_tx_packets option Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 03/17] selftests: xsk: remove unused variables Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 04/17] selftests: xsk: set rlimit per thread Magnus Karlsson
2021-07-27 18:39   ` Yonghong Song
2021-07-28  6:13     ` Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 05/17] selftests: xsk: return correct error codes Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 06/17] selftests: xsk: simplify the retry code Magnus Karlsson
2021-07-27 13:17 ` Magnus Karlsson [this message]
2021-07-27 13:17 ` [PATCH bpf-next 08/17] selftests: xsk: disassociate umem size with packets sent Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 09/17] selftests: xsk: rename worker_* functions that are not thred entry points Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 10/17] selftests: xsk: simplify packet validation in xsk tests Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 11/17] selftests: xsk: validate tx stats on tx thread Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 12/17] selftests: xsk: decrease batch size Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 13/17] selftests: xsk: remove cleanup at end of program Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 14/17] selftests: xsk: generate packet directly in umem Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 15/17] selftests: xsk: generate packets from specification Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 16/17] selftests: xsk: make enums lower case Magnus Karlsson
2021-07-27 13:17 ` [PATCH bpf-next 17/17] selftests: xsk: preface options with opt Magnus Karlsson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210727131753.10924-8-magnus.karlsson@gmail.com \
    --to=magnus.karlsson@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bjorn@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=ciara.loftus@intel.com \
    --cc=daniel@iogearbox.net \
    --cc=joamaki@gmail.com \
    --cc=jonathan.lemon@gmail.com \
    --cc=maciej.fijalkowski@intel.com \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=yhs@fb.com \
    --subject='Re: [PATCH bpf-next 07/17] selftests: xsk: remove end-of-test packet' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).