public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top
Subject: [PATCH v2 3/3] test: Simpler termination handling for UDP tests
Date: Tue, 13 Sep 2022 16:37:45 +1000	[thread overview]
Message-ID: <20220913063745.3657546-4-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20220913063745.3657546-1-david@gibson.dropbear.id.au>

[-- Attachment #1: Type: text/plain, Size: 16113 bytes --]

Because UDP is connectionless we don't have an in-built end-of-stream
signal for our connectivity tests.  We work around this by explicitly
adding an end marker to our sample data and killing the listening end once
it is seen.

However, socat has some built-in options - null-eof and shut-null - which
can be used to signal the end of stream with a zero-length UDP packet.
Use these to simplify how the UDP tests are implemented.

Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au>
---
 test/passt/udp       | 23 +++++++-------
 test/passt_in_ns/udp | 73 ++++++++++++++++++++++----------------------
 test/pasta/udp       | 31 +++++++++----------
 3 files changed, 62 insertions(+), 65 deletions(-)

diff --git a/test/passt/udp b/test/passt/udp
index 0253a86..7d444b8 100644
--- a/test/passt/udp
+++ b/test/passt/udp
@@ -11,42 +11,41 @@
 # Copyright (c) 2021 Red Hat GmbH
 # Author: Stefano Brivio <sbrivio(a)redhat.com>
 
-gtools	socat tee grep cat ip jq md5sum cut
-htools	printf dd socat tee grep cat ip jq md5sum cut
+gtools	socat ip jq md5sum cut
+htools	dd socat jq md5sum cut
 
 test	UDP/IPv4: host to guest
 set	TEMP __STATEDIR__/data
-set	SC_PID __STATEDIR__/socat.pid
-guestb	(socat -u UDP4-LISTEN:10001 STDOUT & echo $! > sc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat sc.pid))
+guestb	socat -u UDP4-LISTEN:10001,null-eof OPEN:test.bin,create,trunc
 sleep	1
-host	dd if=/dev/urandom bs=1k count=5 > __TEMP__ && printf "\nEND_OF_TEST\n" >> __TEMP__
-host	socat -u OPEN:__TEMP__ UDP4:127.0.0.1:10001
+host	dd if=/dev/urandom bs=1k count=5 > __TEMP__
+host	socat -u OPEN:__TEMP__ UDP4:127.0.0.1:10001,shut-null
 guestw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 gout	GUEST_MD5 md5sum test.bin | cut -d' ' -f1
 check	[ "__GUEST_MD5__" = "__HOST_MD5__" ]
 
 test	UDP/IPv4: guest to host
-hostb	(socat -u UDP4-LISTEN:10003,bind=127.0.0.1 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
+hostb	socat -u UDP4-LISTEN:10003,bind=127.0.0.1,null-eof OPEN:__TEMP__,create,trunc
 gout	GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway'
-guest	socat -u OPEN:test.bin UDP4:__GW__:10003
+guest	socat -u OPEN:test.bin UDP4:__GW__:10003,shut-null
 hostw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 check	[ "__GUEST_MD5__" = "__HOST_MD5__" ]
 
 test	UDP/IPv6: host to guest
-guestb	(socat -u UDP6-LISTEN:10001 STDOUT & echo $! > sc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat sc.pid))
+guestb	socat -u UDP6-LISTEN:10001,null-eof OPEN:test.bin,create,trunc
 sleep	1
-host	socat -u OPEN:__TEMP__ UDP6:[::1]:10001
+host	socat -u OPEN:__TEMP__ UDP6:[::1]:10001,shut-null
 guestw
 gout	GUEST_MD5 md5sum test.bin | cut -d' ' -f1
 check	[ "__GUEST_MD5__" = "__HOST_MD5__" ]
 
 test	UDP/IPv6: guest to host
