Skip to content

Commit

Permalink
CI: Add test for different network devices
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chiangkd committed Nov 26, 2024
1 parent c0263f3 commit 92d9166
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
79 changes: 79 additions & 0 deletions .ci/test-netdev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env bash

function cleanup {
sleep 1
pkill -9 semu
}

function ASSERT {
$*
local RES=$?
if [ $RES -ne 0 ]; then
echo 'Assert failed: "' $* '"'
exit $RES
fi
}

cleanup

# macOS needs more time to boot compared to Linux, so the timeout is set to
# 600 seconds for macOS to handle the longer startup. For Linux, 90 seconds
# is sufficient due to its faster boot process.
UNAME_S=$(uname -s)
if [[ ${UNAME_S} == "Darwin" ]]; then
TIMEOUT=600
else # Linux
TIMEOUT=30
fi

function TEST_NETDEV {
local NETDEV=$1
local CMD_PREFIX=""

if [ $NETDEV == tap ]; then
CMD_PREFIX="sudo "
fi

ASSERT expect <<DONE
set timeout ${TIMEOUT}
spawn ${CMD_PREFIX}make check NETDEV=${NETDEV}
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
expect "# " { send "uname -a\n" } timeout { exit 2 }
if { "$NETDEV" == "tap" } {
exec sudo ip addr add 192.168.10.1/24 dev tap0
exec sudo ip link set tap0 up
expect "riscv32 GNU/Linux" { send "ip l set eth0 up\n" } timeout { exit 3 }
expect "# " { send "ip a add 192.168.10.2/24 dev eth0\n" }
expect "# " { send "ping -c 3 192.168.10.1\n" }
expect "3 packets transmitted, 3 packets received, 0% packet loss" { } timeout { exit 4 }
} elseif { "$NETDEV" == "user" } {
# Test slirp configuration
expect "riscv32 GNU/Linux" { send "\x01"; send "x" } timeout { exit 3 }
}
DONE
}

# Network devices
NETWORK_DEVICES=(tap user)

for NETDEV in "${NETWORK_DEVICES[@]}"; do
cleanup
echo "Test network device: $NETDEV"
TEST_NETDEV $NETDEV
done

ret=$?
cleanup

MESSAGES=("OK!" \
"Fail to boot" \
"Fail to login" \
"Fail to run commands" \
"Fail to transfer packet" \
)

COLOR_G='\e[32;01m' # Green
COLOR_N='\e[0m'
printf "\n[ ${COLOR_G}${MESSAGES[$ret]}${COLOR_N} ]\n"

exit ${ret}
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ jobs:
- name: automated test
run: .ci/autorun.sh
shell: bash
- name: netdev test
run: .ci/test-netdev.sh
shell: bash
if: ${{ success() }}

semu-macOS:
runs-on: macos-latest
Expand Down

0 comments on commit 92d9166

Please sign in to comment.