Skip to content

Commit 1cfeeda

Browse files
committed
Apply shfmt to existing shell script
shfmt -w $(find . -type f -name "*.sh")
1 parent 82b4adc commit 1cfeeda

File tree

7 files changed

+61
-53
lines changed

7 files changed

+61
-53
lines changed

.ci/boot-linux-prepare.sh

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@
55
check_platform
66

77
VBLK_IMG=build/disk.img
8-
which dd >/dev/null 2>&1 || { echo "Error: dd not found"; exit 1; }
9-
which mkfs.ext4 >/dev/null 2>&1 || which $(brew --prefix e2fsprogs)/sbin/mkfs.ext4 >/dev/null 2>&1 || \
10-
{ echo "Error: mkfs.ext4 not found"; exit 1; }
11-
which 7z >/dev/null 2>&1 || { echo "Error: 7z not found"; exit 1; }
8+
which dd > /dev/null 2>&1 || {
9+
echo "Error: dd not found"
10+
exit 1
11+
}
12+
which mkfs.ext4 > /dev/null 2>&1 || which $(brew --prefix e2fsprogs)/sbin/mkfs.ext4 > /dev/null 2>&1 \
13+
|| {
14+
echo "Error: mkfs.ext4 not found"
15+
exit 1
16+
}
17+
which 7z > /dev/null 2>&1 || {
18+
echo "Error: 7z not found"
19+
exit 1
20+
}
1221

1322
ACTION=$1
1423

@@ -23,11 +32,11 @@ case "$ACTION" in
2332
mkfs.ext4 ${VBLK_IMG}
2433
BLK_DEV=$(losetup -f)
2534
losetup ${BLK_DEV} ${VBLK_IMG}
26-
;;
35+
;;
2736
Darwin)
2837
$(brew --prefix e2fsprogs)/sbin/mkfs.ext4 ${VBLK_IMG}
2938
BLK_DEV=$(hdiutil attach -nomount ${VBLK_IMG})
30-
;;
39+
;;
3140
esac
3241

3342
# On Linux, ${VBLK_IMG} will be created by root and owned by root:root.
@@ -48,10 +57,10 @@ case "$ACTION" in
4857
case "${OS_TYPE}" in
4958
Linux)
5059
losetup -d ${BLK_DEV}
51-
;;
60+
;;
5261
Darwin)
5362
hdiutil detach ${BLK_DEV}
54-
;;
63+
;;
5564
esac
5665

5766
# delete disk image

.ci/boot-linux.sh

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
check_platform
66

