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