@@ -6,13 +6,54 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
66
77check_platform
88
9- function cleanup
9+ cleanup ()
1010{
1111 sleep 1
1212 pkill -9 rv32emu
1313}
1414
15- function ASSERT
15+ check_image_for_file ()
16+ {
17+ local image_path=$1
18+ local file_path=$2
19+ local tool_available=0
20+ local debugfs_cmd
21+
22+ debugfs_cmd=$( command -v debugfs 2> /dev/null || true)
23+ if [ -z " ${debugfs_cmd} " ] && [ -x /sbin/debugfs ]; then
24+ debugfs_cmd=/sbin/debugfs
25+ fi
26+
27+ if [ -n " ${debugfs_cmd} " ]; then
28+ tool_available=1
29+ if " ${debugfs_cmd} " -R " stat ${file_path} " " ${image_path} " > /dev/null 2>&1 ; then
30+ return 0
31+ fi
32+ fi
33+
34+ if command -v 7z > /dev/null 2>&1 ; then
35+ tool_available=1
36+ if 7z l " ${image_path} " | grep -q " ${file_path} " ; then
37+ return 0
38+ fi
39+ fi
40+
41+ if [ -n " ${debugfs_cmd} " ]; then
42+ tool_available=1
43+ if sudo " ${debugfs_cmd} " -R " stat ${file_path} " " ${image_path} " > /dev/null 2>&1 ; then
44+ return 0
45+ fi
46+ fi
47+
48+ if [ " ${tool_available} " -eq 0 ]; then
49+ print_warning " Skipping verification of ${file_path} in ${image_path} : neither debugfs nor 7z is available."
50+ return 0
51+ fi
52+
53+ return 1
54+ }
55+
56+ ASSERT ()
1657{
1758 $*
1859 local RES=$?
@@ -130,9 +171,12 @@ for i in "${!TEST_OPTIONS[@]}"; do
130171
131172 OPTS=" ${OPTS_BASE} "
132173 # No need to add option when running base test
133- if [[ ! " ${TEST_OPTIONS[$i]} " =~ " base" ]]; then
134- OPTS+=" ${TEST_OPTIONS[$i]} "
135- fi
174+ case " ${TEST_OPTIONS[$i]} " in
175+ * base* ) ;;
176+ * )
177+ OPTS+=" ${TEST_OPTIONS[$i]} "
178+ ;;
179+ esac
136180 RUN_LINUX=" build/rv32emu ${OPTS} "
137181
138182 ASSERT expect << - DONE
@@ -145,13 +189,20 @@ for i in "${!TEST_OPTIONS[@]}"; do
145189 cleanup
146190
147191 printf " \nBoot Linux Test: [ ${MESSAGES[$ret]}${COLOR_N} ]\n"
148- if [[ " ${TEST_OPTIONS[$i]} " =~ vblk ]]; then
149- # read-only test first, so the emu.txt definitely does not exist, skipping the check
150- if [[ ! " ${TEST_OPTIONS[$i]} " =~ readonly ]]; then
151- 7z l ${VBLK_IMG} | grep emu.txt > /dev/null 2>&1 || ret=4
152- fi
153- printf " Virtio-blk Test: [ ${MESSAGES[$ret]}${COLOR_N} ]\n"
154- fi
192+ case " ${TEST_OPTIONS[$i]} " in
193+ * vblk* )
194+ # read-only test first, so the emu.txt definitely does not exist, skipping the check
195+ case " ${TEST_OPTIONS[$i]} " in
196+ * readonly* ) ;;
197+ * )
198+ if ! check_image_for_file " ${VBLK_IMG} " emu.txt; then
199+ ret=4
200+ fi
201+ ;;
202+ esac
203+ printf " Virtio-blk Test: [ ${MESSAGES[$ret]}${COLOR_N} ]\n"
204+ ;;
205+ esac
155206done
156207
157208exit ${ret}
0 commit comments