xsk_prereqs.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. # Copyright(c) 2020 Intel Corporation.
  4. ksft_pass=0
  5. ksft_fail=1
  6. ksft_xfail=2
  7. ksft_xpass=3
  8. ksft_skip=4
  9. XSKOBJ=xskxceiver
  10. validate_root_exec()
  11. {
  12. msg="skip all tests:"
  13. if [ $UID != 0 ]; then
  14. echo $msg must be run as root >&2
  15. test_exit $ksft_fail
  16. else
  17. return $ksft_pass
  18. fi
  19. }
  20. validate_veth_support()
  21. {
  22. msg="skip all tests:"
  23. if [ $(ip link add $1 type veth 2>/dev/null; echo $?;) != 0 ]; then
  24. echo $msg veth kernel support not available >&2
  25. test_exit $ksft_skip
  26. else
  27. ip link del $1
  28. return $ksft_pass
  29. fi
  30. }
  31. test_status()
  32. {
  33. statusval=$1
  34. if [ $statusval -eq $ksft_fail ]; then
  35. echo "$2: [ FAIL ]"
  36. elif [ $statusval -eq $ksft_skip ]; then
  37. echo "$2: [ SKIPPED ]"
  38. elif [ $statusval -eq $ksft_pass ]; then
  39. echo "$2: [ PASS ]"
  40. fi
  41. }
  42. test_exit()
  43. {
  44. if [ $1 -ne 0 ]; then
  45. test_status $1 $(basename $0)
  46. fi
  47. exit 1
  48. }
  49. clear_configs()
  50. {
  51. if [ $(ip netns show | grep $3 &>/dev/null; echo $?;) == 0 ]; then
  52. [ $(ip netns exec $3 ip link show $2 &>/dev/null; echo $?;) == 0 ] &&
  53. { ip netns exec $3 ip link del $2; }
  54. ip netns del $3
  55. fi
  56. #Once we delete a veth pair node, the entire veth pair is removed,
  57. #this is just to be cautious just incase the NS does not exist then
  58. #veth node inside NS won't get removed so we explicitly remove it
  59. [ $(ip link show $1 &>/dev/null; echo $?;) == 0 ] &&
  60. { ip link del $1; }
  61. }
  62. cleanup_exit()
  63. {
  64. clear_configs $1 $2 $3
  65. }
  66. validate_ip_utility()
  67. {
  68. [ ! $(type -P ip) ] && { echo "'ip' not found. Skipping tests."; test_exit $ksft_skip; }
  69. }
  70. exec_xskxceiver()
  71. {
  72. if [[ $busy_poll -eq 1 ]]; then
  73. ARGS+="-b "
  74. fi
  75. ./${XSKOBJ} -i ${VETH0} -i ${VETH1},${NS1} ${ARGS}
  76. retval=$?
  77. test_status $retval "${TEST_NAME}"
  78. statusList+=($retval)
  79. nameList+=(${TEST_NAME})
  80. }