11#! /usr/bin/env bash
22
3- function cleanup {
4- sleep 1
5- pkill -9 semu
6- }
3+ # Source common functions and settings
4+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
5+ source " ${SCRIPT_DIR} /common.sh"
76
8- function ASSERT {
9- $*
10- local RES=$?
11- if [ $RES -ne 0 ]; then
12- echo ' Assert failed: "' $* ' "'
13- exit $RES
14- fi
15- }
7+ # Override timeout for netdev tests
8+ # Network tests need different timeout: 30s for Linux, 600s for macOS
9+ case " ${OS_TYPE} " in
10+ Darwin)
11+ TIMEOUT=600
12+ ;;
13+ Linux)
14+ TIMEOUT=30
15+ ;;
16+ * )
17+ TIMEOUT=30
18+ ;;
19+ esac
1620
21+ # Clean up any existing semu processes before starting tests
1722cleanup
1823
19- # macOS needs more time to boot compared to Linux, so the timeout is set to
20- # 600 seconds for macOS to handle the longer startup. For Linux, 90 seconds
21- # is sufficient due to its faster boot process.
22- UNAME_S=$( uname -s)
23- if [[ ${UNAME_S} == " Darwin" ]]; then
24- TIMEOUT=600
25- else # Linux
26- TIMEOUT=30
27- fi
28-
29- function TEST_NETDEV {
30- local NETDEV=$1
24+ # Test network device functionality
25+ TEST_NETDEV () {
26+ local NETDEV=" $1 "
3127 local CMD_PREFIX=" "
3228
33- if [ $NETDEV == tap ]; then
29+ if [ " $NETDEV " = " tap" ]; then
3430 CMD_PREFIX=" sudo "
3531 fi
3632
37- ASSERT expect << DONE
33+ ASSERT expect << DONE
3834 set timeout ${TIMEOUT}
3935 spawn ${CMD_PREFIX} make check NETDEV=${NETDEV}
4036 expect "buildroot login:" { send "root\n" } timeout { exit 1 }
@@ -56,17 +52,16 @@ ASSERT expect <<DONE
5652DONE
5753}
5854
59- # Network devices
55+ # Network devices to test
6056NETWORK_DEVICES=(tap user)
6157
6258for NETDEV in " ${NETWORK_DEVICES[@]} " ; do
6359 cleanup
6460 echo " Test network device: $NETDEV "
65- TEST_NETDEV $NETDEV
61+ TEST_NETDEV " $NETDEV "
6662done
6763
68- ret=$?
69- cleanup
64+ ret=" $? "
7065
7166MESSAGES=(" OK!" \
7267 " Fail to boot" \
@@ -75,8 +70,10 @@ MESSAGES=("OK!" \
7570 " Fail to transfer packet" \
7671)
7772
78- COLOR_G=' \e[32;01m' # Green
79- COLOR_N=' \e[0m'
80- printf " \n[ ${COLOR_G}${MESSAGES[$ret]}${COLOR_N} ]\n"
73+ if [ " $ret " -eq 0 ]; then
74+ print_success " ${MESSAGES["$ret"]} "
75+ else
76+ print_error " ${MESSAGES["$ret"]} "
77+ fi
8178
82- exit ${ ret}
79+ exit " $ ret"
0 commit comments