Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/rtl8127-omega/blob/main/cmd/rtl8127d/test/run.sh # rtl8127-omega aien-dev/rtl8127-omega Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `rtl8127-omega / cmd / rtl8127d / test / run.sh` 52 lines ยท 3015 bytes Raw Blame History 1 #!/bin/sh 2 # SPDX-License-Identifier: Apache-2.0 3 # rtl8127-probe against a FAKE BAR file (no device). Usage: sh cmd/rtl8127d/test/run.sh OMC 4 # Checks: a good RTL8127 image prints the right id, both MAC addresses and the link; the wrong chip, an all-ones image and a missing 5 # file are refused with their own exit codes; the file is not modified (read-only). Never touches a real device. 6 set -eu 7 omc=${1:?usage: run.sh OMC} 8 here=$(cd "$(dirname "$0")" && pwd) 9 root=$(cd "$here/../../.." && pwd) 10 out="$root/build/test/probe" 11 rm -rf "$out"; mkdir -p "$out" 12 fail=0 13 cat "$root/om/rtl8127/rtl8127.om" "$root/om/rtl8127/hw.om" "$root/cmd/rtl8127d/probe.om" | "$omc" > "$out/probe" 2> "$out/err" || { echo "probe: omc failed: $(cat "$out/err")"; exit 1; } 14 chmod +x "$out/probe" 15 16 poke() { # poke FILE OFFSET HEXBYTES... (little-endian bytes in file order) 17 f=$1; o=$2; shift 2 18 for b in "$@"; do printf "\\$(printf %03o "0x$b")" | dd of="$f" bs=1 seek="$o" conv=notrunc 2>/dev/null; o=$((o + 1)); done 19 } 20 newbar() { dd if=/dev/zero of="$1" bs=4096 count=64 2>/dev/null; } 21 22 check() { # check NAME WANT_EXIT WANT_TEXT FILE 23 rc=0; "$out/probe" "$4" > "$out/$1.out" 2> "$out/$1.err" || rc=$? 24 if [ "$rc" = "$2" ] && { [ -z "$3" ] || cat "$out/$1.out" "$out/$1.err" | grep -qF "$3"; }; then echo "probe: $1 PASS (exit $rc)"; else echo "probe: $1 FAIL (exit $rc, want $2 / '$3')"; cat "$out/$1.out" "$out/$1.err"; fail=1; fi 25 } 26 27 good="$out/bar-good"; newbar "$good" 28 poke "$good" 64 00 00 90 6c # TxConfig 0x6c900000: RTL8127, IC version 1 29 poke "$good" 0 a0 a1 a2 a3 a4 a5 # MAC0 30 poke "$good" 6624 48 11 22 33 44 55 # backup address 31 poke "$good" 108 03 40 # PHYstatus: link up, 10 Gb/s 32 sum1=$(sha256sum "$good" | cut -d' ' -f1) 33 check good 0 "TxConfig 0x6c900000" "$good" 34 grep -qF "MAC (backup) 48:11:22:33:44:55" "$out/good.out" && echo "probe: backup MAC PASS" || { echo "probe: backup MAC FAIL"; fail=1; } 35 grep -qF "MAC (current) a0:a1:a2:a3:a4:a5" "$out/good.out" && echo "probe: current MAC PASS" || { echo "probe: current MAC FAIL"; fail=1; } 36 grep -qF "link up, Mb/s 10000" "$out/good.out" && echo "probe: link PASS" || { echo "probe: link FAIL"; fail=1; } 37 grep -qF "read-only, nothing was written" "$out/good.out" && echo "probe: read-only notice PASS" || { echo "probe: notice FAIL"; fail=1; } 38 [ "$(sha256sum "$good" | cut -d' ' -f1)" = "$sum1" ] && echo "probe: file unchanged PASS" || { echo "probe: file CHANGED FAIL"; fail=1; } 39 40 down="$out/bar-down"; cp "$good" "$down"; poke "$down" 108 00 00 41 check down 0 "link down" "$down" 42 43 wrong="$out/bar-wrong"; cp "$good" "$wrong"; poke "$wrong" 64 00 00 00 54 44 check wrong-chip 14 "not an RTL8127" "$wrong" 45 46 ones="$out/bar-ones"; newbar "$ones"; tr '\000' '\377' < "$ones" > "$ones.x"; mv "$ones.x" "$ones" 47 check absent 13 "all ones" "$ones" 48 49 check missing 11 "" "$out/does-not-exist" 50 rc=0; "$out/probe" > /dev/null 2>&1 || rc=$? 51 [ "$rc" = 10 ] && echo "probe: usage exit 10 PASS" || { echo "probe: usage FAIL (exit $rc)"; fail=1; } 52 exit $fail