Skip to content

Commit 50532e7

Browse files
Reuse Linux boot flow for virtio-net CI
Move the virtio-net validation logic into .ci/netdev.sh and invoke it from .ci/boot-linux.sh when VNET_BACKEND is set. This keeps the network-specific checks modular while reusing existing Linux boot test flow, including boot-linux-prepare.sh setup and cleanup, matching the structure used by the RTC tests. The TAP test still validates that the guest virtio_net driver binds, brings eth0 up, assigns the guest address, and can ping the host TAP gateway.
1 parent 9fe7f5d commit 50532e7

3 files changed

Lines changed: 106 additions & 67 deletions

File tree

.ci/boot-linux.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ COLOR_N='\e[0m' # No color
8585

8686
cleanup
8787

88+
# virtio-net tests
89+
if [[ -n "${VNET_BACKEND:-}" ]]; then
90+
(. "${SCRIPT_DIR}/netdev.sh")
91+
exit $?
92+
fi
93+
8894
# RTC tests in a subshell ()
8995
(. "${SCRIPT_DIR}/rtc.sh")
9096
RET=$?

.ci/netdev.sh

Lines changed: 95 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,113 @@
11
#!/usr/bin/env bash
22

3-
set -euo pipefail
4-
3+
# Get the directory of this script
54
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
65
. "${SCRIPT_DIR}/common.sh"
76

87
check_platform
98

9+
RET=0
10+
11+
backend="${VNET_BACKEND:-tap}"
12+
13+
if [[ "${backend}" != "tap" ]]; then
14+
print_error "Unsupported virtio-net backend for this test: ${backend}"
15+
exit 2
16+
fi
17+
1018
if [[ "${OS_TYPE}" != "Linux" ]]; then
11-
print_warning "Skipping virtio-net test on non-Linux host"
19+
print_warning "Skipping virtio-net TAP test on non-Linux host"
1220
exit 0
1321
fi
1422

1523
register_cleanup cleanup_emulator
1624

1725
TIMEOUT=${BOOT_TIMEOUT:-60}
1826

