netdev.vger.kernel.org archive mirror
 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, bpf@vger.kernel.org, yhs@fb.com,
	andrii@kernel.org, martin.lau@linux.dev, song@kernel.org,
	john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com,
	haoluo@google.com, jolsa@kernel.org
Subject: [PATCH bpf-next 02/10] selftests/xsk: add timeout for Tx thread
Date: Wed,  9 Aug 2023 14:43:35 +0200	[thread overview]
Message-ID: <20230809124343.12957-3-magnus.karlsson@gmail.com> (raw)
In-Reply-To: <20230809124343.12957-1-magnus.karlsson@gmail.com>

From: Magnus Karlsson <magnus.karlsson@intel.com>

Add a timeout for the transmission thread. If packets are not
completed properly, for some reason, the test harness would previously
get stuck forever in a while loop. But with this patch, this timeout
will trigger, flag the test as a failure, and continue with the next
test.

Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
---
 tools/testing/selftests/bpf/xskxceiver.c | 26 ++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
index c595c0b65417..514fe994e02b 100644
--- a/tools/testing/selftests/bpf/xskxceiver.c
+++ b/tools/testing/selftests/bpf/xskxceiver.c
@@ -1216,10 +1216,29 @@ static int __send_pkts(struct ifobject *ifobject, struct pollfd *fds, bool timeo
 	return TEST_CONTINUE;
 }
 
-static void wait_for_tx_completion(struct xsk_socket_info *xsk)
+static int wait_for_tx_completion(struct xsk_socket_info *xsk)
 {
-	while (xsk->outstanding_tx)
+	struct timeval tv_end, tv_now, tv_timeout = {THREAD_TMOUT, 0};
+	int ret;
+
+	ret = gettimeofday(&tv_now, NULL);
+	if (ret)
+		exit_with_error(errno);
+	timeradd(&tv_now, &tv_timeout, &tv_end);
+
+	while (xsk->outstanding_tx) {
+		ret = gettimeofday(&tv_now, NULL);
+		if (ret)
+			exit_with_error(errno);
+		if (timercmp(&tv_now, &tv_end, >)) {
+			ksft_print_msg("ERROR: [%s] Transmission loop timed out\n", __func__);
+			return TEST_FAILURE;
+		}
+
 		complete_pkts(xsk, BATCH_SIZE);
+	}
+
+	return TEST_PASS;
 }
 
 static int send_pkts(struct test_spec *test, struct ifobject *ifobject)
@@ -1242,8 +1261,7 @@ static int send_pkts(struct test_spec *test, struct ifobject *ifobject)
 			return ret;
 	}
 
-	wait_for_tx_completion(ifobject->xsk);
-	return TEST_PASS;
+	return wait_for_tx_completion(ifobject->xsk);
 }
 
 static int get_xsk_stats(struct xsk_socket *xsk, struct xdp_statistics *stats)
-- 
2.34.1


  parent reply	other threads:[~2023-08-09 12:44 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-09 12:43 [PATCH bpf-next 00/10] seltests/xsk: various improvements to xskxceiver Magnus Karlsson
2023-08-09 12:43 ` [PATCH bpf-next 01/10] selftests/xsk: print per packet info in verbose mode Magnus Karlsson
2023-08-09 12:43 ` Magnus Karlsson [this message]
2023-08-09 12:43 ` [PATCH bpf-next 03/10] selftests/xsk: add option to only run tests in a single mode Magnus Karlsson
2023-08-10 12:14   ` Przemek Kitszel
2023-08-10 12:36     ` Magnus Karlsson
2023-08-09 12:43 ` [PATCH bpf-next 04/10] selftests/xsk: move all tests to separate functions Magnus Karlsson
2023-08-09 12:43 ` [PATCH bpf-next 05/10] selftests/xsk: declare test names in struct Magnus Karlsson
2023-08-10 12:15   ` Przemek Kitszel
2023-08-10 12:36     ` Magnus Karlsson
2023-08-22 12:28   ` Maciej Fijalkowski
2023-08-09 12:43 ` [PATCH bpf-next 06/10] selftests/xsk: add option that lists all tests Magnus Karlsson
2023-08-22 12:37   ` Maciej Fijalkowski
2023-08-22 13:52     ` Magnus Karlsson
2023-08-09 12:43 ` [PATCH bpf-next 07/10] selftests/xsk: add option to run single test Magnus Karlsson
2023-08-22 12:50   ` Maciej Fijalkowski
2023-08-09 12:43 ` [PATCH bpf-next 08/10] selftests/xsk: use ksft_print_msg uniformly Magnus Karlsson
2023-08-09 12:43 ` [PATCH bpf-next 09/10] selftests/xsk: fail single test instead of all tests Magnus Karlsson
2023-08-09 12:43 ` [PATCH bpf-next 10/10] selftests/xsk: display command line options with -h Magnus Karlsson
2023-08-10 12:19   ` Przemek Kitszel
2023-08-10 12:41     ` Magnus Karlsson
2023-08-22 13:02   ` Maciej Fijalkowski

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=20230809124343.12957-3-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=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=maciej.fijalkowski@intel.com \
    --cc=magnus.karlsson@intel.com \
    --cc=martin.lau@linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=yhs@fb.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).