* [PATCH kvm-unit-tests] scripts: ShellCheck found cleanups
@ 2017-07-26 13:21 Andrew Jones
2017-07-26 13:47 ` Radim Krčmář
0 siblings, 1 reply; 2+ messages in thread
From: Andrew Jones @ 2017-07-26 13:21 UTC (permalink / raw)
To: kvm; +Cc: pbonzini, rkrcmar
Checked all the bash scripts with
shellcheck --shell=bash
checking with and without the following exclude list
--exclude=SC1091,SC2004,SC2006,SC2086,SC2143,SC2155
Even with the exclude list there were some warnings not fixed with
this patch, but those are OK.
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
configure | 12 +++++-------
scripts/arch-run.bash | 16 ++++++++--------
scripts/common.bash | 2 +-
scripts/runtime.bash | 4 ++--
x86/run | 2 +-
5 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/configure b/configure
index e1efb3ca0cca..dd9d36199194 100755
--- a/configure
+++ b/configure
@@ -130,17 +130,15 @@ fi
cat << EOF > lib-test.c
__UINT32_TYPE__
EOF
-u32_long=$($cross_prefix$cc -E lib-test.c | grep -v '^#' | grep -q long && echo yes)
+u32_long=$("$cross_prefix$cc" -E lib-test.c | grep -v '^#' | grep -q long && echo yes)
rm -f lib-test.c
# api/: check for dependent 32 bit libraries and gnu++11 support
if [ "$testdir" = "x86" ]; then
echo 'int main () {}' > lib-test.c
- $cc -m32 -o /dev/null -lstdc++ -lpthread -lrt lib-test.c &> /dev/null
- exit=$?
- $cxx -m32 -o /dev/null -std=gnu++11 lib-test.c &> /dev/null
- if [ $? -eq 0 -a $exit -eq 0 ]; then
- api=true
+ if $cc -m32 -o /dev/null -lstdc++ -lpthread -lrt lib-test.c &> /dev/null &&
+ $cxx -m32 -o /dev/null -std=gnu++11 lib-test.c &> /dev/null; then
+ api=yes
fi
rm -f lib-test.c
fi
@@ -163,7 +161,7 @@ fi
# link lib/asm for the architecture
rm -f lib/asm
-asm=asm-generic
+asm="asm-generic"
if [ -d "$srcdir/lib/$arch/asm" ]; then
asm="$srcdir/lib/$arch/asm"
elif [ -d "$srcdir/lib/$testdir/asm" ]; then
diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
index 5249e8d87715..28a9efa9bf95 100644
--- a/scripts/arch-run.bash
+++ b/scripts/arch-run.bash
@@ -28,7 +28,7 @@ run_qemu ()
{
local stdout errors ret sig
- echo -n $@
+ echo -n "$@"
initrd_create &&
echo -n " #"
echo " $INITRD"
@@ -107,7 +107,7 @@ qmp ()
run_migration ()
{
if ! command -v nc >/dev/null 2>&1; then
- echo "$FUNCNAME needs nc (netcat)" >&2
+ echo "${FUNCNAME[0]} needs nc (netcat)" >&2
exit 2
fi
@@ -229,8 +229,8 @@ env_generate_errata ()
local kernel_version kernel_patchlevel kernel_sublevel kernel_extraversion
local line commit minver errata rest v p s x have
- IFS=. read kernel_version kernel_patchlevel rest <<<$kernel_version_string
- IFS=- read kernel_sublevel kernel_extraversion <<<$rest
+ IFS=. read -r kernel_version kernel_patchlevel rest <<<$kernel_version_string
+ IFS=- read -r kernel_sublevel kernel_extraversion <<<$rest
kernel_sublevel=${kernel_sublevel%%[!0-9]*}
kernel_extraversion=${kernel_extraversion%%[!0-9]*}
@@ -247,8 +247,8 @@ env_generate_errata ()
errata="ERRATA_$commit"
test -v $errata && continue
- IFS=. read v p rest <<<$minver
- IFS=- read s x <<<$rest
+ IFS=. read -r v p rest <<<$minver
+ IFS=- read -r s x <<<$rest
s=${s%%[!0-9]*}
x=${x%%[!0-9]*}
@@ -305,8 +305,8 @@ kvm_available ()
return 1
[ "$HOST" = "$ARCH_NAME" ] ||
- [ "$HOST" = aarch64 -a "$ARCH" = arm ] ||
- [ "$HOST" = x86_64 -a "$ARCH" = i386 ]
+ ( [ "$HOST" = aarch64 ] && [ "$ARCH" = arm ] ) ||
+ ( [ "$HOST" = x86_64 ] && [ "$ARCH" = i386 ] )
}
get_qemu_accelerator ()
diff --git a/scripts/common.bash b/scripts/common.bash
index ee9143c5d630..9a6ebbd7f287 100644
--- a/scripts/common.bash
+++ b/scripts/common.bash
@@ -15,7 +15,7 @@ function for_each_unittest()
exec {fd}<"$unittests"
- while read -u $fd line; do
+ while read -r -u $fd line; do
if [[ "$line" =~ ^\[(.*)\]$ ]]; then
"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout"
testname=${BASH_REMATCH[1]}
diff --git a/scripts/runtime.bash b/scripts/runtime.bash
index ac09e0fd30ac..a31ae913c8c8 100644
--- a/scripts/runtime.bash
+++ b/scripts/runtime.bash
@@ -38,7 +38,7 @@ skip_nodefault()
[ "$STANDALONE" != "yes" ] && return 0
while true; do
- read -p "Test marked not to be run by default, are you sure (y/N)? " yn
+ read -r -p "Test marked not to be run by default, are you sure (y/N)? " yn
case $yn in
"Y" | "y" | "Yes" | "yes")
return 1
@@ -84,7 +84,7 @@ function run()
# check a file for a particular value before running a test
# the check line can contain multiple files to check separated by a space
# but each check parameter needs to be of the form <path>=<value>
- for check_param in ${check[@]}; do
+ for check_param in "${check[@]}"; do
path=${check_param%%=*}
value=${check_param#*=}
if [ "$path" ] && [ "$(cat $path)" != "$value" ]; then
diff --git a/x86/run b/x86/run
index e59c6c590a20..1ac91f1d880f 100755
--- a/x86/run
+++ b/x86/run
@@ -37,7 +37,7 @@ else
pc_testdev="-device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out"
fi
-command="${qemu} -nodefaults $pc_testdev -vnc none -serial stdio $pci_testdev $hyperv_testdev"
+command="${qemu} -nodefaults $pc_testdev -vnc none -serial stdio $pci_testdev"
command+=" -machine accel=$ACCEL -kernel"
command="$(timeout_cmd) $command"
--
2.13.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH kvm-unit-tests] scripts: ShellCheck found cleanups
2017-07-26 13:21 [PATCH kvm-unit-tests] scripts: ShellCheck found cleanups Andrew Jones
@ 2017-07-26 13:47 ` Radim Krčmář
0 siblings, 0 replies; 2+ messages in thread
From: Radim Krčmář @ 2017-07-26 13:47 UTC (permalink / raw)
To: Andrew Jones; +Cc: kvm, pbonzini
2017-07-26 15:21+0200, Andrew Jones:
> Checked all the bash scripts with
>
> shellcheck --shell=bash
>
> checking with and without the following exclude list
>
> --exclude=SC1091,SC2004,SC2006,SC2086,SC2143,SC2155
>
> Even with the exclude list there were some warnings not fixed with
> this patch, but those are OK.
>
> Signed-off-by: Andrew Jones <drjones@redhat.com>
> ---
I'll remember to never use -a in `test`,
Reviewed-by: Radim Krčmář <rkrcmar@redhat.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-07-26 13:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-26 13:21 [PATCH kvm-unit-tests] scripts: ShellCheck found cleanups Andrew Jones
2017-07-26 13:47 ` Radim Krčmář
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox