Skip to contentSkip to conversation

lib/shell: run commands with 'timeout'

PATCH New Alexey Kodanev 2 participants 7 messages May 24, 2017 – Sep 11, 2017

lore
Share & tools
lore
#0 lore raw

cover lib/shell: run commands with 'timeout'

The first three patches remove usage of shell functions with 'ROD' based functions and the last one adds 'timeout' command to the both shell libraries.

Alexey Kodanev (4):
lib/test_net: print TPASS/TFAIL inside tst_ping()
net: remove EXPECT_PASS usage with tst_ping() net/virt_lib.sh: don't use ROD_SILENT with shell function lib/test: run ROD_BASE() & tst_rod() with 'timeout' cmd

 testcases/lib/test.sh                              |    7 +++++--
 testcases/lib/test_net.sh                          |    4 ++--
 testcases/lib/tst_test.sh                          |   11 +++++++----
 .../network/stress/broken_ip/broken_ip4-checksum   |    2 +-
 .../network/stress/broken_ip/broken_ip4-dstaddr    |    2 +-
 .../network/stress/broken_ip/broken_ip4-fragment   |    2 +-
 testcases/network/stress/broken_ip/broken_ip4-ihl  |    2 +-
 .../network/stress/broken_ip/broken_ip4-protcol    |    2 +-
 .../network/stress/broken_ip/broken_ip4-totlen     |    2 +-
 .../network/stress/broken_ip/broken_ip4-version    |    2 +-
 .../network/stress/broken_ip/broken_ip6-dstaddr    |    2 +-
 .../network/stress/broken_ip/broken_ip6-nexthdr    |    2 +-
 testcases/network/stress/broken_ip/broken_ip6-plen |    2 +-
 .../network/stress/broken_ip/broken_ip6-version    |    2 +-
 testcases/network/stress/icmp/icmp-uni-basic.sh    |    5 -----
 testcases/network/stress/icmp/icmp-uni-vti.sh      |    2 +-
 testcases/network/stress/interface/if-lib.sh       |    7 +------
 testcases/network/stress/interface/if-mtu-change   |    2 +-
 testcases/network/stress/interface/if4-addr-change |    4 ++--
 testcases/network/virt/virt_lib.sh                 |    9 ++++++---
 20 files changed, 36 insertions(+), 37 deletions(-)
#1 lore raw

PATCH 1/4 lib/test_net: print TPASS/TFAIL inside tst_ping()

Since there is no usage of 'expected fail' in the tests with tst_ping() and new shell library doesn't support passing shell functions to EXPECT_PASS, set test result inside tst_ping.

---
 testcases/lib/test_net.sh |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
testcases/lib/test_net.sh +2 -2
index dae066b..2ed6fb4 100644
@@ -426,9 +426,9 @@ tst_ping()
 			-s $size -i 0 > /dev/null 2>&1
 		ret=$?
 		if [ $ret -eq 0 ]; then
-			tst_resm TINFO "tst_ping IPv${TST_IPV6:-4} msg_size $size pass"
+			tst_resm TPASS "tst_ping IPv${TST_IPV6:-4} msg_size $size pass"
 		else
-			tst_resm TINFO "tst_ping IPv${TST_IPV6:-4} msg_size $size fail"
+			tst_resm TFAIL "tst_ping IPv${TST_IPV6:-4} msg_size $size fail"
 			break
 		fi
 	done
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/4 net: remove EXPECT_PASS usage with tst_ping()

