gro.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 [[ "${exit_code}" -eq 0 ]]; then
  32. break;
  33. fi
  34. done
  35. cleanup_ns
  36. echo ${exit_code}
  37. }
  38. run_all_tests() {
  39. local failed_tests=()
  40. for proto in "${PROTOS[@]}"; do
  41. for test in "${TESTS[@]}"; do
  42. echo "running test ${proto} ${test}" >&2
  43. exit_code=$(run_test $proto $test)
  44. if [[ "${exit_code}" -ne 0 ]]; then
  45. failed_tests+=("${proto}_${test}")
  46. fi;
  47. done;
  48. done
  49. if [[ ${#failed_tests[@]} -ne 0 ]]; then
  50. echo "failed tests: ${failed_tests[*]}. \
  51. Please see log.txt for more logs"
  52. exit 1
  53. else
  54. echo "All Tests Succeeded!"
  55. fi;
  56. }
  57. usage() {
  58. echo "Usage: $0 \
  59. [-i <DEV>] \
  60. [-t data|ack|flags|tcp|ip|large] \
  61. [-p <ipv4|ipv6>]" 1>&2;
  62. exit 1;
  63. }
  64. while getopts "i:t:p:" opt; do
  65. case "${opt}" in
  66. i)
  67. dev="${OPTARG}"
  68. ;;
  69. t)
  70. test="${OPTARG}"
  71. ;;
  72. p)
  73. proto="${OPTARG}"
  74. ;;
  75. *)
  76. usage
  77. ;;
  78. esac
  79. done
  80. if [ -n "$dev" ]; then
  81. source setup_loopback.sh
  82. else
  83. source setup_veth.sh
  84. fi
  85. setup
  86. trap cleanup EXIT
  87. if [[ "${test}" == "all" ]]; then
  88. run_all_tests
  89. else
  90. run_test "${proto}" "${test}"
  91. fi;