27+
COLOR_G='\e[32;01m' # Green
28+
COLOR_R='\e[31;01m' # Red
29+
COLOR_Y='\e[33;01m' # Yellow
30+
COLOR_N='\e[0m' # No color
31+
32+
MESSAGES=("${COLOR_G}OK!"
33+
"${COLOR_R}Fail to boot"
34+
"${COLOR_R}Fail to login"
35+
"${COLOR_R}Fail to run commands"
36+
"${COLOR_R}Fail to ping host TAP"
37+
)
38+
39+
OPTS_BASE=" -k build/linux-image/Image -i build/linux-image/rootfs.cpio"
40+
RUN_LINUX="sudo -E build/rv32emu ${OPTS_BASE} -x vnet:tap"
41+
42+
printf "${COLOR_Y}===== Test option: ${OPTS_BASE} -x vnet:tap =====${COLOR_N}\n"
43+
1944
ASSERT expect <<- DONE
20-
set timeout ${TIMEOUT}
21-
set tap_if ""
22-
23-
spawn sudo -E build/rv32emu \
24-
-k build/linux-image/Image \
25-
-i build/linux-image/rootfs.cpio \
26-
-x vnet:tap
27-
28-
expect {
29-
-re {allocated TAP interface: (tap[0-9]+)} {
30-
set tap_if \$expect_out(1,string)
31-
exp_continue
32-
}
33-
"buildroot login:" {
34-
if { "\$tap_if" == "" } {
35-
set tap_if [exec sh -c {ip -o link show | awk -F': ' '\$2 ~ /^tap[0-9]+/ {print \$2; exit}'}]
36-
}
37-
38-
exec sudo ip addr replace 192.168.100.1/24 dev \$tap_if
39-
exec sudo ip link set \$tap_if up
40-
41-
send "root\\r"
42-
}
43-
timeout {
44-
exit 1
45-
}
46-
}
47-
48-
expect "# "
49-
send "readlink /sys/bus/virtio/devices/virtio0/driver\\r"
50-
expect {
51-
"virtio_net" {}
52-
timeout { exit 2 }
53-
}
54-
55-
expect "# "
56-
send "ip link set eth0 up\\r"
57-
58-
expect "# "
59-
send "ip addr add 192.168.100.2/24 dev eth0\\r"
60-
61-
expect "# "
62-
send "ip addr show eth0\\r"
63-
expect {
64-
"192.168.100.2/24" {}
65-
timeout { exit 3 }
66-
}
67-
68-
expect "# "
69-
send "ping -c 3 -W 5 192.168.100.1\r"
70-
expect {
71-
-re {3 packets transmitted, 3 packets received|3 packets transmitted, 3 received} {
72-
send "\x01"
73-
send "x"
74-
exit 0
75-
}
76-
timeout {
77-
exit 4
78-
}
45+
set timeout ${TIMEOUT}
46+
set tap_if ""
47+
48+
spawn ${RUN_LINUX}
49+
50+
expect {
51+
-re {allocated TAP interface: (tap[0-9]+)} {
52+
set tap_if \$expect_out(1,string)
53+
exp_continue
54+
}
55+
"buildroot login:" {
56+
if { "\$tap_if" == "" } {
57+
set tap_if [exec sh -c {ip -o link show | awk -F': ' '\$2 ~ /^tap[0-9]+/ {print \$2; exit}'}]
58+
}
59+
60+
exec sudo ip addr replace 192.168.100.1/24 dev \$tap_if
61+
exec sudo ip link set \$tap_if up
62+
63+
send "root\\r"
64+
}
65+
timeout {
66+
exit 1
67+
}
68+
}
69+
70+
expect "# "
71+
send "readlink /sys/bus/virtio/devices/virtio0/driver\\r"
72+
expect {
73+
"virtio_net" {}
74+
timeout { exit 2 }
75+
}
76+
77+
expect "# "
78+
send "ip link set eth0 up\\r"
79+
80+
expect "# "
81+
send "ip addr add 192.168.100.2/24 dev eth0\\r"
82+
83+
expect "# "
84+
send "ip addr show eth0\\r"
85+
expect {
86+
"192.168.100.2/24" {}
87+
timeout { exit 3 }
88+
}
89+
90+
expect "# "
91+
send "ping -c 3 -W 5 192.168.100.1\\r"
92+
expect {
93+
-re {3 packets transmitted, 3 packets received|3 packets transmitted, 3 received} {
94+
send "\\x01"
95+
send "x"
96+
exit 0
97+
}
98+
-re {3 packets transmitted, 0 packets received|3 packets transmitted, 0 received|100% packet loss} {
99+
exit 4
100+
}
101+
timeout {
102+
exit 4
103+
}
104+
}
79105
DONE
80106

81-
print_success "virtio-net boot test passed"
107+
ret=$?
108+
RET=$((${RET} + ${ret}))
109+
cleanup
110+
111+
printf "\nVirtio-net TAP Test: [ ${MESSAGES[$ret]}${COLOR_N} ]\n"
112+
113+
exit ${RET}

.github/workflows/main.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,14 @@ jobs:
444444
fi
445445
bash -c "${BOOT_LINUX_TEST}"
446446
447-
- name: virtio-net boot test
448-
if: success() && matrix.compiler == 'gcc' && matrix.boot_type == 'interpreter'
447+
- name: virtio-net TAP boot test
448+
if: success()
449449
env:
450450
CC: ${{ steps.install_cc.outputs.cc }}
451-
BOOT_TIMEOUT: 60
451+
BOOT_TIMEOUT: ${{ matrix.timeout }}
452+
VNET_BACKEND: tap
452453
run: |
453-
.ci/test-netdev.sh
454+
bash -c "${BOOT_LINUX_TEST}"
454455
455456
# Native AArch64 on GitHub ARM runners - fast, no QEMU overhead
456457
host-arm64:

0 commit comments

Comments
 (0)