[LTP] [PATCH 1/1] if-mtu-change.sh: Fix using functions
Petr Vorel
pvorel@suse.cz
Mon May 9 11:43:22 CEST 2022
Functions can be used after loading shell library, otherwise:
/opt/ltp/testcases/bin/if-mtu-change.sh: 14: tst_net_use_netns: not found
/opt/ltp/testcases/bin/if-mtu-change.sh: 19: tst_is_int: not found
Thus move timeout setup to setup function (which requires to call
tst_set_timeout() as TST_TIMEOUT is read before setup is run.
Also move setup and cleanup function up, to make variables more visible.
It could be also fixed by moving variables after sourcing if-lib.sh,
but that'd hide part of the setup to the end.
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Hi,
sorry for introducing a regression.
Kind regards,
Petr
.../network/stress/interface/if-mtu-change.sh | 58 ++++++++++---------
1 file changed, 30 insertions(+), 28 deletions(-)
diff --git a/testcases/network/stress/interface/if-mtu-change.sh b/testcases/network/stress/interface/if-mtu-change.sh
index 1fb667c19..cabc5d4cf 100755
--- a/testcases/network/stress/interface/if-mtu-change.sh
+++ b/testcases/network/stress/interface/if-mtu-change.sh
@@ -9,16 +9,6 @@ IF_CMD='ifconfig'
TST_SETUP="do_setup"
TST_CLEANUP="do_cleanup"
-# CHANGE_INTERVAL: The interval of the mtu change
-TST_TIMEOUT=1
-if tst_net_use_netns; then
- CHANGE_INTERVAL=${CHANGE_INTERVAL:-100ms}
-else
- CHANGE_INTERVAL=${CHANGE_INTERVAL:-5}
-fi
-tst_is_int $CHANGE_INTERVAL && TST_TIMEOUT=$CHANGE_INTERVAL
-TST_TIMEOUT=$(((TST_TIMEOUT + 30) * MTU_CHANGE_TIMES))
-
# The array of the value which MTU is changed into sequentially
# 552 - net.ipv4.route.min_pmtu
CHANGE_VALUES="784 1142 552 1500 552 1500 552 748 552 1142 1500"
@@ -27,6 +17,36 @@ saved_mtu=
MAX_PACKET_SIZE=65507
+do_setup()
+{
+ # CHANGE_INTERVAL: The interval of the mtu change
+ if tst_net_use_netns; then
+ CHANGE_INTERVAL=${CHANGE_INTERVAL:-100ms}
+ else
+ CHANGE_INTERVAL=${CHANGE_INTERVAL:-5}
+ fi
+
+ local timeout=1
+ tst_is_int $CHANGE_INTERVAL && timeout=$CHANGE_INTERVAL
+ tst_set_timeout $(((timeout + 30) * MTU_CHANGE_TIMES))
+
+ [ "$TST_IPV6" ] && CHANGE_VALUES=$CHANGE6_VALUES
+
+ if_setup
+ saved_mtu="$(cat /sys/class/net/$(tst_iface)/mtu)"
+ [ "$TST_IPV6" ] || find_ipv4_max_packet_size
+}
+
+do_cleanup()
+{
+ if_cleanup_restore
+
+ if [ "$saved_mtu" ]; then
+ ip link set $(tst_iface) mtu $saved_mtu
+ tst_rhost_run -c "ip link set $(tst_iface rhost) mtu $saved_mtu"
+ fi
+}
+
set_mtu()
{
local mtu="$1"
@@ -67,24 +87,6 @@ find_ipv4_max_packet_size()
tst_brk TBROK "failed to find max MTU"
}
-do_setup()
-{
-
- [ "$TST_IPV6" ] && CHANGE_VALUES=$CHANGE6_VALUES
- if_setup
- saved_mtu="$(cat /sys/class/net/$(tst_iface)/mtu)"
- [ "$TST_IPV6" ] || find_ipv4_max_packet_size
-}
-
-do_cleanup()
-{
- if_cleanup_restore
- if [ "$saved_mtu" ]; then
- ip link set $(tst_iface) mtu $saved_mtu
- tst_rhost_run -c "ip link set $(tst_iface rhost) mtu $saved_mtu"
- fi
-}
-
test_body()
{
local cmd="$CMD"
--
2.36.0
More information about the ltp
mailing list