In reply to Alexey Kodanev
---
 .../network/stress/broken_ip/broken_ip4-checksum   |    2 +-
 .../network/stress/broken_ip/broken_ip4-dstaddr    |    2 +-
 .../network/stress/broken_ip/broken_ip4-fragment   |    2 +-
 testcases/network/stress/broken_ip/broken_ip4-ihl  |    2 +-
 .../network/stress/broken_ip/broken_ip4-protcol    |    2 +-
 .../network/stress/broken_ip/broken_ip4-totlen     |    2 +-
 .../network/stress/broken_ip/broken_ip4-version    |    2 +-
 .../network/stress/broken_ip/broken_ip6-dstaddr    |    2 +-
 .../network/stress/broken_ip/broken_ip6-nexthdr    |    2 +-
 testcases/network/stress/broken_ip/broken_ip6-plen |    2 +-
 .../network/stress/broken_ip/broken_ip6-version    |    2 +-
 testcases/network/stress/icmp/icmp-uni-basic.sh    |    5 -----
 testcases/network/stress/icmp/icmp-uni-vti.sh      |    2 +-
 testcases/network/stress/interface/if-lib.sh       |    7 +------
 testcases/network/stress/interface/if-mtu-change   |    2 +-
 testcases/network/stress/interface/if4-addr-change |    4 ++--
 16 files changed, 16 insertions(+), 26 deletions(-)
testcases/network/stress/broken_ip/broken_ip4-checksum +1 -1
index 33667ba..ff30fbf 100644
@@ -27,6 +27,6 @@ tst_resm TINFO "Sending ICMPv4 with wrong chksum field for $NS_DURATION sec"
 
 tst_icmp -t $NS_DURATION -s "0 100 500 1000 1472" -c
 
-EXPECT_PASS tst_ping
+tst_ping
 
 tst_exit
testcases/network/stress/broken_ip/broken_ip4-dstaddr +1 -1
index b4b676e..eb236f2 100644
@@ -27,6 +27,6 @@ tst_resm TINFO "Sending ICMPv4 with wrong dst address for $NS_DURATION sec"
 
 tst_icmp -t $NS_DURATION -s "0 100 500 1000 1472" -i
 
-EXPECT_PASS tst_ping
+tst_ping
 
 tst_exit
testcases/network/stress/broken_ip/broken_ip4-fragment +1 -1
index dbef193..8f2aca9 100644
@@ -27,6 +27,6 @@ tst_resm TINFO "Sending ICMPv4 with wrong frag. info for $NS_DURATION sec"
 
 tst_icmp -t $NS_DURATION -s "0 100 500 1000 1472" -f
 
-EXPECT_PASS tst_ping
+tst_ping
 
 tst_exit
testcases/network/stress/broken_ip/broken_ip4-ihl +1 -1
index 48deb3b..2e136a5 100644
@@ -27,6 +27,6 @@ tst_resm TINFO "Sending ICMPv4 with wrong header len field for $NS_DURATION sec"
 
 tst_icmp -t $NS_DURATION -s "0 100 500 1000 1472" -l
 
-EXPECT_PASS tst_ping
+tst_ping
 
 tst_exit
testcases/network/stress/broken_ip/broken_ip4-protcol +1 -1
index b4b767c..a57ce61 100644
@@ -27,6 +27,6 @@ tst_resm TINFO "Sending ICMPv4 with wrong proto field for $NS_DURATION sec"
 
 tst_icmp -t $NS_DURATION -s "0 100 500 1000 1472" -p
 
-EXPECT_PASS tst_ping
+tst_ping
 
 tst_exit
testcases/network/stress/broken_ip/broken_ip4-totlen +1 -1
index 051d969..4466487 100644
@@ -27,6 +27,6 @@ tst_resm TINFO "Sending ICMPv4 with wrong total len field for $NS_DURATION sec"
 
 tst_icmp -t $NS_DURATION -s "0 100 500 1000 1472" -L
 
-EXPECT_PASS tst_ping
+tst_ping
 
 tst_exit
testcases/network/stress/broken_ip/broken_ip4-version +1 -1
index c3ccf7f..83cf568 100644
@@ -27,6 +27,6 @@ tst_resm TINFO "Sending ICMPv4 with wrong version field for $NS_DURATION sec"
 
 tst_icmp -t $NS_DURATION -s "0 100 500 1000 1472" -v
 
-EXPECT_PASS tst_ping
+tst_ping
 
 tst_exit
testcases/network/stress/broken_ip/broken_ip6-dstaddr +1 -1
index 5da38ab..ea7d66d 100644
@@ -27,6 +27,6 @@ tst_resm TINFO "Sending ICMPv6 with wrong dst address for $NS_DURATION sec"
 
 tst_icmp -t $NS_DURATION -s "0 100 500 1000 1452" -i
 
