gro.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. readonly SERVER_MAC="aa:00:00:00:00:02"
  4. readonly CLIENT_MAC="aa:00:00:00:00:01"
  5. readonly TESTS=("data" "ack" "flags" "tcp" "ip" "large")
  6. readonly PROTOS=("ipv4" "ipv6")
  7. dev=""
  8. test="all"
  9. proto="ipv4"
  10. run_test() {
  11. local server_pid=0
  12. local exit_code=0
  13. local protocol=$1
  14. local test=$2
  15. local ARGS=( "--${protocol}" "--dmac" "${SERVER_MAC}" \
  16. "--smac" "${CLIENT_MAC}" "--test" "${test}" "--verbose" )
  17. setup_ns
  18. # Each test is run 3 times to deflake, because given the receive timing,
  19. # not all packets that should coalesce will be considered in the same flow
  20. # on every try.
  21. for tries in {1..3}; do
  22. # Actual test starts here
  23. ip netns exec $server_ns ./gro "${ARGS[@]}" "--rx" "--iface" "server" \
  24. 1>>log.txt &
  25. server_pid=$!
  26. sleep 0.5 # to allow for socket init
  27. ip netns exec $client_ns ./gro "${ARGS[@]}" "--iface" "client" \
  28. 1>>log.txt
  29. wait "${server_pid}"
  30. exit_code=$?
  31. if [[ ${test} == "large" && -n "${KSFT_MACHINE_SLOW}" && \
  32. ${exit_code} -ne 0 ]]; then
  33. echo "Ignoring errors due to slow environment" 1>&2
  34. exit_code=0
  35. fi
  36. if [[ "${exit_code}" -eq 0 ]]; then
  37. break;
  38. fi
  39. done
  40. cleanup_ns
  41. echo ${exit_code}
  42. }
  43. run_all_tests() {
  44. local failed_tests=()
  45. for proto in "${PROTOS[@]}"; do
  46. for test in "${TESTS[@]}"; do
  47. echo "running test ${proto} ${test}" >&2
  48. exit_code=$(run_test $proto $test)
  49. if [[ "${exit_code}" -ne 0 ]]; then
  50. failed_tests+=("${proto}_${test}")
  51. fi;
  52. done;
  53. done
  54. if [[ ${#failed_tests[@]} -ne 0 ]]; then
  55. echo "failed tests: ${failed_tests[*]}. \
  56. Please see log.txt for more logs"
  57. exit 1
  58. else
  59. echo "All Tests Succeeded!"
  60. fi;
  61. }
  62. usage() {
  63. echo "Usage: $0 \
  64. [-i <DEV>] \
  65. [-t data|ack|flags|tcp|ip|large] \
  66. [-p <ipv4|ipv6>]" 1>&2;
  67. exit 1;
  68. }
  69. while getopts "i:t:p:" opt; do
  70. case "${opt}" in
  71. i)
  72. dev="${OPTARG}"
  73. ;;
  74. t)
  75. test="${OPTARG}"
  76. ;;
  77. p)
  78. proto="${OPTARG}"
  79. ;;
  80. *)
  81. usage
  82. ;;
  83. esac
  84. done
  85. if [ -n "$dev" ]; then
  86. source setup_loopback.sh
  87. else
  88. source setup_veth.sh
  89. fi
  90. setup
  91. trap cleanup EXIT
  92. if [[ "${test}" == "all" ]]; then
  93. run_all_tests
  94. else
  95. exit_code=$(run_test "${proto}" "${test}")
  96. exit $exit_code
  97. fi;