All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Jones <drjones@redhat.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, rkrcmar@redhat.com
Subject: [PATCH kvm-unit-tests] scripts: ShellCheck found cleanups
Date: Wed, 26 Jul 2017 15:21:37 +0200	[thread overview]
Message-ID: <20170726132137.14722-1-drjones@redhat.com> (raw)

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

             reply	other threads:[~2017-07-26 13:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-26 13:21 Andrew Jones [this message]
2017-07-26 13:47 ` [PATCH kvm-unit-tests] scripts: ShellCheck found cleanups Radim Krčmář

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170726132137.14722-1-drjones@redhat.com \
    --to=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.