All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Geliang Tang <geliang@kernel.org>
To: mptcp@lists.linux.dev
Cc: Geliang Tang <tanggeliang@kylinos.cn>
Subject: [PATCH mptcp-next v9 3/8] Squash to "selftests/bpf: Add bpf scheduler test" 2 time
Date: Wed, 17 Apr 2024 10:38:49 +0800	[thread overview]
Message-ID: <d67ba53775755dbaa7441ed6cab263b3250a6d49.1713321357.git.tanggeliang@kylinos.cn> (raw)
In-Reply-To: <cover.1713321357.git.tanggeliang@kylinos.cn>

From: Geliang Tang <tanggeliang@kylinos.cn>

Move time related code from send_data into send_data_and_verify. Then
send_data can be exported into network_helpers.h as a public function,
reused by mptcp.c and bpf_tcp_ca.c.

Drop duplicate '#include <time.h>', it's included in test_progs.h
already.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 23 +++++++++----------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index d7ce28fd7809..1979c685ee24 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -5,7 +5,6 @@
 #include <linux/const.h>
 #include <netinet/in.h>
 #include <test_progs.h>
-#include <time.h>
 #include "cgroup_helpers.h"
 #include "network_helpers.h"
 #include "mptcp_sock.skel.h"
@@ -382,16 +381,12 @@ static void *server(void *arg)
 static void send_data(int lfd, int fd, char *msg)
 {
 	ssize_t nr_recv = 0, bytes = 0;
-	struct timespec start, end;
-	unsigned int delta_ms;
 	pthread_t srv_thread;
 	void *thread_ret;
 	char batch[1500];
 	int err;
 
 	WRITE_ONCE(stop, 0);
-	if (clock_gettime(CLOCK_MONOTONIC, &start) < 0)
-		return;
 
 	err = pthread_create(&srv_thread, NULL, server, (void *)(long)lfd);
 	if (CHECK(err != 0, "pthread_create", "err:%d errno:%d\n", err, errno))
@@ -408,16 +403,9 @@ static void send_data(int lfd, int fd, char *msg)
 		bytes += nr_recv;
 	}
 
-	if (clock_gettime(CLOCK_MONOTONIC, &end) < 0)
-		return;
-
-	delta_ms = (end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000;
-
 	CHECK(bytes != total_bytes, "recv", "%zd != %u nr_recv:%zd errno:%d\n",
 	      bytes, total_bytes, nr_recv, errno);
 
-	printf("%s: %u ms\n", msg, delta_ms);
-
 	WRITE_ONCE(stop, 1);
 
 	pthread_join(srv_thread, &thread_ret);
@@ -461,7 +449,9 @@ static int has_bytes_sent(char *addr)
 
 static void send_data_and_verify(char *sched, bool addr1, bool addr2)
 {
+	struct timespec start, end;
 	int server_fd, client_fd;
+	unsigned int delta_ms;
 
 	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
 	if (CHECK(server_fd < 0, sched, "start_mptcp_server: %d\n", errno))
@@ -471,8 +461,17 @@ static void send_data_and_verify(char *sched, bool addr1, bool addr2)
 	if (CHECK(client_fd < 0, sched, "connect_to_fd: %d\n", errno))
 		goto fail;
 
+	if (clock_gettime(CLOCK_MONOTONIC, &start) < 0)
+		goto fail;
+
 	send_data(server_fd, client_fd, sched);
 
+	if (clock_gettime(CLOCK_MONOTONIC, &end) < 0)
+		goto fail;
+
+	delta_ms = (end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000;
+	printf("%s: %u ms\n", sched, delta_ms);
+
 	if (addr1)
 		CHECK(has_bytes_sent(ADDR_1), sched, "should have bytes_sent on addr1\n");
 	else
-- 
2.40.1


  parent reply	other threads:[~2024-04-17  2:39 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-17  2:38 [PATCH mptcp-next v9 0/8] refactor mptcp bpf tests Geliang Tang
2024-04-17  2:38 ` [PATCH mptcp-next v9 1/8] selftests/bpf: Add RUN_MPTCP_TEST macro Geliang Tang
2024-04-18 16:42   ` Mat Martineau
2024-04-17  2:38 ` [PATCH mptcp-next v9 2/8] Squash to "selftests/bpf: Add bpf scheduler test" 1 verify Geliang Tang
2024-04-17  2:38 ` Geliang Tang [this message]
2024-04-17  2:38 ` [PATCH mptcp-next v9 4/8] Squash to "selftests/bpf: Add bpf_first scheduler & test" Geliang Tang
2024-04-18  0:23   ` Mat Martineau
2024-04-17  2:38 ` [PATCH mptcp-next v9 5/8] Squash to "selftests/bpf: Add bpf_bkup " Geliang Tang
2024-04-17  2:38 ` [PATCH mptcp-next v9 6/8] Squash to "selftests/bpf: Add bpf_rr " Geliang Tang
2024-04-17  2:38 ` [PATCH mptcp-next v9 7/8] Squash to "selftests/bpf: Add bpf_red " Geliang Tang
2024-04-17  2:38 ` [PATCH mptcp-next v9 8/8] Squash to "selftests/bpf: Add bpf_burst " Geliang Tang
2024-04-17  3:25 ` [PATCH mptcp-next v9 0/8] refactor mptcp bpf tests MPTCP CI
2024-04-19  9:58 ` Matthieu Baerts
2024-04-20  0:18   ` Geliang Tang
2024-04-20  9:12     ` Matthieu Baerts
2024-04-22  7:05       ` Geliang Tang

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=d67ba53775755dbaa7441ed6cab263b3250a6d49.1713321357.git.tanggeliang@kylinos.cn \
    --to=geliang@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=tanggeliang@kylinos.cn \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.