-EXPECT_PASS tst_ping
+tst_ping
 
 tst_exit
testcases/network/stress/broken_ip/broken_ip6-nexthdr +1 -1
index bb1bdcb..ebbef5e 100644
@@ -27,6 +27,6 @@ tst_resm TINFO "Sending ICMPv4 with wrong next header for $NS_DURATION sec"
 
 tst_icmp -t $NS_DURATION -s "0 100 500 1000 1452" -n
 
-EXPECT_PASS tst_ping
+tst_ping
 
 tst_exit
testcases/network/stress/broken_ip/broken_ip6-plen +1 -1
index 8eacbf4..e93cdcc 100644
@@ -27,6 +27,6 @@ tst_resm TINFO "Sending ICMPv4 with wrong payload len for $NS_DURATION sec"
 
 tst_icmp -t $NS_DURATION -s "0 100 500 1000 1452" -L
 
-EXPECT_PASS tst_ping
+tst_ping
 
 tst_exit
testcases/network/stress/broken_ip/broken_ip6-version +1 -1
index cdce71f..3eff2d7 100644
@@ -27,6 +27,6 @@ tst_resm TINFO "Sending ICMPv6 with wrong version field for $NS_DURATION sec"
 
 tst_icmp -t $NS_DURATION -s "0 100 500 1000 1452" -v
 
-EXPECT_PASS tst_ping
+tst_ping
 
 tst_exit
testcases/network/stress/icmp/icmp-uni-basic.sh +0 -5
index 2aae945..7e50386 100755
@@ -57,10 +57,5 @@ if $DO_IPSEC ; then
 fi
 
 tst_ping $lhost_ifname $rhost_addr $IPSEC_SIZE_ARRAY
-if [ $? -ne 0 ]; then
-	tst_resm TFAIL "Checked IPv${TST_IPV6:-4} $IPSEC_PROTO $IPSEC_MODE"
-else
-	tst_resm TPASS "Checked IPv${TST_IPV6:-4} $IPSEC_PROTO $IPSEC_MODE"
-fi
 
 tst_exit
testcases/network/stress/icmp/icmp-uni-vti.sh +1 -1
index a19c869..b9a1034 100755
@@ -27,7 +27,7 @@ do_test()
 	IPSEC_SIZE_ARRAY="${IPSEC_SIZE_ARRAY:-10 100 1000 10000 65507}"
 
 	tst_resm TINFO "Sending ICMP messages..."
-	EXPECT_PASS tst_ping $tst_vti $ip_rmt_tun $IPSEC_SIZE_ARRAY
+	tst_ping $tst_vti $ip_rmt_tun $IPSEC_SIZE_ARRAY
 }
 
 tst_ipsec_setup_vti
testcases/network/stress/interface/if-lib.sh +1 -6
index 4168dd0..000f742 100644
@@ -58,12 +58,7 @@ check_connectivity()
 
 	[ -n "$restore" ] && restore_ipaddr
 
-	tst_ping
-	if [ $? -ne 0 ]; then
-		tst_resm TFAIL "$(tst_iface) is broken"
-		return 1
-	fi
-	return 0
+	tst_ping || return 1
 }
 
 restore_ipaddr()
testcases/network/stress/interface/if-mtu-change +1 -1
index 637fa63..01cbec6 100644
@@ -91,7 +91,7 @@ test_body()
 
 		tst_sleep $CHANGE_INTERVAL
 
-		EXPECT_PASS tst_ping $(tst_ipaddr) $(tst_ipaddr rhost) "1 1000 65507"
+		tst_ping $(tst_ipaddr) $(tst_ipaddr rhost) "1 1000 65507"
 
 		# Check the background TCP traffic
 		pgrep -x netstress > /dev/null || make_background_tcp_traffic
