|
| 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 | +while [ "$SEARCH" != "/" ]; do |
| 11 | + if [ -f "$SEARCH/init_env" ]; then |
| 12 | + INIT_ENV="$SEARCH/init_env" |
| 13 | + break |
| 14 | + fi |
| 15 | + SEARCH=$(dirname "$SEARCH") |
| 16 | +done |
| 17 | + |
| 18 | +if [ -z "$INIT_ENV" ]; then |
| 19 | + echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2 |
| 20 | + exit 1 |
| 21 | +fi |
| 22 | + |
| 23 | +# shellcheck disable=SC1090 |
| 24 | +. "$INIT_ENV" |
| 25 | + |
| 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 "$TESTNAME FAIL" > "./$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 | +log_info "Checking dependencies: ip, ping" |
| 43 | +check_dependencies ip ping |
| 44 | + |
| 45 | +IFACE="eth0" |
| 46 | +MAX_RETRIES=3 |
| 47 | +RETRY_DELAY=3 |
| 48 | + |
| 49 | +log_info "Validating interface $IFACE..." |
| 50 | + |
| 51 | +# Check if interface exists |
| 52 | +if ! ip link show "$IFACE" >/dev/null 2>&1; then |
| 53 | + log_fail "Interface $IFACE not found" |
| 54 | + echo "$TESTNAME FAIL" > "$res_file" |
| 55 | + exit 1 |
| 56 | +fi |
| 57 | + |
| 58 | +# Try to bring interface up if not up |
| 59 | +if ! ip link show "$IFACE" | grep -q "state UP"; then |
| 60 | + log_warn "$IFACE is down, attempting to bring it up..." |
| 61 | + ip link set "$IFACE" up |
| 62 | + sleep "$RETRY_DELAY" |
| 63 | + if ! ip link show "$IFACE" | grep -q "state UP"; then |
| 64 | + log_fail "Failed to bring up $IFACE" |
| 65 | + echo "$TESTNAME FAIL" > "$res_file" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | +fi |
| 69 | + |
| 70 | +# Optional: Check if IP is assigned |
| 71 | +ip_addr=$(ip -4 addr show "$IFACE" | awk '/inet / {print $2}' | cut -d/ -f1) |
| 72 | +if [ -z "$ip_addr" ]; then |
| 73 | + log_warn "$IFACE has no IPv4 address assigned" |
| 74 | +fi |
| 75 | + |
| 76 | +# Run ping test |
| 77 | +log_info "Pinging 8.8.8.8 from $IFACE..." |
| 78 | +if ping -I "$IFACE" -c 4 -W 2 8.8.8.8 >/dev/null 2>&1; then |
| 79 | + log_pass "Ethernet ping test succeeded" |
| 80 | + echo "$TESTNAME PASS" > "$res_file" |
| 81 | + exit 0 |
| 82 | +else |
| 83 | + log_fail "Ethernet ping test failed" |
| 84 | + echo "$TESTNAME FAIL" > "$res_file" |
| 85 | + exit 1 |
| 86 | +fi |
| 87 | + |
0 commit comments