xref: /openbmc/linux/tools/testing/selftests/net/gro.sh (revision 9af771d2)
17d157501SCoco Li#!/bin/bash
27d157501SCoco Li# SPDX-License-Identifier: GPL-2.0
37d157501SCoco Li
47d157501SCoco Lireadonly SERVER_MAC="aa:00:00:00:00:02"
57d157501SCoco Lireadonly CLIENT_MAC="aa:00:00:00:00:01"
67d157501SCoco Lireadonly TESTS=("data" "ack" "flags" "tcp" "ip" "large")
77d157501SCoco Lireadonly PROTOS=("ipv4" "ipv6")
8*9af771d2SPaolo Abenidev=""
97d157501SCoco Litest="all"
107d157501SCoco Liproto="ipv4"
117d157501SCoco Li
127d157501SCoco Lirun_test() {
137d157501SCoco Li  local server_pid=0
147d157501SCoco Li  local exit_code=0
157d157501SCoco Li  local protocol=$1
167d157501SCoco Li  local test=$2
177d157501SCoco Li  local ARGS=( "--${protocol}" "--dmac" "${SERVER_MAC}" \
187d157501SCoco Li  "--smac" "${CLIENT_MAC}" "--test" "${test}" "--verbose" )
197d157501SCoco Li
207d157501SCoco Li  setup_ns
217d157501SCoco Li  # Each test is run 3 times to deflake, because given the receive timing,
227d157501SCoco Li  # not all packets that should coalesce will be considered in the same flow
237d157501SCoco Li  # on every try.
247d157501SCoco Li  for tries in {1..3}; do
257d157501SCoco Li    # Actual test starts here
267d157501SCoco Li    ip netns exec server_ns ./gro "${ARGS[@]}" "--rx" "--iface" "server" \
277d157501SCoco Li      1>>log.txt &
287d157501SCoco Li    server_pid=$!
297d157501SCoco Li    sleep 0.5  # to allow for socket init
307d157501SCoco Li    ip netns exec client_ns ./gro "${ARGS[@]}" "--iface" "client" \
317d157501SCoco Li      1>>log.txt
327d157501SCoco Li    wait "${server_pid}"
337d157501SCoco Li    exit_code=$?
347d157501SCoco Li    if [[ "${exit_code}" -eq 0 ]]; then
357d157501SCoco Li        break;
367d157501SCoco Li    fi
377d157501SCoco Li  done
387d157501SCoco Li  cleanup_ns
397d157501SCoco Li  echo ${exit_code}
407d157501SCoco Li}
417d157501SCoco Li
427d157501SCoco Lirun_all_tests() {
437d157501SCoco Li  local failed_tests=()
447d157501SCoco Li  for proto in "${PROTOS[@]}"; do
457d157501SCoco Li    for test in "${TESTS[@]}"; do
467d157501SCoco Li      echo "running test ${proto} ${test}" >&2
477d157501SCoco Li      exit_code=$(run_test $proto $test)
487d157501SCoco Li      if [[ "${exit_code}" -ne 0 ]]; then
497d157501SCoco Li        failed_tests+=("${proto}_${test}")
507d157501SCoco Li      fi;
517d157501SCoco Li    done;
527d157501SCoco Li  done
537d157501SCoco Li  if [[ ${#failed_tests[@]} -ne 0 ]]; then
547d157501SCoco Li    echo "failed tests: ${failed_tests[*]}. \
557d157501SCoco Li    Please see log.txt for more logs"
567d157501SCoco Li    exit 1
577d157501SCoco Li  else
587d157501SCoco Li    echo "All Tests Succeeded!"
597d157501SCoco Li  fi;
607d157501SCoco Li}
617d157501SCoco Li
627d157501SCoco Liusage() {
637d157501SCoco Li  echo "Usage: $0 \
647d157501SCoco Li  [-i <DEV>] \
657d157501SCoco Li  [-t data|ack|flags|tcp|ip|large] \
667d157501SCoco Li  [-p <ipv4|ipv6>]" 1>&2;
677d157501SCoco Li  exit 1;
687d157501SCoco Li}
697d157501SCoco Li
707d157501SCoco Liwhile getopts "i:t:p:" opt; do
717d157501SCoco Li  case "${opt}" in
727d157501SCoco Li    i)
737d157501SCoco Li      dev="${OPTARG}"
747d157501SCoco Li      ;;
757d157501SCoco Li    t)
767d157501SCoco Li      test="${OPTARG}"
777d157501SCoco Li      ;;
787d157501SCoco Li    p)
797d157501SCoco Li      proto="${OPTARG}"
807d157501SCoco Li      ;;
817d157501SCoco Li    *)
827d157501SCoco Li      usage
837d157501SCoco Li      ;;
847d157501SCoco Li  esac
857d157501SCoco Lidone
867d157501SCoco Li
87*9af771d2SPaolo Abeniif [ -n "$dev" ]; then
88*9af771d2SPaolo Abeni	source setup_loopback.sh
89*9af771d2SPaolo Abenielse
90*9af771d2SPaolo Abeni	source setup_veth.sh
91*9af771d2SPaolo Abenifi
92*9af771d2SPaolo Abeni
937d157501SCoco Lisetup
947d157501SCoco Litrap cleanup EXIT
957d157501SCoco Liif [[ "${test}" == "all" ]]; then
967d157501SCoco Li  run_all_tests
977d157501SCoco Lielse
987d157501SCoco Li  run_test "${proto}" "${test}"
997d157501SCoco Lifi;
100