7-
function cleanup {
7+
function cleanup
8+
{
89
sleep 1
910
pkill -9 rv32emu
1011
}
1112

12-
function ASSERT {
13+
function ASSERT
14+
{
1315
$*
1416
local RES=$?
1517
if [ ${RES} -ne 0 ]; then
@@ -30,45 +32,45 @@ OPTS_BASE+=" -i build/linux-image/rootfs.cpio"
3032

3133
TEST_OPTIONS=("base (${OPTS_BASE})")
3234
EXPECT_CMDS=('
33-
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
34-
expect "# " { send "uname -a\n" } timeout { exit 2 }
35-
expect "riscv32 GNU/Linux" { send "\x01"; send "x" } timeout { exit 3 }
35+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
36+
expect "# " { send "uname -a\n" } timeout { exit 2 }
37+
expect "riscv32 GNU/Linux" { send "\x01"; send "x" } timeout { exit 3 }
3638
')
3739

3840
COLOR_G='\e[32;01m' # Green
3941
COLOR_R='\e[31;01m' # Red
4042
COLOR_Y='\e[33;01m' # Yellow
41-
COLOR_N='\e[0m' # No color
43+
COLOR_N='\e[0m' # No color
4244

43-
MESSAGES=("${COLOR_G}OK!" \
44-
"${COLOR_R}Fail to boot" \
45-
"${COLOR_R}Fail to login" \
46-
"${COLOR_R}Fail to run commands" \
47-
"${COLOR_R}Fail to find emu.txt in ${VBLK_IMG}"\
45+
MESSAGES=("${COLOR_G}OK!"
46+
"${COLOR_R}Fail to boot"
47+
"${COLOR_R}Fail to login"
48+
"${COLOR_R}Fail to run commands"
49+
"${COLOR_R}Fail to find emu.txt in ${VBLK_IMG}"
4850
)
4951

5052
if [ "${ENABLE_VBLK}" -eq "1" ]; then
5153
# Read-only
5254
TEST_OPTIONS+=("${OPTS_BASE} -x vblk:${VBLK_IMG},readonly")
5355
EXPECT_CMDS+=('
54-
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
55-
expect "# " { send "uname -a\n" } timeout { exit 2 }
56-
expect "riscv32 GNU/Linux" { send "mkdir mnt && mount /dev/vda mnt\n" } timeout { exit 3 }
57-
expect "# " { send "echo rv32emu > mnt/emu.txt\n" } timeout { exit 3 }
58-
expect -ex "-sh: can'\''t create mnt/emu.txt: Read-only file system" {} timeout { exit 3 }
59-
expect "# " { send "\x01"; send "x" } timeout { exit 3 }
56+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
57+
expect "# " { send "uname -a\n" } timeout { exit 2 }
58+
expect "riscv32 GNU/Linux" { send "mkdir mnt && mount /dev/vda mnt\n" } timeout { exit 3 }
59+
expect "# " { send "echo rv32emu > mnt/emu.txt\n" } timeout { exit 3 }
60+
expect -ex "-sh: can'\''t create mnt/emu.txt: Read-only file system" {} timeout { exit 3 }
61+
expect "# " { send "\x01"; send "x" } timeout { exit 3 }
6062
')
6163

6264
# Read-write using disk image
6365
TEST_OPTIONS+=("${OPTS_BASE} -x vblk:${VBLK_IMG}")
6466
VBLK_EXPECT_CMDS='
65-
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
66-
expect "# " { send "uname -a\n" } timeout { exit 2 }
67-
expect "riscv32 GNU/Linux" { send "mkdir mnt && mount /dev/vda mnt\n" } timeout { exit 3 }
68-
expect "# " { send "echo rv32emu > mnt/emu.txt\n" } timeout { exit 3 }
69-
expect "# " { send "sync\n" } timeout { exit 3 }
70-
expect "# " { send "umount mnt\n" } timeout { exit 3 }
71-
expect "# " { send "\x01"; send "x" } timeout { exit 3 }
67+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
68+
expect "# " { send "uname -a\n" } timeout { exit 2 }
69+
expect "riscv32 GNU/Linux" { send "mkdir mnt && mount /dev/vda mnt\n" } timeout { exit 3 }
70+
expect "# " { send "echo rv32emu > mnt/emu.txt\n" } timeout { exit 3 }
71+
expect "# " { send "sync\n" } timeout { exit 3 }
72+
expect "# " { send "umount mnt\n" } timeout { exit 3 }
73+
expect "# " { send "\x01"; send "x" } timeout { exit 3 }
7274
'
7375
EXPECT_CMDS+=("${VBLK_EXPECT_CMDS}")
7476

@@ -87,7 +89,7 @@ for i in "${!TEST_OPTIONS[@]}"; do
8789
fi
8890
RUN_LINUX="build/rv32emu ${OPTS}"
8991

90-
ASSERT expect <<-DONE
92+
ASSERT expect <<- DONE
9193
set timeout ${TIMEOUT}
9294
spawn ${RUN_LINUX}
9395
${EXPECT_CMDS[$i]}
@@ -100,7 +102,7 @@ for i in "${!TEST_OPTIONS[@]}"; do
100102
if [[ "${TEST_OPTIONS[$i]}" =~ vblk ]]; then
101103
# read-only test first, so the emu.txt definitely does not exist, skipping the check
102104
if [[ ! "${TEST_OPTIONS[$i]}" =~ readonly ]]; then
103-
7z l ${VBLK_IMG} | grep emu.txt >/dev/null 2>&1 || ret=4
105+
7z l ${VBLK_IMG} | grep emu.txt > /dev/null 2>&1 || ret=4
104106
fi
105107
printf "Virtio-blk Test: [ ${MESSAGES[$ret]}${COLOR_N} ]\n"
106108
fi

.ci/check-format.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ REPO_ROOT="$(git rev-parse --show-toplevel)"
1010

1111
C_SOURCES=$(find "${REPO_ROOT}" | egrep "\.(c|cxx|cpp|h|hpp)$")
1212
for file in ${C_SOURCES}; do
13-
clang-format-18 ${file} >expected-format
13+
clang-format-18 ${file} > expected-format
1414
diff -u -p --label="${file}" --label="expected coding style" ${file} expected-format
1515
done
1616
C_MISMATCH_LINE_CNT=$(clang-format-18 --output-replacements-xml ${C_SOURCES} | egrep -c "</replacement>")

.ci/common.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ OS_TYPE=$(uname -s)
66
check_platform()
77
{
88
case "${MACHINE_TYPE}/${OS_TYPE}" in
9-
x86_64/Linux | aarch64/Linux | arm64/Darwin)
10-
;;
9+
x86_64/Linux | aarch64/Linux | arm64/Darwin) ;;
10+
1111
*)
1212
echo "Unsupported platform: ${MACHINE_TYPE}/${OS_TYPE}"
1313
exit 1
@@ -16,7 +16,7 @@ check_platform()
1616
}
1717

1818
if [[ "${OS_TYPE}" == "Linux" ]]; then
19-
PARALLEL=-j$(nproc)
19+
PARALLEL=-j$(nproc)
2020
else
21-
PARALLEL=-j$(sysctl -n hw.logicalcpu)
21+
PARALLEL=-j$(sysctl -n hw.logicalcpu)
2222
fi

.ci/riscv-tests.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ make distclean
1818
# for this purpose, although the emulator can run all selected benchmarks with
1919
# much smaller memory mapping regions.
2020
make ENABLE_ARCH_TEST=1 ENABLE_EXT_M=1 ENABLE_EXT_A=1 ENABLE_EXT_F=1 ENABLE_EXT_C=1 \
21-
ENABLE_Zicsr=1 ENABLE_Zifencei=1 ENABLE_FULL4G=1 $PARALLEL
21+
ENABLE_Zicsr=1 ENABLE_Zifencei=1 ENABLE_FULL4G=1 $PARALLEL
2222
make arch-test RISCV_DEVICE=IMAFCZicsrZifencei hw_data_misaligned_support=1 $PARALLEL || exit 1
2323
make arch-test RISCV_DEVICE=FCZicsr hw_data_misaligned_support=1 $PARALLEL || exit 1
2424
make arch-test RISCV_DEVICE=IMZbaZbbZbcZbs hw_data_misaligned_support=1 $PARALLEL || exit 1
@@ -33,6 +33,6 @@ make arch-test RISCV_DEVICE=E $PARALLEL || exit 1
3333
# the hardware misalignment (hw_data_misaligned_support) option.
3434
make distclean
3535
make ENABLE_ARCH_TEST=1 ENABLE_JIT=1 ENABLE_T2C=0 \
36-
ENABLE_EXT_M=1 ENABLE_EXT_A=1 ENABLE_EXT_F=1 ENABLE_EXT_C=1 \
37-
ENABLE_Zicsr=1 ENABLE_Zifencei=1 ENABLE_FULL4G=1 $PARALLEL
36+
ENABLE_EXT_M=1 ENABLE_EXT_A=1 ENABLE_EXT_F=1 ENABLE_EXT_C=1 \
37+
ENABLE_Zicsr=1 ENABLE_Zifencei=1 ENABLE_FULL4G=1 $PARALLEL
3838
make arch-test RISCV_DEVICE=IMC hw_data_misaligned_support=0 $PARALLEL || exit 1

tests/common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function fail()
1+
function fail()
22
{
33
echo "*** Fail"
44
exit 1

tests/dhrystone.sh

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ function run_dhrystone()
2525
sanity_check
2626
# Run Dhrystone benchmark and collect DMIPS values
2727
dmips_values=()
28-
for ((i=1; i<=$N_RUNS; i++))
29-
do
28+
for ((i = 1; i <= $N_RUNS; i++)); do
3029
echo "Running Dhrystone benchmark - Run #$i"
3130
dmips=$(run_dhrystone)
3231
exit_code=$?
@@ -48,7 +47,7 @@ fi
4847

4948
deviation=0
5049
for dmips in "${sorted_dmips[@]}"; do
51-
if (( $(echo "$dmips > $median" | bc -l) )); then
50+
if (($(echo "$dmips > $median" | bc -l))); then
5251
diff=$(echo "$dmips - $median" | bc -l)
5352
else
5453
diff=$(echo "$median - $dmips" | bc -l)
@@ -60,15 +59,14 @@ mad=$(echo "scale=2; $deviation / $num_dmips" | bc -l)
6059

6160
# Filter outliers based on MAD
6261
filtered_dmips=()
63-
for dmips in "${sorted_dmips[@]}"
64-
do
65-
if (( $(echo "$dmips > 0" | bc -l) )); then
66-
if (( $(echo "$dmips > $median" | bc -l) )); then
62+
for dmips in "${sorted_dmips[@]}"; do
63+
if (($(echo "$dmips > 0" | bc -l))); then
64+
if (($(echo "$dmips > $median" | bc -l))); then
6765
diff=$(echo "$dmips - $median" | bc -l)
6866
else
6967
diff=$(echo "$median - $dmips" | bc -l)
7068
fi
71-
if (( $(echo "$diff <= $mad * 2" | bc -l) )); then
69+
if (($(echo "$diff <= $mad * 2" | bc -l))); then
7270
filtered_dmips+=("$dmips")
7371
fi
7472
fi
@@ -83,8 +81,7 @@ echo -n "" > $benchmark_output
8381
num_filtered=${#filtered_dmips[@]}
8482
if ((num_filtered > 0)); then
8583
total_dmips=0
86-
for dmips in "${filtered_dmips[@]}"
87-
do
84+
for dmips in "${filtered_dmips[@]}"; do
8885
total_dmips=$(echo "scale=2; $total_dmips + $dmips" | bc -l)
8986
done
9087

0 commit comments

Comments
 (0)