brintos

brintos / linux-shallow public Read only

0
0
Text · 2.2 KiB · 02c21ff Raw
105 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 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=014  local exit_code=015  local protocol=$116  local test=$217  local ARGS=( "--${protocol}" "--dmac" "${SERVER_MAC}" \18  "--smac" "${CLIENT_MAC}" "--test" "${test}" "--verbose" )19 20  setup_ns21  # 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 flow23  # on every try.24  for tries in {1..3}; do25    # Actual test starts here26    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 init30    ip netns exec $client_ns ./gro "${ARGS[@]}" "--iface" "client" \31      1>>log.txt32    wait "${server_pid}"33    exit_code=$?34    if [[ ${test} == "large" && -n "${KSFT_MACHINE_SLOW}" && \35          ${exit_code} -ne 0 ]]; then36        echo "Ignoring errors due to slow environment" 1>&237        exit_code=038    fi39    if [[ "${exit_code}" -eq 0 ]]; then40        break;41    fi42  done43  cleanup_ns44  echo ${exit_code}45}46 47run_all_tests() {48  local failed_tests=()49  for proto in "${PROTOS[@]}"; do50    for test in "${TESTS[@]}"; do51      echo "running test ${proto} ${test}" >&252      exit_code=$(run_test $proto $test)53      if [[ "${exit_code}" -ne 0 ]]; then54        failed_tests+=("${proto}_${test}")55      fi;56    done;57  done58  if [[ ${#failed_tests[@]} -ne 0 ]]; then59    echo "failed tests: ${failed_tests[*]}. \60    Please see log.txt for more logs"61    exit 162  else63    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; do76  case "${opt}" in77    i)78      dev="${OPTARG}"79      ;;80    t)81      test="${OPTARG}"82      ;;83    p)84      proto="${OPTARG}"85      ;;86    *)87      usage88      ;;89  esac90done91 92if [ -n "$dev" ]; then93	source setup_loopback.sh94else95	source setup_veth.sh96fi97 98setup99trap cleanup EXIT100if [[ "${test}" == "all" ]]; then101  run_all_tests102else103  run_test "${proto}" "${test}"104fi;105