-hostb	(socat -u UDP6-LISTEN:10003,bind=[::1] STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
+hostb	socat -u UDP6-LISTEN:10003,bind=[::1],null-eof OPEN:__TEMP__,create,trunc
 gout	GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway'
 gout	IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname'
-guest	socat -u OPEN:test.bin UDP6:[__GW6__%__IFNAME__]:10003
+guest	socat -u OPEN:test.bin UDP6:[__GW6__%__IFNAME__]:10003,shut-null
 hostw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 check	[ "__GUEST_MD5__" = "__HOST_MD5__" ]
diff --git a/test/passt_in_ns/udp b/test/passt_in_ns/udp
index 3b1e521..5f01cbf 100644
--- a/test/passt_in_ns/udp
+++ b/test/passt_in_ns/udp
@@ -11,17 +11,16 @@
 # Copyright (c) 2021 Red Hat GmbH
 # Author: Stefano Brivio <sbrivio(a)redhat.com>
 
-gtools	socat tee grep cat ip jq md5sum cut
-nstools	socat tee grep cat ip jq md5sum cut
-htools	printf dd socat tee grep cat ip jq md5sum cut
+gtools	socat ip jq md5sum cut
+nstools	socat ip jq md5sum cut
+htools	dd socat ip jq md5sum cut
 
 test	UDP/IPv4: host to guest
 set	TEMP __STATEDIR__/data
-set	SC_PID __STATEDIR__/socat.pid
-guestb	(socat -u UDP4-LISTEN:10001 STDOUT & echo $! > sc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat sc.pid))
+guestb	socat -u UDP4-LISTEN:10001,null-eof OPEN:test.bin,create,trunc
 sleep	1
-host	dd if=/dev/urandom bs=1k count=5 > __TEMP__ && printf "\nEND_OF_TEST\n" >> __TEMP__
-host	socat -u OPEN:__TEMP__ UDP4:127.0.0.1:10001
+host	dd if=/dev/urandom bs=1k count=5 > __TEMP__
+host	socat -u OPEN:__TEMP__ UDP4:127.0.0.1:10001,shut-null
 guestw
 hout	MD5 md5sum __TEMP__ | cut -d' ' -f1
 gout	GUEST_MD5 md5sum test.bin | cut -d' ' -f1
