Skip to content

Commit b10b1ee

Browse files
committed
CI: Add test for different network devices
To support future development, tests are added for different network devices. ICMP packet transmission is used to verify link functionality between virtio-net and other network devices, such as TAP.
1 parent 0bd4ef6 commit b10b1ee

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

.ci/test-netdev.sh

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env bash
2+
3+
function cleanup {
4+
sleep 1
5+
pkill -9 semu
6+
}
7+
8+
function ASSERT {
9+
$*
10+
local RES=$?
11+
if [ $RES -ne 0 ]; then
12+
echo 'Assert failed: "' $* '"'
13+
exit $RES
14+
fi
15+
}
16+
17+
cleanup
18+
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
31+
local CMD_PREFIX=""
32+
33+
if [ $NETDEV == tap ]; then
34+
CMD_PREFIX="sudo "
35+
fi
36+
37+
ASSERT expect <<DONE
38+
set timeout ${TIMEOUT}
39+
spawn ${CMD_PREFIX}make check NETDEV=${NETDEV}
40+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
41+
expect "# " { send "uname -a\n" } timeout { exit 2 }
42+
if { "$NETDEV" == "tap" } {
43+
exec sudo ip addr add 192.168.10.1/24 dev tap0
44+
exec sudo ip link set tap0 up
45+
expect "riscv32 GNU/Linux" { send "ip l set eth0 up\n" } timeout { exit 3 }
46+
expect "# " { send "ip a add 192.168.10.2/24 dev eth0\n" }
47+
expect "# " { send "ping -c 3 192.168.10.1\n" }
48+
expect "3 packets transmitted, 3 packets received, 0% packet loss" { } timeout { exit 4 }
49+
} elseif { "$NETDEV" == "user" } {
50+
# Test slirp configuration
51+
expect "riscv32 GNU/Linux" { send "\x01"; send "x" } timeout { exit 3 }
52+
}
53+
DONE
54+
}
55+
56+
# Network devices
57+
NETWORK_DEVICES=(tap user)
58+
59+
for NETDEV in "${NETWORK_DEVICES[@]}"; do
60+
cleanup
61+
echo "Test network device: $NETDEV"
62+
TEST_NETDEV $NETDEV
63+
done
64+
65+
ret=$?
66+
cleanup
67+
68+
MESSAGES=("OK!" \
69+
"Fail to boot" \
70+
"Fail to login" \
71+
"Fail to run commands" \
72+
"Fail to transfer packet" \
73+
)
74+
75+
COLOR_G='\e[32;01m' # Green
76+
COLOR_N='\e[0m'
77+
printf "\n[ ${COLOR_G}${MESSAGES[$ret]}${COLOR_N} ]\n"
78+
79+
exit ${ret}

.github/workflows/main.yml

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ jobs:
1616
- name: automated test
1717
run: .ci/autorun.sh
1818
shell: bash
19+
- name: netdev test
20+
run: .ci/test-netdev.sh
21+
shell: bash
22+
if: ${{ success() }}
1923

2024
semu-macOS:
2125
runs-on: macos-latest

0 commit comments

Comments
 (0)