diff mbox series

[net-next,v3,06/13] selftests: Use separate stdout and stderr buffers in nettest

Message ID 20210113040040.50813-7-dsahern@kernel.org
State Superseded
Headers show
Series [net-next,v3,01/13] selftests: Move device validation in nettest | expand

Commit Message

David Ahern Jan. 13, 2021, 4 a.m. UTC
From: David Ahern <dsahern@gmail.com>

When a single instance of nettest is doing both client and
server modes, stdout and stderr messages can get interlaced
and become unreadable. Allocate a new set of buffers for the
child process handling server mode.

Signed-off-by: David Ahern <dsahern@gmail.com>
---
 tools/testing/selftests/net/nettest.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

Comments

David Ahern Jan. 14, 2021, 12:08 a.m. UTC | #1
On 1/13/21 4:56 PM, Jakub Kicinski wrote:
>> diff --git a/tools/testing/selftests/net/nettest.c b/tools/testing/selftests/net/nettest.c

>> index 685cbe8933de..9114bc823092 100644

>> --- a/tools/testing/selftests/net/nettest.c

>> +++ b/tools/testing/selftests/net/nettest.c

>> @@ -1707,9 +1707,27 @@ static char *random_msg(int len)

>>  

>>  static int ipc_child(int fd, struct sock_args *args)

>>  {

>> +	char *outbuf, *errbuf;

>> +	int rc;

>> +

>> +	outbuf = malloc(4096);

>> +	errbuf = malloc(4096);

>> +	if (!outbuf || !errbuf) {

>> +		fprintf(stderr, "server: Failed to allocate buffers for stdout and stderr\n");

>> +		return 1;

> 

> So this patch did not change? Did you send the wrong version,

> or am I missing something?

> 


yes, I did. Will send a v4 later.
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/nettest.c b/tools/testing/selftests/net/nettest.c
index 685cbe8933de..9114bc823092 100644
--- a/tools/testing/selftests/net/nettest.c
+++ b/tools/testing/selftests/net/nettest.c
@@ -1707,9 +1707,27 @@  static char *random_msg(int len)
 
 static int ipc_child(int fd, struct sock_args *args)
 {
+	char *outbuf, *errbuf;
+	int rc;
+
+	outbuf = malloc(4096);
+	errbuf = malloc(4096);
+	if (!outbuf || !errbuf) {
+		fprintf(stderr, "server: Failed to allocate buffers for stdout and stderr\n");
+		return 1;
+	}
+
+	setbuffer(stdout, outbuf, 4096);
+	setbuffer(stderr, errbuf, 4096);
+
 	server_mode = 1; /* to tell log_msg in case we are in both_mode */
 
-	return do_server(args, fd);
+	rc = do_server(args, fd);
+
+	free(outbuf);
+	free(errbuf);
+
+	return rc;
 }
 
 static int ipc_parent(int cpid, int fd, struct sock_args *args)