@@ -29,114 +28,114 @@ check	[ "__GUEST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv4: host to ns
 set	TEMP_NS __STATEDIR__/data_ns
-nsb	(socat -u UDP4-LISTEN:10002 STDOUT & echo $! > __SC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
-host	socat -u OPEN:__TEMP__ UDP4:127.0.0.1:10002
+nsb	socat -u UDP4-LISTEN:10002,null-eof OPEN:__TEMP_NS__,create,trunc
+host	socat -u OPEN:__TEMP__ UDP4:127.0.0.1:10002,shut-null
 nsw
 nsout	NS_MD5 md5sum __TEMP_NS__ | cut -d' ' -f1
 check	[ "__NS_MD5__" = "__MD5__" ]
 
 test	UDP/IPv4: guest to host
-hostb	(socat -u UDP4-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
+hostb	socat -u UDP4-LISTEN:10003,null-eof OPEN:__TEMP__,create,trunc
 gout	GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway'
-guest	socat -u OPEN:test.bin UDP4:__GW__:10003
+guest	socat -u OPEN:test.bin UDP4:__GW__:10003,shut-null
 hostw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 check	[ "__HOST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv4: guest to ns
-nsb	(socat -u UDP4-LISTEN:10002 STDOUT & echo $! > __SC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
-guest	socat -u OPEN:test.bin UDP4:__GW__:10002
+nsb	socat -u UDP4-LISTEN:10002,null-eof OPEN:__TEMP_NS__,create,trunc
+guest	socat -u OPEN:test.bin UDP4:__GW__:10002,shut-null
 nsw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 check	[ "__HOST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv4: ns to host (recvmmsg/sendmmsg)
 sleep	1
-hostb	(socat -u UDP4-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
-ns	socat -u OPEN:__TEMP_NS__ UDP4:127.0.0.1:10003
+hostb	socat -u UDP4-LISTEN:10003,null-eof OPEN:__TEMP__,create,trunc
+ns	socat -u OPEN:__TEMP_NS__ UDP4:127.0.0.1:10003,shut-null
 hostw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 check	[ "__HOST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv4: ns to host (via tap)
-hostb	(socat -u UDP4-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
-ns	socat -u OPEN:__TEMP_NS__ UDP4:__GW__:10003
+hostb	socat -u UDP4-LISTEN:10003,null-eof OPEN:__TEMP__,create,trunc
+ns	socat -u OPEN:__TEMP_NS__ UDP4:__GW__:10003,shut-null
 hostw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 check	[ "__HOST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv4: ns to guest (using loopback address)
-guestb	(socat -u UDP4-LISTEN:10001 STDOUT & echo $! > sc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat sc.pid))
-ns	socat -u OPEN:__TEMP_NS__ UDP4:127.0.0.1:10001
+guestb	socat -u UDP4-LISTEN:10001,null-eof OPEN:test.bin,create,trunc
+ns	socat -u OPEN:__TEMP_NS__ UDP4:127.0.0.1:10001,shut-null
 guestw
 gout	GUEST_MD5 md5sum test.bin | cut -d' ' -f1
 check	[ "__GUEST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv4: ns to guest (using namespace address)
-guestb	(socat -u UDP4-LISTEN:10001 STDOUT & echo $! > sc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat sc.pid))
+guestb	socat -u UDP4-LISTEN:10001,null-eof OPEN:test.bin,create,trunc
 nsout	IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname'
 nsout	ADDR ip -j -4 addr show|jq -rM '.[] | select(.ifname == "__IFNAME__").addr_info[0].local'
-ns	socat -u OPEN:__TEMP_NS__ UDP4:__ADDR__:10001
+ns	socat -u OPEN:__TEMP_NS__ UDP4:__ADDR__:10001,shut-null
 guestw
 gout	GUEST_MD5 md5sum test.bin | cut -d' ' -f1
 check	[ "__GUEST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv6: host to guest
-guestb	(socat -u UDP6-LISTEN:10001 STDOUT & echo $! > sc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat sc.pid))
-host	socat -u OPEN:__TEMP__ UDP6:[::1]:10001
+guestb	socat -u UDP6-LISTEN:10001,null-eof OPEN:test.bin,create,trunc
+host	socat -u OPEN:__TEMP__ UDP6:[::1]:10001,shut-null
 guestw
 gout	GUEST_MD5 md5sum test.bin | cut -d' ' -f1
 check	[ "__GUEST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv6: host to ns
-nsb	(socat -u UDP6-LISTEN:10002 STDOUT & echo $! > __SC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
-host	socat -u OPEN:__TEMP__ UDP6:[::1]:10002
+nsb	socat -u UDP6-LISTEN:10002,null-eof OPEN:__TEMP_NS__,create,trunc
+host	socat -u OPEN:__TEMP__ UDP6:[::1]:10002,shut-null
 nsw
 nsout	NS_MD5 md5sum __TEMP_NS__ | cut -d' ' -f1
 check	[ "__NS_MD5__" = "__MD5__" ]
 
 test	UDP/IPv6: guest to host
-hostb	(socat -u UDP6-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
+hostb	socat -u UDP6-LISTEN:10003,null-eof OPEN:__TEMP__,create,trunc
 gout	GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway'
 gout	IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname'
-guest	socat -u OPEN:test.bin UDP6:[__GW6__%__IFNAME__]:10003
+guest	socat -u OPEN:test.bin UDP6:[__GW6__%__IFNAME__]:10003,shut-null
 hostw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 check	[ "__HOST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv6: guest to ns
-nsb	(socat -u UDP6-LISTEN:10002 STDOUT & echo $! > __SC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
-guest	socat -u OPEN:test.bin UDP6:[__GW6__%__IFNAME__]:10002
+nsb	socat -u UDP6-LISTEN:10002,null-eof OPEN:__TEMP_NS__,create,trunc
+guest	socat -u OPEN:test.bin UDP6:[__GW6__%__IFNAME__]:10002,shut-null
 nsw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 check	[ "__HOST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv6: ns to host (recvmmsg/sendmmsg)
-hostb	(socat -u UDP6-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
-ns	socat -u OPEN:__TEMP_NS__ UDP6:[::1]:10003
+hostb	socat -u UDP6-LISTEN:10003,null-eof OPEN:__TEMP__,create,trunc
+ns	socat -u OPEN:__TEMP_NS__ UDP6:[::1]:10003,shut-null
 hostw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 check	[ "__HOST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv6: ns to host (via tap)
-hostb	(socat -u UDP6-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
+hostb	socat -u UDP6-LISTEN:10003,null-eof OPEN:__TEMP__,create,trunc
 nsout	IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname'
-ns	socat -u OPEN:__TEMP_NS__ UDP6:[__GW6__%__IFNAME__]:10003
+ns	socat -u OPEN:__TEMP_NS__ UDP6:[__GW6__%__IFNAME__]:10003,shut-null
 hostw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 check	[ "__HOST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv6: ns to guest (using loopback address)
-guestb	(socat -u UDP6-LISTEN:10001 STDOUT & echo $! > sc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat sc.pid))
-ns	socat -u OPEN:__TEMP_NS__ UDP6:[::1]:10001
+guestb	socat -u UDP6-LISTEN:10001,null-eof OPEN:test.bin,create,trunc
+ns	socat -u OPEN:__TEMP_NS__ UDP6:[::1]:10001,shut-null
 guestw
 gout	GUEST_MD5 md5sum test.bin | cut -d' ' -f1
 check	[ "__GUEST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv6: ns to guest (using namespace address)
-guestb	(socat -u UDP6-LISTEN:10001 STDOUT & echo $! > sc.pid) | tee test.bin | (grep -qm1 "END_OF_TEST" && kill $(cat sc.pid))
+guestb	socat -u UDP6-LISTEN:10001,null-eof OPEN:test.bin,create,trunc
 nsout	ADDR6 ip -j -6 addr show|jq -rM '.[] | select(.ifname == "__IFNAME__").addr_info[0].local'
-ns	socat -u OPEN:__TEMP_NS__ UDP6:[__ADDR6__]:10001
+ns	socat -u OPEN:__TEMP_NS__ UDP6:[__ADDR6__]:10001,shut-null
 guestw
 gout	GUEST_MD5 md5sum test.bin | cut -d' ' -f1
 check	[ "__GUEST_MD5__" = "__MD5__" ]
diff --git a/test/pasta/udp b/test/pasta/udp
index 74148e3..fc6bf0a 100644
--- a/test/pasta/udp
+++ b/test/pasta/udp
@@ -11,59 +11,58 @@
 # Copyright (c) 2021 Red Hat GmbH
 # Author: Stefano Brivio <sbrivio(a)redhat.com>
 
-nstools	socat tee grep cat ip jq md5sum cut
-htools	printf dd socat tee grep cat ip jq md5sum cut
+nstools	socat ip jq md5sum cut
+htools	dd socat ip jq md5sum cut
 
 test	UDP/IPv4: host to ns
 set	TEMP __STATEDIR__/data
 set	TEMP_NS __STATEDIR__/data_ns
-set	SC_PID __STATEDIR__/socat.pid
-nsb	(socat -u UDP4-LISTEN:10002,bind=127.0.0.1 STDOUT & echo $! > __SC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
-host	dd if=/dev/urandom bs=1k count=5 > __TEMP__ && printf "\nEND_OF_TEST\n" >> __TEMP__
+nsb	socat -u UDP4-LISTEN:10002,bind=127.0.0.1,null-eof OPEN:__TEMP_NS__,create,trunc
+host	dd if=/dev/urandom bs=1k count=5 > __TEMP__
 
-host	socat OPEN:__TEMP__ UDP4:127.0.0.1:10002
+host	socat OPEN:__TEMP__ UDP4:127.0.0.1:10002,shut-null
 nsw
 hout	MD5 md5sum __TEMP__ | cut -d' ' -f1
 nsout	NS_MD5 md5sum __TEMP_NS__ | cut -d' ' -f1
 check	[ "__NS_MD5__" = "__MD5__" ]
 
 test	UDP/IPv4: ns to host (recvmmsg/sendmmsg)
-hostb	(socat -u UDP4-LISTEN:10003,bind=127.0.0.1 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
+hostb	socat -u UDP4-LISTEN:10003,bind=127.0.0.1,null-eof OPEN:__TEMP__,create,trunc
 sleep	1
-ns	socat OPEN:__TEMP_NS__ UDP4:127.0.0.1:10003
+ns	socat OPEN:__TEMP_NS__ UDP4:127.0.0.1:10003,shut-null
 hostw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 check	[ "__HOST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv4: ns to host (via tap)
-hostb	(socat -u UDP4-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
+hostb	socat -u UDP4-LISTEN:10003,null-eof OPEN:__TEMP__,create,trunc
 nsout	GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway'
-ns	socat -u OPEN:__TEMP_NS__ UDP4:__GW__:10003
+ns	socat -u OPEN:__TEMP_NS__ UDP4:__GW__:10003,shut-null
 hostw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 check	[ "__HOST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv6: host to ns
-nsb	(socat -u UDP6-LISTEN:10002,bind=[::1] STDOUT & echo $! > __SC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
-host	socat -u OPEN:__TEMP__ UDP6:[::1]:10002
+nsb	socat -u UDP6-LISTEN:10002,bind=[::1],null-eof OPEN:__TEMP_NS__,create,trunc
+host	socat -u OPEN:__TEMP__ UDP6:[::1]:10002,shut-null
 nsw
 hout	MD5 md5sum __TEMP__ | cut -d' ' -f1
 nsout	NS_MD5 md5sum __TEMP_NS__ | cut -d' ' -f1
 check	[ "__NS_MD5__" = "__MD5__" ]
 
 test	UDP/IPv6: ns to host (recvmmsg/sendmmsg)
-hostb	(socat -u UDP6-LISTEN:10003,bind=[::1] STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
+hostb	socat -u UDP6-LISTEN:10003,bind=[::1],null-eof OPEN:__TEMP__,create,trunc
 sleep	1
-ns	socat -u OPEN:__TEMP_NS__ UDP6:[::1]:10003
+ns	socat -u OPEN:__TEMP_NS__ UDP6:[::1]:10003,shut-null
 hostw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 check	[ "__HOST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv6: ns to host (via tap)
-hostb	(socat -u UDP6-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
+hostb	socat -u UDP6-LISTEN:10003,null-eof OPEN:__TEMP__,create,trunc
 nsout	GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway'
 nsout	IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname'
-ns	socat -u OPEN:__TEMP_NS__ UDP6:[__GW6__%__IFNAME__]:10003
+ns	socat -u OPEN:__TEMP_NS__ UDP6:[__GW6__%__IFNAME__]:10003,shut-null
 hostw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 check	[ "__HOST_MD5__" = "__MD5__" ]
-- 
@@ -11,59 +11,58 @@
 # Copyright (c) 2021 Red Hat GmbH
 # Author: Stefano Brivio <sbrivio(a)redhat.com>
 
-nstools	socat tee grep cat ip jq md5sum cut
-htools	printf dd socat tee grep cat ip jq md5sum cut
+nstools	socat ip jq md5sum cut
+htools	dd socat ip jq md5sum cut
 
 test	UDP/IPv4: host to ns
 set	TEMP __STATEDIR__/data
 set	TEMP_NS __STATEDIR__/data_ns
-set	SC_PID __STATEDIR__/socat.pid
-nsb	(socat -u UDP4-LISTEN:10002,bind=127.0.0.1 STDOUT & echo $! > __SC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
-host	dd if=/dev/urandom bs=1k count=5 > __TEMP__ && printf "\nEND_OF_TEST\n" >> __TEMP__
+nsb	socat -u UDP4-LISTEN:10002,bind=127.0.0.1,null-eof OPEN:__TEMP_NS__,create,trunc
+host	dd if=/dev/urandom bs=1k count=5 > __TEMP__
 
-host	socat OPEN:__TEMP__ UDP4:127.0.0.1:10002
+host	socat OPEN:__TEMP__ UDP4:127.0.0.1:10002,shut-null
 nsw
 hout	MD5 md5sum __TEMP__ | cut -d' ' -f1
 nsout	NS_MD5 md5sum __TEMP_NS__ | cut -d' ' -f1
 check	[ "__NS_MD5__" = "__MD5__" ]
 
 test	UDP/IPv4: ns to host (recvmmsg/sendmmsg)
-hostb	(socat -u UDP4-LISTEN:10003,bind=127.0.0.1 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
+hostb	socat -u UDP4-LISTEN:10003,bind=127.0.0.1,null-eof OPEN:__TEMP__,create,trunc
 sleep	1
-ns	socat OPEN:__TEMP_NS__ UDP4:127.0.0.1:10003
+ns	socat OPEN:__TEMP_NS__ UDP4:127.0.0.1:10003,shut-null
 hostw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 check	[ "__HOST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv4: ns to host (via tap)
-hostb	(socat -u UDP4-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
+hostb	socat -u UDP4-LISTEN:10003,null-eof OPEN:__TEMP__,create,trunc
 nsout	GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway'
-ns	socat -u OPEN:__TEMP_NS__ UDP4:__GW__:10003
+ns	socat -u OPEN:__TEMP_NS__ UDP4:__GW__:10003,shut-null
 hostw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 check	[ "__HOST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv6: host to ns
-nsb	(socat -u UDP6-LISTEN:10002,bind=[::1] STDOUT & echo $! > __SC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
-host	socat -u OPEN:__TEMP__ UDP6:[::1]:10002
+nsb	socat -u UDP6-LISTEN:10002,bind=[::1],null-eof OPEN:__TEMP_NS__,create,trunc
+host	socat -u OPEN:__TEMP__ UDP6:[::1]:10002,shut-null
 nsw
 hout	MD5 md5sum __TEMP__ | cut -d' ' -f1
 nsout	NS_MD5 md5sum __TEMP_NS__ | cut -d' ' -f1
 check	[ "__NS_MD5__" = "__MD5__" ]
 
 test	UDP/IPv6: ns to host (recvmmsg/sendmmsg)
-hostb	(socat -u UDP6-LISTEN:10003,bind=[::1] STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
+hostb	socat -u UDP6-LISTEN:10003,bind=[::1],null-eof OPEN:__TEMP__,create,trunc
 sleep	1
-ns	socat -u OPEN:__TEMP_NS__ UDP6:[::1]:10003
+ns	socat -u OPEN:__TEMP_NS__ UDP6:[::1]:10003,shut-null
 hostw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 check	[ "__HOST_MD5__" = "__MD5__" ]
 
 test	UDP/IPv6: ns to host (via tap)
-hostb	(socat -u UDP6-LISTEN:10003 STDOUT & echo $! > __SC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __SC_PID__))
+hostb	socat -u UDP6-LISTEN:10003,null-eof OPEN:__TEMP__,create,trunc
 nsout	GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway'
 nsout	IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname'
-ns	socat -u OPEN:__TEMP_NS__ UDP6:[__GW6__%__IFNAME__]:10003
+ns	socat -u OPEN:__TEMP_NS__ UDP6:[__GW6__%__IFNAME__]:10003,shut-null
 hostw
 hout	HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1
 check	[ "__HOST_MD5__" = "__MD5__" ]
-- 
2.37.3


      parent reply	other threads:[~2022-09-13  6:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-13  6:37 [PATCH v2 0/3] Don't drop outbound zero-length UDP packets over tap David Gibson
2022-09-13  6:37 ` [PATCH v2 1/3] udp: Don't pre-initialize msghdr array David Gibson
2022-09-13  6:37 ` [PATCH v2 2/3] udp: Don't drop zero-length outbound UDP packets David Gibson
2022-09-13  6:37 ` David Gibson [this message]

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=20220913063745.3657546-4-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    /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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

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 IMAP folder(s).