testcases/network/stress/interface/if4-addr-change +2 -2
index 54b8fd5..cbe22ce 100644
@@ -61,9 +61,9 @@ while [ $cnt -lt $NS_TIMES ]; do
 	[ $(($cnt % $CHECK_INTERVAL)) -ne 0 ] && continue
 
 	tst_resm TINFO "ping $(tst_ipaddr):$(tst_ipaddr rhost) ${cnt}/$NS_TIMES"
-	EXPECT_PASS tst_ping
+	tst_ping
 done
 
-EXPECT_PASS tst_ping
+tst_ping
 
 tst_exit
Signature · 1 line
1.7.1
#3 lore raw

PATCH 2/4 net: remove EXPECT_PASS usage with tst_ping()

Hi,

Applied the first two patches from the set:

[PATCH 1/4] lib/test_net: print TPASS/TFAIL inside tst_ping() [PATCH 2/4] net: remove EXPECT_PASS usage with tst_ping()

Best regards,
Alexey

#4 lore raw

PATCH 3/4 net/virt_lib.sh: don't use ROD_SILENT with shell function

In reply to Alexey Kodanev
---
 testcases/network/virt/virt_lib.sh |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
testcases/network/virt/virt_lib.sh +6 -3
index 6036b42..05eaf0d 100644
@@ -157,7 +157,8 @@ virt_multiple_add_test()
 	tst_resm TINFO "add $virt_count $virt_type, then delete"
 
 	for i in $(seq $start_id $max); do
-		ROD_SILENT "virt_add ltp_v$i id $i $opt"
+		virt_add ltp_v$i id $i $opt || \
+			tst_brkm TFAIL "failed to create 'ltp_v0 $opt'"
 		ROD_SILENT "ip link set ltp_v$i up"
 	done
 
@@ -177,7 +178,8 @@ virt_add_delete_test()
 	tst_resm TINFO "add/del $virt_type $virt_count times"
 
 	for i in $(seq 0 $max); do
-		ROD_SILENT "virt_add ltp_v0 $opt"
+		virt_add ltp_v0 $opt || \
+			tst_brkm TFAIL "failed to create 'ltp_v0 $opt'"
 		ROD_SILENT "ip link set ltp_v0 up"
 		ROD_SILENT "ip link delete ltp_v0"
 	done
@@ -190,7 +192,8 @@ virt_setup()
 	local opt_r="$2"
 
 	tst_resm TINFO "setup local ${virt_type} with '$opt'"
-	ROD_SILENT "virt_add ltp_v0 $opt"
+	virt_add ltp_v0 $opt || \
+		tst_brkm TBROK "failed to create 'ltp_v0 $opt'"
 
 	tst_resm TINFO "setup rhost ${virt_type} with '$opt_r'"
 	virt_add_rhost "$opt_r"
Signature · 1 line
1.7.1
#5 lore raw

PATCH 4/4 lib/test: run ROD_BASE() & tst_rod() with 'timeout' cmd

In reply to Alexey Kodanev
---
 testcases/lib/test.sh     |    7 +++++--
 testcases/lib/tst_test.sh |   11 +++++++----
 2 files changed, 12 insertions(+), 6 deletions(-)
testcases/lib/test.sh +5 -2
index 2e4d868..5247873 100644
@@ -253,9 +253,9 @@ ROD_BASE()
 	done
 
 	if [ -n "$flag" ]; then
-		$cmd > $file
+		$TST_TIMECMD $cmd > $file
 	else
-		$@
+		$TST_TIMECMD $@
 	fi
 }
 
@@ -425,3 +425,6 @@ if [ "$TST_NEEDS_CHECKPOINTS" = "1" ]; then
 	ROD_SILENT chmod 600 "$LTP_IPC_PATH"
 	export LTP_IPC_PATH
 fi
