Skip to content

Commit 0890602

Browse files
committed
CI: Add guestOS reboot test suite
- Store reboot test suite in a new file called reboot.sh. - The exit code of the test suite is the accumulated exit code from reboot.sh and virtio block test suite in the boot-linux.sh.
1 parent 8f9fd34 commit 0890602

File tree

2 files changed

+69
-18
lines changed

2 files changed

+69
-18
lines changed

.ci/boot-linux.sh

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ ASSERT()
6363
fi
6464
}
6565

66-
cleanup
67-
6866
ENABLE_VBLK=1
6967
VBLK_IMGS=(
7068
build/disk_ext4.img
@@ -84,31 +82,32 @@ for disk_img in "${VBLK_IMGS[@]}"; do
8482
done
8583

8684
TIMEOUT=50
87-
OPTS_BASE=" -k build/linux-image/Image"
88-
OPTS_BASE+=" -i build/linux-image/rootfs.cpio"
89-
90-
TEST_OPTIONS=("base (${OPTS_BASE})")
91-
EXPECT_CMDS=('
92-
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
93-
expect "# " { send "uname -a\n" } timeout { exit 2 }
94-
expect "riscv32 GNU/Linux" { send "\x01"; send "x" } timeout { exit 3 }
95-
')
85+
OPTS_BASE=" -k build/linux-image/Image -i build/linux-image/rootfs.cpio"
9686

9787
COLOR_G='\e[32;01m' # Green
9888
COLOR_R='\e[31;01m' # Red
9989
COLOR_Y='\e[33;01m' # Yellow
10090
COLOR_N='\e[0m' # No color
10191

92+
MESSAGES=("${COLOR_G}OK!"
93+
"${COLOR_R}Fail to boot"
94+
"${COLOR_R}Fail to login"
95+
"${COLOR_R}Fail to run commands"
96+
)
97+
98+
cleanup
99+
100+
# Reboot tests in a subshell ()
101+
(. "${SCRIPT_DIR}/reboot.sh")
102+
RET=$?
103+
104+
# VirtIO block tests
102105
for disk_img in "${VBLK_IMGS[@]}"; do
103106
TEST_OPTIONS=()
104107
EXPECT_CMDS=()
105108

106-
MESSAGES=("${COLOR_G}OK!"
107-
"${COLOR_R}Fail to boot"
108-
"${COLOR_R}Fail to login"
109-
"${COLOR_R}Fail to run commands"
110-
"${COLOR_R}Fail to find emu.txt in ${disk_img}"
111-
)
109+
# VirtIO Block Tests specific error message
110+
MESSAGES+=("${COLOR_R}Fail to find emu.txt in ${disk_img}")
112111

113112
if [ "${ENABLE_VBLK}" -eq "1" ]; then
114113
# Read-only
@@ -298,6 +297,7 @@ for disk_img in "${VBLK_IMGS[@]}"; do
298297
DONE
299298

300299
ret=$?
300+
RET=$((${RET} + ${ret}))
301301
cleanup
302302

303303
printf "\nBoot Linux Test: [ ${MESSAGES[$ret]}${COLOR_N} ]\n"
@@ -317,4 +317,4 @@ for disk_img in "${VBLK_IMGS[@]}"; do
317317
done
318318
done
319319

320-
exit ${ret}
320+
exit ${RET}

.ci/reboot.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
3+
# Get the directory of this script
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
. "${SCRIPT_DIR}/common.sh"
6+
7+
RET=0
8+
9+
# Reboot Tests
10+
# cold reboot
11+
TEST_OPTIONS=("${OPTS_BASE} (cold reboot)")
12+
EXPECT_CMDS=('
13+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
14+
expect "# " { send "uname -a\n" } timeout { exit 2 }
15+
expect "riscv32 GNU/Linux" { send "reboot\n" } timeout { exit 3 }
16+
expect -ex "cold reboot" {} timeout { exit 1 }
17+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
18+
expect "# " { send "uname -a\n" } timeout { exit 2 }
19+
expect "riscv32 GNU/Linux" { send "\x01"; send "x" } timeout { exit 3 }
20+
')
21+
# warm reboot
22+
TEST_OPTIONS+=("${OPTS_BASE} (warm reboot)")
23+
EXPECT_CMDS+=('
24+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
25+
expect "# " { send "uname -a\n" } timeout { exit 2 }
26+
expect "riscv32 GNU/Linux" { send "echo 'warm' > /sys/kernel/reboot/mode && reboot\n" } timeout { exit 3 }
27+
expect -ex "warm reboot" {} timeout { exit 1 }
28+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
29+
expect "# " { send "uname -a\n" } timeout { exit 2 }
30+
expect "riscv32 GNU/Linux" { send "\x01"; send "x" } timeout { exit 3 }
31+
')
32+
33+
for i in "${!TEST_OPTIONS[@]}"; do
34+
printf "${COLOR_Y}===== Test option: ${TEST_OPTIONS[$i]} =====${COLOR_N}\n"
35+
36+
RUN_LINUX="build/rv32emu ${TEST_OPTIONS[$i]}"
37+
38+
ASSERT expect <<- DONE
39+
set timeout ${TIMEOUT}
40+
spawn ${RUN_LINUX}
41+
${EXPECT_CMDS[$i]}
42+
DONE
43+
44+
ret=$?
45+
RET=$((${RET} + ${ret}))
46+
cleanup
47+
48+
printf "\nBoot Linux Test: [ ${MESSAGES[$ret]}${COLOR_N} ]\n"
49+
done
50+
51+
exit ${RET}

0 commit comments

Comments
 (0)