Skip to content

Commit 68fb6cd

Browse files
committed
CI: Refine Linux boot script for new feature verification
The Linux boot script previously tested both booting and VirtIO block access simultaneously. This commit refines the boot script to test each guest Linux feature independently. In addition, a new color (yellow) is introduced to clearly indicate which test is currently running in the CI, improving debugging capabilities. For future VirtIO device tests or other new features, TEST_OPTIONS and EXPECT_CMDS can be easily updated to extend the tests, enhancing the overall flexibility of the script.
1 parent 119d07a commit 68fb6cd

File tree

2 files changed

+98
-40
lines changed

2 files changed

+98
-40
lines changed

.ci/boot-linux.sh

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

3+
. .ci/common.sh
4+
5+
check_platform
6+
37
function cleanup {
48
sleep 1
59
pkill -9 rv32emu
@@ -8,9 +12,9 @@ function cleanup {
812
function ASSERT {
913
$*
1014
local RES=$?
11-
if [ $RES -ne 0 ]; then
15+
if [ ${RES} -ne 0 ]; then
1216
echo 'Assert failed: "' $* '"'
13-
exit $RES
17+
exit ${RES}
1418
fi
1519
}
1620

@@ -23,56 +27,110 @@ which mkfs.ext4 >/dev/null 2>&1 || which $(brew --prefix e2fsprogs)/sbin/mkfs.ex
2327
which 7z >/dev/null 2>&1 || ENABLE_VBLK=0
2428

2529
TIMEOUT=50
26-
OPTS=" -k build/linux-image/Image "
27-
OPTS+=" -i build/linux-image/rootfs.cpio "
28-
if [ "$ENABLE_VBLK" -eq "1" ]; then
29-
dd if=/dev/zero of=$VBLK_IMG bs=4M count=32
30-
mkfs.ext4 $VBLK_IMG || $(brew --prefix e2fsprogs)/sbin/mkfs.ext4 $VBLK_IMG
31-
OPTS+=" -x vblk:$VBLK_IMG "
32-
else
33-
printf "Virtio-blk Test...Passed\n"
34-
fi
35-
RUN_LINUX="build/rv32emu ${OPTS}"
30+
OPTS_BASE=" -k build/linux-image/Image"
31+
OPTS_BASE+=" -i build/linux-image/rootfs.cpio"
3632

37-
if [ "$ENABLE_VBLK" -eq "1" ]; then
38-
ASSERT expect <<DONE
39-
set timeout ${TIMEOUT}
40-
spawn ${RUN_LINUX}
41-
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
42-
expect "# " { send "uname -a\n" } timeout { exit 2 }
43-
expect "riscv32 GNU/Linux" { send "mkdir mnt && mount /dev/vda mnt\n" } timeout { exit 3 }
44-
expect "# " { send "echo rv32emu > mnt/emu.txt\n" } timeout { exit 3 }
45-
expect "# " { send "sync\n" } timeout { exit 3 }
46-
expect "# " { send "umount mnt\n" } timeout { exit 3 }
47-
expect "# " { send "\x01"; send "x" } timeout { exit 3 }
48-
DONE
49-
else
50-
ASSERT expect <<DONE
51-
set timeout ${TIMEOUT}
52-
spawn ${RUN_LINUX}
33+
TEST_OPTIONS=("base (${OPTS_BASE})")
34+
EXPECT_CMDS=('
5335
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
5436
expect "# " { send "uname -a\n" } timeout { exit 2 }
5537
expect "riscv32 GNU/Linux" { send "\x01"; send "x" } timeout { exit 3 }
56-
DONE
57-
fi
58-
ret=$?
59-
cleanup
38+
')
6039

6140
COLOR_G='\e[32;01m' # Green
6241
COLOR_R='\e[31;01m' # Red
42+
COLOR_Y='\e[33;01m' # Yellow
6343
COLOR_N='\e[0m' # No color
6444

6545
MESSAGES=("${COLOR_G}OK!" \
6646
"${COLOR_R}Fail to boot" \
6747
"${COLOR_R}Fail to login" \
6848
"${COLOR_R}Fail to run commands" \
69-
"${COLOR_R}Fail to find emu.txt in $VBLK_IMG"\
49+
"${COLOR_R}Fail to find emu.txt in ${VBLK_IMG}"\
7050
)
7151

72-
printf "\nBoot Linux Test: [ ${MESSAGES[$ret]}${COLOR_N} ]\n"
73-
if [ "$ENABLE_VBLK" -eq "1" ]; then
74-
7z l $VBLK_IMG | grep emu.txt >/dev/null 2>&1 || ret=4
75-
printf "Virtio-blk Test: [ ${MESSAGES[$ret]}${COLOR_N} ]\n"
52+
if [ "${ENABLE_VBLK}" -eq "1" ]; then
53+
dd if=/dev/zero of=${VBLK_IMG} bs=4M count=32
54+
mkfs.ext4 ${VBLK_IMG} || $(brew --prefix e2fsprogs)/sbin/mkfs.ext4 ${VBLK_IMG}
55+
56+
# Setup a /dev/ block device with ${VBLK_IMG} to test guestOS access to hostOS /dev/ block device
57+
case "${OS_TYPE}" in
58+
Linux)
59+
BLK_DEV=$(losetup -f)
60+
losetup ${BLK_DEV} ${VBLK_IMG}
61+
;;
62+
Darwin)
63+
BLK_DEV=$(hdiutil attach -nomount ${VBLK_IMG})
64+
;;
65+
esac
66+
67+
# Read-only
68+
TEST_OPTIONS+=("${OPTS_BASE} -x vblk:${VBLK_IMG},readonly")
69+
EXPECT_CMDS+=('
70+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
71+
expect "# " { send "uname -a\n" } timeout { exit 2 }
72+
expect "riscv32 GNU/Linux" { send "mkdir mnt && mount /dev/vda mnt\n" } timeout { exit 3 }
73+
expect "# " { send "echo rv32emu > mnt/emu.txt\n" } timeout { exit 3 }
74+
expect -ex "-sh: can'\''t create mnt/emu.txt: Read-only file system" {} timeout { exit 3 }
75+
expect "# " { send "\x01"; send "x" } timeout { exit 3 }
76+
')
77+
78+
# Read-write using disk image
79+
TEST_OPTIONS+=("${OPTS_BASE} -x vblk:${VBLK_IMG}")
80+
VBLK_EXPECT_CMDS='
81+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
82+
expect "# " { send "uname -a\n" } timeout { exit 2 }
83+
expect "riscv32 GNU/Linux" { send "mkdir mnt && mount /dev/vda mnt\n" } timeout { exit 3 }
84+
expect "# " { send "echo rv32emu > mnt/emu.txt\n" } timeout { exit 3 }
85+
expect "# " { send "sync\n" } timeout { exit 3 }
86+
expect "# " { send "umount mnt\n" } timeout { exit 3 }
87+
expect "# " { send "\x01"; send "x" } timeout { exit 3 }
88+
'
89+
EXPECT_CMDS+=("${VBLK_EXPECT_CMDS}")
90+
91+
# Read-write using /dev/loopx(Linux) or /dev/diskx(Darwin) block device
92+
TEST_OPTIONS+=("${OPTS_BASE} -x vblk:${BLK_DEV}")
93+
EXPECT_CMDS+=("${VBLK_EXPECT_CMDS}")
7694
fi
7795

96+
for i in "${!TEST_OPTIONS[@]}"; do
97+
echo -e "\n${COLOR_Y}===== Test option: ${TEST_OPTIONS[$i]} =====${COLOR_N}"
98+
99+
OPTS="${OPTS_BASE}"
100+
# No need to add option when running base test
101+
if [[ ! "${TEST_OPTIONS[$i]}" =~ "base" ]]; then
102+
OPTS+="${TEST_OPTIONS[$i]}"
103+
fi
104+
RUN_LINUX="build/rv32emu ${OPTS}"
105+
106+
ASSERT expect <<-DONE
107+
set timeout ${TIMEOUT}
108+
spawn ${RUN_LINUX}
109+
${EXPECT_CMDS[$i]}
110+
DONE
111+
112+
ret=$?
113+
cleanup
114+
115+
printf "\nBoot Linux Test: [ ${MESSAGES[$ret]}${COLOR_N} ]\n"
116+
if [[ "${TEST_OPTIONS[$i]}" =~ vblk ]]; then
117+
# read-only test first, so the emu.txt definitely does not exist, skipping the check
118+
if [[ ! "${TEST_OPTIONS[$i]}" =~ readonly ]]; then
119+
7z l ${VBLK_IMG} | grep emu.txt >/dev/null 2>&1 || ret=4
120+
fi
121+
# Detach the /dev/loopx(Linux) or /dev/diskx(Darwin) to release system resources
122+
if [[ "${TEST_OPTIONS[$i]}" =~ /dev/ ]]; then
123+
case "${OS_TYPE}" in
124+
Linux)
125+
losetup -d ${BLK_DEV}
126+
;;
127+
Darwin)
128+
hdiutil detach ${BLK_DEV}
129+
;;
130+
esac
131+
fi
132+
printf "Virtio-blk Test: [ ${MESSAGES[$ret]}${COLOR_N} ]\n"
133+
fi
134+
done
135+
78136
exit ${ret}

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,15 @@ jobs:
265265
CC: ${{ steps.install_cc.outputs.cc }}
266266
run: |
267267
make distclean && make INITRD_SIZE=32 ENABLE_SYSTEM=1 $PARALLEL && make ENABLE_SYSTEM=1 artifact $PARALLEL
268-
.ci/boot-linux.sh
268+
sudo .ci/boot-linux.sh
269269
make ENABLE_SYSTEM=1 clean
270270
if: ${{ always() }}
271271
- name: boot Linux kernel test (JIT)
272272
env:
273273
CC: ${{ steps.install_cc.outputs.cc }}
274274
run: |
275275
make distclean && make INITRD_SIZE=32 ENABLE_SYSTEM=1 ENABLE_JIT=1 ENABLE_T2C=0 ENABLE_MOP_FUSION=0 $PARALLEL && make ENABLE_SYSTEM=1 artifact $PARALLEL
276-
.ci/boot-linux.sh
276+
sudo .ci/boot-linux.sh
277277
make ENABLE_SYSTEM=1 ENABLE_JIT=1 ENABLE_T2C=0 ENABLE_MOP_FUSION=0 clean
278278
if: ${{ always() }}
279279
- name: Architecture test
@@ -463,7 +463,7 @@ jobs:
463463
run: |
464464
make distclean && make INITRD_SIZE=32 ENABLE_SYSTEM=1 $PARALLEL && \
465465
make ENABLE_SYSTEM=1 artifact $PARALLEL
466-
.ci/boot-linux.sh
466+
sudo .ci/boot-linux.sh
467467
make ENABLE_SYSTEM=1 clean
468468
if: ${{ always() }}
469469
- name: Architecture test

0 commit comments

Comments
 (0)