+
+command -v timeout > /dev/null 2>&1 && \
+	TST_TIMECMD="timeout -s 9 $((300 * ${LTP_TIMEOUT_MUL:-1}))s"
testcases/lib/tst_test.sh +7 -4
index 087adda..c4fbe86 100644
@@ -116,7 +116,7 @@ tst_brk()
 
 ROD_SILENT()
 {
-	tst_rod $@ > /dev/null 2>&1
+	$TST_TIMECMD tst_rod $@ > /dev/null 2>&1
 	if [ $? -ne 0 ]; then
 		tst_brk TBROK "$@ failed"
 	fi
@@ -124,7 +124,7 @@ ROD_SILENT()
 
 ROD()
 {
-	tst_rod "$@"
+	$TST_TIMECMD tst_rod "$@"
 	if [ $? -ne 0 ]; then
 		tst_brk TBROK "$@ failed"
 	fi
@@ -132,7 +132,7 @@ ROD()
 
 EXPECT_PASS()
 {
-	tst_rod "$@"
+	$TST_TIMECMD tst_rod "$@"
 	if [ $? -eq 0 ]; then
 		tst_res TPASS "$@ passed as expected"
 	else
@@ -143,7 +143,7 @@ EXPECT_PASS()
 EXPECT_FAIL()
 {
 	# redirect stderr since we expect the command to fail
-	tst_rod "$@" 2> /dev/null
+	$TST_TIMECMD tst_rod "$@" 2> /dev/null
 	if [ $? -ne 0 ]; then
 		tst_res TPASS "$@ failed as expected"
 	else
@@ -430,3 +430,6 @@ else
 		tst_brk TBROK "Unexpected positional arguments '$@'"
 	fi
 fi
+
+command -v timeout > /dev/null 2>&1 && \
+	TST_TIMECMD="timeout -s 9 $((300 * ${LTP_TIMEOUT_MUL:-1}))s"
Signature · 1 line
1.7.1
#6 lore raw

PATCH 4/4 lib/test: run ROD_BASE() & tst_rod() with 'timeout' cmd

Hi!

testcases/lib/tst_test.sh tst_brk() · line 119

Quoted 10 lines
testcases/lib/tst_test.sh +1 -1
index 087adda..c4fbe86 100644
@@ -116,7 +116,7 @@ tst_brk()
 
 ROD_SILENT()
 {
-	tst_rod $@ > /dev/null 2>&1
+	$TST_TIMECMD tst_rod $@ > /dev/null 2>&1

It would be a bit cleaner to add the timeout capability to the tst_rod and pass timeout to tst_rod as a first parameter here. Which would fix the second (below) that I have for this patch.

Quoted 31 lines
testcases/lib/tst_test.sh +3 -3
 	if [ $? -ne 0 ]; then
 		tst_brk TBROK "$@ failed"
 	fi
@@ -124,7 +124,7 @@ ROD_SILENT()
 
 ROD()
 {
-	tst_rod "$@"
+	$TST_TIMECMD tst_rod "$@"
 	if [ $? -ne 0 ]; then
 		tst_brk TBROK "$@ failed"
 	fi
@@ -132,7 +132,7 @@ ROD()
 
 EXPECT_PASS()
 {
-	tst_rod "$@"
+	$TST_TIMECMD tst_rod "$@"
 	if [ $? -eq 0 ]; then
 		tst_res TPASS "$@ passed as expected"
 	else
@@ -143,7 +143,7 @@ EXPECT_PASS()
 EXPECT_FAIL()
 {
 	# redirect stderr since we expect the command to fail
-	tst_rod "$@" 2> /dev/null
+	$TST_TIMECMD tst_rod "$@" 2> /dev/null
 	if [ $? -ne 0 ]; then
 		tst_res TPASS "$@ failed as expected"
 	else

testcases/lib/tst_test.sh else · line 435

Quoted 6 lines
testcases/lib/tst_test.sh +3 -0
@@ -430,3 +430,6 @@ else
 		tst_brk TBROK "Unexpected positional arguments '$@'"
 	fi
 fi
+
+command -v timeout > /dev/null 2>&1 && \
+	TST_TIMECMD="timeout -s 9 $((300 * ${LTP_TIMEOUT_MUL:-1}))s"

I do not like that we silently disable the timeout if 'timeout' command is not available. I would rather add tst_timeout.c helper to the lib/ as we do for instance for tst_sleep to support sub-second sleep intervals.

Signature · 2 lines
Cyril Hrubis
[email protected]