if-updown.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. # Copyright (c) 2017-2018 Petr Vorel <pvorel@suse.cz>
  4. # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
  5. # Copyright (c) International Business Machines Corp., 2005
  6. # Author: Mitsuru Chinen <mitch@jp.ibm.com>
  7. IF_CMD='ifconfig'
  8. TST_CLEANUP="if_cleanup_restore"
  9. . if-lib.sh
  10. CHECK_INTERVAL=${CHECK_INTERVAL:-$(($IF_UPDOWN_TIMES / 20))}
  11. test_body()
  12. {
  13. local cmd="$CMD"
  14. local iface=$(tst_iface)
  15. tst_res TINFO "'$cmd' ups/downs $iface $IF_UPDOWN_TIMES times"
  16. tst_res TINFO "check connectivity interval is $CHECK_INTERVAL"
  17. local cnt=1
  18. while [ $cnt -le $IF_UPDOWN_TIMES ]; do
  19. case $cmd in
  20. ifconfig) ifconfig $iface down ;;
  21. ip) ip link set $iface down ;;
  22. esac
  23. if [ $? -ne 0 ]; then
  24. tst_res TFAIL "Failed to down $iface"
  25. return
  26. fi
  27. case $cmd in
  28. ifconfig) ifconfig $iface up ;;
  29. ip) ip link set $iface up ;;
  30. esac
  31. if [ $? -ne 0 ]; then
  32. tst_res TFAIL "Failed to up $iface"
  33. return
  34. fi
  35. check_connectivity_interval $cnt restore_ip || return
  36. cnt=$(($cnt + 1))
  37. done
  38. tst_res TPASS "Test is finished correctly"
  39. }
  40. tst_run