]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tests: Add shellcheck test suite
authorMartin Schwenke <martin@meltin.net>
Thu, 14 Jul 2016 02:01:14 +0000 (12:01 +1000)
committerAmitay Isaacs <amitay@samba.org>
Thu, 21 Jul 2016 04:06:49 +0000 (06:06 +0200)
CTDB has a lot of scripts and shellcheck can be useful to find dubious
scripting practices.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Autobuild-User(master): Amitay Isaacs <amitay@samba.org>
Autobuild-Date(master): Thu Jul 21 06:06:49 CEST 2016 on sn-devel-144

ctdb/tests/run_tests.sh
ctdb/tests/shellcheck/base_scripts.sh [new file with mode: 0755]
ctdb/tests/shellcheck/ctdb_helpers.sh [new file with mode: 0755]
ctdb/tests/shellcheck/ctdbd_wrapper.sh [new file with mode: 0755]
ctdb/tests/shellcheck/event_scripts.sh [new file with mode: 0755]
ctdb/tests/shellcheck/functions.sh [new file with mode: 0755]
ctdb/tests/shellcheck/init_script.sh [new file with mode: 0755]
ctdb/tests/shellcheck/scripts/local.sh [new file with mode: 0644]
ctdb/tests/shellcheck/tools.sh [new file with mode: 0755]
ctdb/wscript

index 2af2daf4740e2182044a8023ae010125909b51ca..a7823dca40de7d70c7022d04f2daaf400f29893f 100755 (executable)
@@ -255,7 +255,7 @@ export TEST_SCRIPTS_DIR="${test_dir}/scripts"
 # If no tests specified then run some defaults
 if [ -z "$1" ] ; then
     if [ -n "$TEST_LOCAL_DAEMONS" ] ; then
-       set -- onnode takeover tool eventscripts cunit simple
+       set -- onnode takeover tool eventscripts cunit shellcheck simple
     else
        set -- simple complex
     fi
diff --git a/ctdb/tests/shellcheck/base_scripts.sh b/ctdb/tests/shellcheck/base_scripts.sh
new file mode 100755 (executable)
index 0000000..cbb8502
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "base scripts"
+
+shellcheck_test \
+       "${CTDB_SCRIPTS_BASE}/ctdb-crash-cleanup.sh" \
+       "${CTDB_SCRIPTS_BASE}/debug-hung-script.sh" \
+       "${CTDB_SCRIPTS_BASE}/debug_locks.sh" \
+       "${CTDB_SCRIPTS_BASE}/nfs-linux-kernel-callout" \
+       "${CTDB_SCRIPTS_BASE}/statd-callout"
diff --git a/ctdb/tests/shellcheck/ctdb_helpers.sh b/ctdb/tests/shellcheck/ctdb_helpers.sh
new file mode 100755 (executable)
index 0000000..f6c7e31
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "ctdb helpers"
+
+shellcheck_test \
+       "${CTDB_SCRIPTS_TOOLS_HELPER_DIR}/ctdb_lvs" \
+       "${CTDB_SCRIPTS_TOOLS_HELPER_DIR}/ctdb_natgw"
diff --git a/ctdb/tests/shellcheck/ctdbd_wrapper.sh b/ctdb/tests/shellcheck/ctdbd_wrapper.sh
new file mode 100755 (executable)
index 0000000..84045af
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "ctdbd_wrapper"
+
+shellcheck_test "${CTDB_SCRIPTS_SBIN_DIR}/ctdbd_wrapper"
diff --git a/ctdb/tests/shellcheck/event_scripts.sh b/ctdb/tests/shellcheck/event_scripts.sh
new file mode 100755 (executable)
index 0000000..b8a2b78
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "event scripts"
+
+shellcheck_test "${CTDB_SCRIPTS_BASE}/events.d"/[0-9][0-9].*
diff --git a/ctdb/tests/shellcheck/functions.sh b/ctdb/tests/shellcheck/functions.sh
new file mode 100755 (executable)
index 0000000..7ce206d
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "functions file"
+
+shellcheck_test -s sh "${CTDB_SCRIPTS_BASE}/functions"
diff --git a/ctdb/tests/shellcheck/init_script.sh b/ctdb/tests/shellcheck/init_script.sh
new file mode 100755 (executable)
index 0000000..d1b5151
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "init script"
+
+script="$CTDB_SCRIPTS_INIT_DIR"
+
+if [ -z "$script" ] ; then
+       script="/etc/init.d/ctdb"
+       if [ ! -r "$script" ] ; then
+               script="/usr/local/etc/init.d/ctdb"
+       fi
+       if [ ! -r "$script" ] ; then
+               echo "WARNING: Unable to find ctdb init script, skipping test"
+               exit 0
+       fi
+fi
+
+shellcheck_test "$script"
diff --git a/ctdb/tests/shellcheck/scripts/local.sh b/ctdb/tests/shellcheck/scripts/local.sh
new file mode 100644 (file)
index 0000000..ab92aaa
--- /dev/null
@@ -0,0 +1,44 @@
+# Hey Emacs, this is a -*- shell-script -*- !!!  :-)
+
+. "${TEST_SCRIPTS_DIR}/script_install_paths.sh"
+
+define_test ()
+{
+    _f=$(basename "$0" ".sh")
+
+    printf "%-28s - %s\n" "$_f" "$1"
+}
+shellcheck_test ()
+{
+       ok_null
+       if type shellcheck >/dev/null ; then
+               # Skip some recent checks:
+               #
+               # SC1090: Can't follow non-constant source. Use a
+               #         directive to specify location.
+               # SC1091: Not following: FILE was not specified as
+               #         input (see shellcheck -x).
+               #         - Shellcheck doesn't handle our includes
+               #           very well.  Adding directives to handle
+               #           include for both in-tree and installed
+               #           cases just isn't going to be possible.
+               # SC2162: read without -r will mangle backslashes.
+               #         - We never read things with backslashes,
+               #           unnecessary churn.
+               # SC2164: Use cd ... || exit in case cd fails.
+               #         - Most hits are on known directories.  Too
+               #           much churn, maybe later.
+               # SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not
+               #         well defined.
+               # SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not
+               #         well defined.
+               #         - This can cause issues but the number of
+               #           true positives will be very low.  Too much
+               #           churn, maybe later.
+               _excludes="SC1090,SC1091,SC2162,SC2164,SC2166"
+               unit_test shellcheck --exclude="$_excludes" "$@"
+       else
+               echo "WARNING: shellcheck not installed, skipping test"
+               unit_test true
+       fi
+}
diff --git a/ctdb/tests/shellcheck/tools.sh b/ctdb/tests/shellcheck/tools.sh
new file mode 100755 (executable)
index 0000000..2cd322c
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "tools"
+
+shellcheck_test \
+       "${CTDB_SCRIPTS_TOOLS_BIN_DIR}/onnode" \
+       "${CTDB_SCRIPTS_TOOLS_BIN_DIR}/ctdb_diagnostics"
index 3429e379117dfcfcbc1c00545bfb9119cb4e2982..96158c0f7d36f6908c03bc895a42b065446b8a1c 100755 (executable)
@@ -731,6 +731,7 @@ def build(bld):
         'events.d',
         'eventscripts',
         'onnode',
+        'shellcheck',
         'simple',
         'takeover',
         'tool'