Skip to content

Commit bf0ecdc

Browse files
committed
CI: Fix POSIX compliance
This replaces bash-specific syntax with POSIX-compliant alternatives for better portability across different shell environments.
1 parent f4070d9 commit bf0ecdc

File tree

4 files changed

+71
-20
lines changed

4 files changed

+71
-20
lines changed

.ci/boot-linux-prepare.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ which mkfs.ext4 > /dev/null 2>&1 || which $(brew --prefix e2fsprogs)/sbin/mkfs.e
1616
echo "Error: mkfs.ext4 not found"
1717
exit 1
1818
}
19-
which 7z > /dev/null 2>&1 || {
20-
echo "Error: 7z not found"
21-
exit 1
22-
}
19+
# Optional tooling used later in the test suite
20+
if ! command -v debugfs > /dev/null 2>&1 && ! command -v 7z > /dev/null 2>&1; then
21+
print_warning "Neither debugfs nor 7z is available; virtio-blk verification will be skipped."
22+
fi
2323

2424
ACTION=$1
2525

.ci/boot-linux.sh

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,54 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
66

77
check_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
155206
done
156207

157208
exit ${ret}

.ci/gdbstub-test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ prefixes=("${CROSS_COMPILE}" "riscv32-unknown-elf-" "riscv-none-elf-")
99
for prefix in "${prefixes[@]}"; do
1010
utility=${prefix}gdb
1111
set +e # temporarily disable exit on error
12-
command -v "${utility}" &> /dev/null
13-
if [[ $? == 0 ]]; then
12+
command -v "${utility}" > /dev/null 2>&1
13+
if [ $? = 0 ]; then
1414
GDB=${utility}
1515
fi
1616
set -e

.ci/riscv-toolchain-install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
99
check_platform
1010
mkdir -p toolchain
1111

12-
if [[ "$#" == "0" ]] || [[ "$1" != "riscv-collab" ]]; then
12+
if [ "$#" = "0" ] || [ "$1" != "riscv-collab" ]; then
1313
GCC_VER=15.2.0-1
1414
TOOLCHAIN_REPO=https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack
1515

16-
if [[ "${OS_TYPE}" == "Linux" ]]; then
16+
if [ "${OS_TYPE}" = "Linux" ]; then
1717
case "${MACHINE_TYPE}" in
1818
"x86_64")
1919
TOOLCHAIN_URL=${TOOLCHAIN_REPO}/releases/download/v${GCC_VER}/xpack-riscv-none-elf-gcc-${GCC_VER}-linux-x64.tar.gz

0 commit comments

Comments
 (0)