|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +#Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. |
| 4 | +#SPDX-License-Identifier: BSD-3-Clause-Clear |
| 5 | + |
| 6 | +# Source init_env and functestlib.sh |
| 7 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 8 | +INIT_ENV="" |
| 9 | +SEARCH="$SCRIPT_DIR" |
| 10 | + |
| 11 | +while [ "$SEARCH" != "/" ]; do |
| 12 | + if [ -f "$SEARCH/init_env" ]; then |
| 13 | + INIT_ENV="$SEARCH/init_env" |
| 14 | + break |
| 15 | + fi |
| 16 | + SEARCH=$(dirname "$SEARCH") |
| 17 | +done |
| 18 | + |
| 19 | +if [ -z "$INIT_ENV" ]; then |
| 20 | + echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2 |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +# shellcheck disable=SC1090 |
| 25 | +. "$INIT_ENV" |
| 26 | +# shellcheck disable=SC1090,SC1091 |
| 27 | +. "$TOOLS/functestlib.sh" |
| 28 | + |
| 29 | +TESTNAME="Ethernet" |
| 30 | +test_path=$(find_test_case_by_name "$TESTNAME") || { |
| 31 | + log_fail "$TESTNAME : Test directory not found." |
| 32 | + echo "FAIL $TESTNAME" > "./$TESTNAME.res" |
| 33 | + exit 1 |
| 34 | +} |
| 35 | + |
| 36 | +cd "$test_path" || exit 1 |
| 37 | +res_file="./$TESTNAME.res" |
| 38 | +rm -f "$res_file" |
| 39 | + |
| 40 | +log_info "--------------------------------------------------------------------------" |
| 41 | +log_info "-------------------Starting $TESTNAME Testcase----------------------------" |
| 42 | + |
| 43 | +check_dependencies ip ping |
| 44 | + |
| 45 | +IFACE="eth0" |
| 46 | +RETRIES=3 |
| 47 | +SLEEP_SEC=3 |
| 48 | + |
| 49 | +# Check interface existence |
| 50 | +if ! ip link show "$IFACE" >/dev/null 2>&1; then |
| 51 | + log_fail "Ethernet interface $IFACE not found" |
| 52 | + echo "FAIL $TESTNAME" > "$res_file" |
| 53 | + exit 1 |
| 54 | +fi |
| 55 | + |
| 56 | +# Bring up interface with retries |
| 57 | +log_info "Ensuring $IFACE is UP..." |
| 58 | +i=0 |
| 59 | +while [ $i -lt $RETRIES ]; do |
| 60 | + ip link set "$IFACE" up |
| 61 | + sleep "$SLEEP_SEC" |
| 62 | + if ip link show "$IFACE" | grep -q "state UP"; then |
| 63 | + log_info "$IFACE is UP" |
| 64 | + break |
| 65 | + fi |
| 66 | + log_warn "$IFACE is still DOWN (attempt $((i + 1))/$RETRIES)..." |
| 67 | + i=$((i + 1)) |
| 68 | +done |
| 69 | + |
| 70 | +if [ $i -eq $RETRIES ]; then |
| 71 | + log_fail "Failed to bring up $IFACE after $RETRIES attempts" |
| 72 | + echo "FAIL $TESTNAME" > "$res_file" |
| 73 | + exit 1 |
| 74 | +fi |
| 75 | + |
| 76 | +# Ping test with retries |
| 77 | +log_info "Running ping test to 8.8.8.8 via $IFACE..." |
| 78 | +i=0 |
| 79 | +while [ $i -lt $RETRIES ]; do |
| 80 | + if ping -I "$IFACE" -c 4 -W 2 8.8.8.8 >/dev/null 2>&1; then |
| 81 | + log_pass "Ethernet connectivity verified via ping" |
| 82 | + echo "PASS $TESTNAME" > "$res_file" |
| 83 | + exit 0 |
| 84 | + fi |
| 85 | + log_warn "Ping failed (attempt $((i + 1))/$RETRIES)... retrying" |
| 86 | + sleep "$SLEEP_SEC" |
| 87 | + i=$((i + 1)) |
| 88 | +done |
| 89 | + |
| 90 | +log_fail "Ping test failed after $RETRIES attempts" |
| 91 | +echo "FAIL $TESTNAME" > "$res_file" |
| 92 | +exit 1 |
0 commit comments