[SCM] Git repository for devscripts branch, master, updated. v2.12.4-23-ge913048
Benjamin Drung
bdrung at debian.org
Thu Oct 25 19:26:15 UTC 2012
The following commit has been merged in the master branch:
commit ed3dcf9c2b74c4a2a862a2dccf51d2c9ed3352e2
Author: Benjamin Drung <bdrung at debian.org>
Date: Thu Oct 25 21:22:05 2012 +0200
Add bashism test cases from Raphael Geissert.
diff --git a/test/bashisms/531327.sh b/test/bashisms/531327.sh
new file mode 100644
index 0000000..8dcc058
--- /dev/null
+++ b/test/bashisms/531327.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+foo() {}
+
+foo \
+source something
diff --git a/test/bashisms/535368.mk b/test/bashisms/535368.mk
new file mode 100644
index 0000000..adba007
--- /dev/null
+++ b/test/bashisms/535368.mk
@@ -0,0 +1,6 @@
+#!/usr/bin/make -f
+
+foo:
+ if [ "$$(< $(DEBIAN)/foo md5sum)" != "$$(cat $(DEBIAN)/foo.md5)" ] ; then \
+ echo moo; \
+ fi
diff --git a/test/bashisms/arith.sh b/test/bashisms/arith.sh
new file mode 100644
index 0000000..2cbe860
--- /dev/null
+++ b/test/bashisms/arith.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+metric=0
+echo $((metric=metric+1))
+
+m=0
+n=2
+echo $((n-m++)) # BASHISM
+echo $((++m)) # BASHISM
+echo $(( m-- )) # BASHISM
+echo $((--m)) # BASHISM
+
+foo_bar=0
+echo $((foo_bar++)) # BASHISM
+echo $((foo_bar=foo_bar*2))
+echo $((foo_bar*3/6))
+
+echo $((2*n++)) # BASHISM
+
+echo $(($n*n++)) # BASHISM
+
+echo $((3**2)) # BASHISM
diff --git a/test/bashisms/arith.sh.out b/test/bashisms/arith.sh.out
new file mode 100644
index 0000000..dae4b40
--- /dev/null
+++ b/test/bashisms/arith.sh.out
@@ -0,0 +1,16 @@
+possible bashism in bashisms/arith.sh line 7 ('$((n++))' should be '$n; $((n=n+1))'):
+echo $((n-m++)) # BASHISM
+possible bashism in bashisms/arith.sh line 8 ('$((++n))' should be '$((n=n+1))'):
+echo $((++m)) # BASHISM
+possible bashism in bashisms/arith.sh line 9 ('$((n--))' should be '$n; $((n=n-1))'):
+echo $(( m-- )) # BASHISM
+possible bashism in bashisms/arith.sh line 10 ('$((--n))' should be '$((n=n-1))'):
+echo $((--m)) # BASHISM
+possible bashism in bashisms/arith.sh line 13 ('$((n++))' should be '$n; $((n=n+1))'):
+echo $((foo_bar++)) # BASHISM
+possible bashism in bashisms/arith.sh line 17 ('$((n++))' should be '$n; $((n=n+1))'):
+echo $((2*n++)) # BASHISM
+possible bashism in bashisms/arith.sh line 19 ('$((n++))' should be '$n; $((n=n+1))'):
+echo $(($n*n++)) # BASHISM
+possible bashism in bashisms/arith.sh line 21 (exponentiation is not POSIX):
+echo $((3**2)) # BASHISM
diff --git a/test/bashisms/ash-setvar.sh b/test/bashisms/ash-setvar.sh
new file mode 100644
index 0000000..c0ae403
--- /dev/null
+++ b/test/bashisms/ash-setvar.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+setvar foo bar # BASHISM
+[ bar = "$foo" ]
diff --git a/test/bashisms/ash-setvar.sh.out b/test/bashisms/ash-setvar.sh.out
new file mode 100644
index 0000000..44de53d
--- /dev/null
+++ b/test/bashisms/ash-setvar.sh.out
@@ -0,0 +1,2 @@
+possible bashism in bashisms/ash-setvar.sh line 3 (setvar 'foo' 'bar' should be eval \$'foo' 'bar'):
+setvar foo bar # BASHISM
diff --git a/test/bashisms/basic-bash-override.mk b/test/bashisms/basic-bash-override.mk
new file mode 100644
index 0000000..7904a5e
--- /dev/null
+++ b/test/bashisms/basic-bash-override.mk
@@ -0,0 +1,6 @@
+#!/usr/bin/make -f
+
+ override SHELL := bash
+
+test:
+ @echo -e foo
diff --git a/test/bashisms/basic-bash.mk b/test/bashisms/basic-bash.mk
new file mode 100644
index 0000000..7a16131
--- /dev/null
+++ b/test/bashisms/basic-bash.mk
@@ -0,0 +1,6 @@
+#!/usr/bin/make -f
+
+SHELL := bash
+
+test:
+ echo -e foo
diff --git a/test/bashisms/basic.mk b/test/bashisms/basic.mk
new file mode 100644
index 0000000..31d59a2
--- /dev/null
+++ b/test/bashisms/basic.mk
@@ -0,0 +1,21 @@
+#!/usr/bin/make -f
+
+# bug:
+overrideSHELL := bash
+
+test:
+ -echo -e "foo BASHISM"
+ @echo -e "bar BASHISM"
+ @-echo -e "bar BASHISM" && false
+ - at echo -e "bar BASHISM" && false
+ true
+
+dirs:
+source diff:
+source diff.gz::
+source file-stamp:
+caller %.so:
+ :
+
+foo: $(shell echo dir/BASHISM/{foo,bar})
+ :
diff --git a/test/bashisms/basic.mk.out b/test/bashisms/basic.mk.out
new file mode 100644
index 0000000..1fae795
--- /dev/null
+++ b/test/bashisms/basic.mk.out
@@ -0,0 +1,10 @@
+possible bashism in bashisms/basic.mk line 7 (echo -e):
+ -echo -e "foo BASHISM"
+possible bashism in bashisms/basic.mk line 8 (echo -e):
+ @echo -e "bar BASHISM"
+possible bashism in bashisms/basic.mk line 9 (echo -e):
+ @-echo -e "bar BASHISM" && false
+possible bashism in bashisms/basic.mk line 10 (echo -e):
+ - at echo -e "bar BASHISM" && false
+possible bashism in bashisms/basic.mk line 20 (brace expansion):
+foo: $(shell echo dir/BASHISM/{foo,bar})
diff --git a/test/bashisms/command.sh b/test/bashisms/command.sh
new file mode 100644
index 0000000..ae60c97
--- /dev/null
+++ b/test/bashisms/command.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+command test
+command -p test
+command -v test # BASHISM
+command -V test # BASHISM
diff --git a/test/bashisms/command.sh.out b/test/bashisms/command.sh.out
new file mode 100644
index 0000000..7a6b081
--- /dev/null
+++ b/test/bashisms/command.sh.out
@@ -0,0 +1,4 @@
+possible bashism in bashisms/command.sh line 5 ('command' with option other than -p):
+command -v test # BASHISM
+possible bashism in bashisms/command.sh line 6 ('command' with option other than -p):
+command -V test # BASHISM
diff --git a/test/bashisms/comments-parsing-fns.sh b/test/bashisms/comments-parsing-fns.sh
new file mode 100644
index 0000000..933caee
--- /dev/null
+++ b/test/bashisms/comments-parsing-fns.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+echo $# ; echo -e BASHISM
diff --git a/test/bashisms/comments-parsing-fns.sh.out b/test/bashisms/comments-parsing-fns.sh.out
new file mode 100644
index 0000000..e0a8f6b
--- /dev/null
+++ b/test/bashisms/comments-parsing-fns.sh.out
@@ -0,0 +1,2 @@
+possible bashism in bashisms/comments-parsing-fns.sh line 3 (echo -e):
+echo $# ; echo -e BASHISM
diff --git a/test/bashisms/coproc.sh b/test/bashisms/coproc.sh
new file mode 100644
index 0000000..6d6edcc
--- /dev/null
+++ b/test/bashisms/coproc.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+coproc true # BASHISM
diff --git a/test/bashisms/coproc.sh.out b/test/bashisms/coproc.sh.out
new file mode 100644
index 0000000..63b4caa
--- /dev/null
+++ b/test/bashisms/coproc.sh.out
@@ -0,0 +1,2 @@
+possible bashism in bashisms/coproc.sh line 3 (coproc):
+coproc true # BASHISM
diff --git a/test/bashisms/dynamic-length.sh b/test/bashisms/dynamic-length.sh
new file mode 100644
index 0000000..fa76729
--- /dev/null
+++ b/test/bashisms/dynamic-length.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+len=1
+f=foo
+
+echo "${f:1}" # BASHISM
+echo "${f:$len}" # BASHISM
+echo "${f:$len$len}" # BASHISM
+echo "${f:${len}}" # BASHISM
diff --git a/test/bashisms/dynamic-length.sh.out b/test/bashisms/dynamic-length.sh.out
new file mode 100644
index 0000000..ffd0b13
--- /dev/null
+++ b/test/bashisms/dynamic-length.sh.out
@@ -0,0 +1,8 @@
+possible bashism in bashisms/dynamic-length.sh line 6 (${foo:3[:1]}):
+echo "${f:1}" # BASHISM
+possible bashism in bashisms/dynamic-length.sh line 7 (${foo:3[:1]}):
+echo "${f:$len}" # BASHISM
+possible bashism in bashisms/dynamic-length.sh line 8 (${foo:3[:1]}):
+echo "${f:$len$len}" # BASHISM
+possible bashism in bashisms/dynamic-length.sh line 9 (${foo:3[:1]}):
+echo "${f:${len}}" # BASHISM
diff --git a/test/bashisms/fail2ban.sh b/test/bashisms/fail2ban.sh
new file mode 100644
index 0000000..1ab61f8
--- /dev/null
+++ b/test/bashisms/fail2ban.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+eval $_INITSCRIPT force-reload ${HIDEOUTPUT:+\>/dev/null 2\>&1}
diff --git a/test/bashisms/fps.sh b/test/bashisms/fps.sh
new file mode 100644
index 0000000..b1a619e
--- /dev/null
+++ b/test/bashisms/fps.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+echo -e "BASHISM" \
+ "something else \n"
+
+#exec ${loclibdir}/tkcon.tcl \
+# -eval "source ${loclibdir}/console.tcl" \
+# -slave "package require Tk; set argc $#; set argv [list $*]; \
+# source ${loclibdir}/xcircuit.tcl"
diff --git a/test/bashisms/fps.sh.out b/test/bashisms/fps.sh.out
new file mode 100644
index 0000000..8f4b457
--- /dev/null
+++ b/test/bashisms/fps.sh.out
@@ -0,0 +1,3 @@
+possible bashism in bashisms/fps.sh line 4 (echo -e):
+echo -e "BASHISM" \
+ "something else \n"
diff --git a/test/bashisms/gettext.sh b/test/bashisms/gettext.sh
new file mode 100644
index 0000000..ebaec32
--- /dev/null
+++ b/test/bashisms/gettext.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+echo $"hello world -- BASHISM"
+
+echo "foo ' bar moo'$"
diff --git a/test/bashisms/gettext.sh.out b/test/bashisms/gettext.sh.out
new file mode 100644
index 0000000..a76578e
--- /dev/null
+++ b/test/bashisms/gettext.sh.out
@@ -0,0 +1,2 @@
+possible bashism in bashisms/gettext.sh line 3 ($"foo" should be eval_gettext "foo"):
+echo $"hello world -- BASHISM"
diff --git a/test/bashisms/heredocs.sh b/test/bashisms/heredocs.sh
new file mode 100644
index 0000000..39dd076
--- /dev/null
+++ b/test/bashisms/heredocs.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+cat <<- FOO
+ foo
+ bar
+ moo
+FOO
+
+echo -e moo # BASHISM
+
+foo() {
+ cat <<- FOO
+ foo
+ bar
+ moo
+ FOO
+ echo -e BASHISM
+}
+
+bar() {
+ cat <<- FOO
+ foo
+ bar
+ moo
+ FOO
+ echo -e nothing wrong here
+FOO
+ echo -e BASHISM
+}
+
+
+moo() {
+ cat << FOO
+ foo
+ bar
+ moo
+ FOO
+ echo -e nothing wrong here
+ FOO
+ echo -e still nothing wrong here
+FOO
+ echo -e BASHISM
+}
+
+baz() {
+ cat << EOF1
+EOF1
+ echo -e still inside the here doc
+EOF1 ; echo -e still inside...
+EOF1
+ echo -e BASHISM
+}
diff --git a/test/bashisms/heredocs.sh.out b/test/bashisms/heredocs.sh.out
new file mode 100644
index 0000000..15e3910
--- /dev/null
+++ b/test/bashisms/heredocs.sh.out
@@ -0,0 +1,10 @@
+possible bashism in bashisms/heredocs.sh line 9 (echo -e):
+echo -e moo # BASHISM
+possible bashism in bashisms/heredocs.sh line 17 (echo -e):
+ echo -e BASHISM
+possible bashism in bashisms/heredocs.sh line 28 (echo -e):
+ echo -e BASHISM
+possible bashism in bashisms/heredocs.sh line 42 (echo -e):
+ echo -e BASHISM
+possible bashism in bashisms/heredocs.sh line 51 (echo -e):
+ echo -e BASHISM
diff --git a/test/bashisms/jobs.sh b/test/bashisms/jobs.sh
new file mode 100644
index 0000000..9e2df54
--- /dev/null
+++ b/test/bashisms/jobs.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# POSIX+UP:
+jobs # BASHISM
+jobs -l # BASHISM
+jobs -p # BASHISM
+
+# Non-POSIX at all:
+
+sleep 10 &
+j=$(jobs -p) # possible BASHISM (context changes because of subshell)
+jobs -r # BASHISM
+jobs -s # BASHISM
+jobs -n # BASHISM
+jobs -x # BASHISM
\ No newline at end of file
diff --git a/test/bashisms/jobs.sh.out b/test/bashisms/jobs.sh.out
new file mode 100644
index 0000000..de8f8b3
--- /dev/null
+++ b/test/bashisms/jobs.sh.out
@@ -0,0 +1,16 @@
+possible bashism in bashisms/jobs.sh line 4 (jobs):
+jobs # BASHISM
+possible bashism in bashisms/jobs.sh line 5 (jobs):
+jobs -l # BASHISM
+possible bashism in bashisms/jobs.sh line 6 (jobs):
+jobs -p # BASHISM
+possible bashism in bashisms/jobs.sh line 11 (jobs):
+j=$(jobs -p) # possible BASHISM (context changes because of subshell)
+possible bashism in bashisms/jobs.sh line 12 (jobs):
+jobs -r # BASHISM
+possible bashism in bashisms/jobs.sh line 13 (jobs):
+jobs -s # BASHISM
+possible bashism in bashisms/jobs.sh line 14 (jobs):
+jobs -n # BASHISM
+possible bashism in bashisms/jobs.sh line 15 (jobs):
+jobs -x # BASHISM
diff --git a/test/bashisms/line-continuation.sh b/test/bashisms/line-continuation.sh
new file mode 100644
index 0000000..e83b6d4
--- /dev/null
+++ b/test/bashisms/line-continuation.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+echo foo; \
+shopt something # BASHISM
+
+echo foo; echo \
+shopt something
+
+cat <<EOF \
+&>/dev/null #BASHISM
+bar
+moo
+EOF
+
+cat <<EOF
+foo\
+bar\
+moo
+EOF
diff --git a/test/bashisms/line-continuation.sh.out b/test/bashisms/line-continuation.sh.out
new file mode 100644
index 0000000..a243228
--- /dev/null
+++ b/test/bashisms/line-continuation.sh.out
@@ -0,0 +1,6 @@
+possible bashism in bashisms/line-continuation.sh line 4 (shopt):
+echo foo; \
+shopt something # BASHISM
+possible bashism in bashisms/line-continuation.sh line 10 (should be >word 2>&1):
+cat <<EOF \
+&>/dev/null #BASHISM
diff --git a/test/bashisms/negations.sh b/test/bashisms/negations.sh
new file mode 100644
index 0000000..8901357
--- /dev/null
+++ b/test/bashisms/negations.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+case "moo" in
+ [^f]oo) # BASHISM
+ echo hey
+ ;;
+ [!f]oo)
+ echo hey
+ ;;
+esac
+
diff --git a/test/bashisms/negations.sh.out b/test/bashisms/negations.sh.out
new file mode 100644
index 0000000..2a481c1
--- /dev/null
+++ b/test/bashisms/negations.sh.out
@@ -0,0 +1,2 @@
+possible bashism in bashisms/negations.sh line 4 ([^] should be [!]):
+ [^f]oo) # BASHISM
diff --git a/test/bashisms/printf.sh b/test/bashisms/printf.sh
new file mode 100644
index 0000000..59e0fcf
--- /dev/null
+++ b/test/bashisms/printf.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+printf -v some_var "this is a BASHISM"
+
+printf "the use of %q is bad\n" "BASHISMS" >/dev/null
+
+printf "this is another BASHISM: %b" "\n" >/dev/null
diff --git a/test/bashisms/printf.sh.out b/test/bashisms/printf.sh.out
new file mode 100644
index 0000000..623c999
--- /dev/null
+++ b/test/bashisms/printf.sh.out
@@ -0,0 +1,6 @@
+possible bashism in bashisms/printf.sh line 3 ('printf -v var ...' should be var='$(printf ...)'):
+printf -v some_var "this is a BASHISM"
+possible bashism in bashisms/printf.sh line 5 (printf %q|%b):
+printf "the use of %q is bad\n" "BASHISMS" >/dev/null
+possible bashism in bashisms/printf.sh line 7 (printf %q|%b):
+printf "this is another BASHISM: %b" "\n" >/dev/null
diff --git a/test/bashisms/quoted-strings.sh b/test/bashisms/quoted-strings.sh
new file mode 100644
index 0000000..bf88104
--- /dev/null
+++ b/test/bashisms/quoted-strings.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+foo="
+echo -e nothing wrong here
+#crap"
+
+echo -e BASHISM
+
+foo="\
+#crap"
+
+echo -e BASHISM
+
+case foo in
+ *\'*)
+ echo -e BASHISM
+ ;;
+esac
+#'
+echo -e BASHISM
+
+case foo in
+ *\\"*")
+ echo -e BASHISM
+ ;;
+ *\\\"*)
+ echo -e BASHISM
+ ;;
+ *\"*)
+ echo -e BASHISM
+ ;;
+esac
+#"
+echo -e BASHISM
+
+foo='\'
+echo -e BASHISM
diff --git a/test/bashisms/quoted-strings.sh.out b/test/bashisms/quoted-strings.sh.out
new file mode 100644
index 0000000..a1fd9d7
--- /dev/null
+++ b/test/bashisms/quoted-strings.sh.out
@@ -0,0 +1,18 @@
+possible bashism in bashisms/quoted-strings.sh line 7 (echo -e):
+echo -e BASHISM
+possible bashism in bashisms/quoted-strings.sh line 12 (echo -e):
+echo -e BASHISM
+possible bashism in bashisms/quoted-strings.sh line 16 (echo -e):
+ echo -e BASHISM
+possible bashism in bashisms/quoted-strings.sh line 20 (echo -e):
+echo -e BASHISM
+possible bashism in bashisms/quoted-strings.sh line 24 (echo -e):
+ echo -e BASHISM
+possible bashism in bashisms/quoted-strings.sh line 27 (echo -e):
+ echo -e BASHISM
+possible bashism in bashisms/quoted-strings.sh line 30 (echo -e):
+ echo -e BASHISM
+possible bashism in bashisms/quoted-strings.sh line 34 (echo -e):
+echo -e BASHISM
+possible bashism in bashisms/quoted-strings.sh line 37 (echo -e):
+echo -e BASHISM
diff --git a/test/bashisms/shell-vars.mk b/test/bashisms/shell-vars.mk
new file mode 100644
index 0000000..54b71cb
--- /dev/null
+++ b/test/bashisms/shell-vars.mk
@@ -0,0 +1,5 @@
+#!/usr/bin/make -f
+
+foo:
+ read foo bar | echo $$foo and $$bar
+ echo my pid: $$$$
diff --git a/test/bashisms/source.out b/test/bashisms/source.out
new file mode 100644
index 0000000..8584a6b
--- /dev/null
+++ b/test/bashisms/source.out
@@ -0,0 +1,2 @@
+possible bashism in bashisms/source line 2 (should be '.', not 'source'):
+source foo.sh
diff --git a/test/bashisms/special-case.sh b/test/bashisms/special-case.sh
new file mode 100644
index 0000000..5dd43e0
--- /dev/null
+++ b/test/bashisms/special-case.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+case "foo" in
+ foo)
+ echo once
+ ;& # BASHISM
+ moo)
+ echo twice
+ ;;& # BASHISM
+ foo)
+ echo foo again
+ ;;
+esac
diff --git a/test/bashisms/special-case.sh.out b/test/bashisms/special-case.sh.out
new file mode 100644
index 0000000..2b0a5e3
--- /dev/null
+++ b/test/bashisms/special-case.sh.out
@@ -0,0 +1,4 @@
+possible bashism in bashisms/special-case.sh line 6 (;;& and ;& special case operators):
+ ;& # BASHISM
+possible bashism in bashisms/special-case.sh line 9 (;;& and ;& special case operators):
+ ;;& # BASHISM
diff --git a/test/bashisms/subshell-no-arith.sh b/test/bashisms/subshell-no-arith.sh
new file mode 100644
index 0000000..f3a5a29
--- /dev/null
+++ b/test/bashisms/subshell-no-arith.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+echo $((echo foo); echo bar)
diff --git a/test/bashisms/unknown-fns.sh b/test/bashisms/unknown-fns.sh
new file mode 100644
index 0000000..64d1b46
--- /dev/null
+++ b/test/bashisms/unknown-fns.sh
@@ -0,0 +1,297 @@
+#!/bin/sh
+
+################################################################################
+# #
+# Copyright (c) 2009 FUJITSU LIMITED #
+# #
+# This program is free software; you can redistribute it and#or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation; either version 2 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, but #
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License #
+# for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program; if not, write to the Free Software #
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+# #
+# Author: Miao Xie <miaox at cn.fujitsu.com> #
+# #
+################################################################################
+
+cd $LTPROOT/testcases/bin
+
+. ./cpuset_funcs.sh
+
+export TCID="cpuset01"
+export TST_TOTAL=97
+export TST_COUNT=1
+
+nr_cpus=$NR_CPUS
+nr_mems=$N_NODES
+
+cpus_all="$(seq -s, 0 $((nr_cpus-1)))"
+mems_all="$(seq -s, 0 $((nr_mems-1)))"
+
+exit_status=0
+
+cfile_name=
+
+# base_op_write_and_test <write_file_name> <write_string> <expect_string>
+base_op_write_and_test()
+{
+ local write_file="$1"
+ local write_string="$2"
+ local expect_string="$3"
+ local write_result=
+ local ret=0
+
+ mkdir -p "$(dirname $write_file)" || {
+ tst_brkm TFAIL "Failed to mkdir -p $(basename $write_file)"
+ return 1
+ }
+ [ "$write_string" = NULL ] && write_string=" "
+
+ /bin/echo "$write_string" > "$write_file" 2> $CPUSET_TMP/stderr
+ ret=$?
+ write_result="$(cat "$write_file")"
+
+ case "$expect_string" in
+ EMPTY)
+ test -z "$write_result" -a $ret = 0
+ ret=$?
+ ;;
+ WRITE_ERROR)
+ ret=$((!$ret))
+ ;;
+ *)
+ test "$expect_string" = "$write_result" -a $ret = 0
+ ret=$?
+ ;;
+ esac
+
+ if [ $ret -eq 0 ]; then
+ tst_resm TPASS "$cfile_name: Get the expected string"
+ else
+ tst_resm TFAIL "$cfile_name: Test result - $write_result Expected string - \"$expect_string\""
+ fi
+ return $ret
+}
+
+base_op_test()
+{
+ setup
+ if [ $? -ne 0 ]; then
+ exit_status=1
+ else
+ base_op_write_and_test "$@"
+ if [ $? -ne 0 ]; then
+ exit_status=1
+ fi
+
+ cleanup
+ if [ $? -ne 0 ]; then
+ exit_status=1
+ fi
+ fi
+ : $((TST_COUNT++)) #BASHISM
+}
+
+test_cpus()
+{
+ cfile_name="cpus"
+ while read cpus result
+ do
+ base_op_test "$CPUSET/1/cpus" "$cpus" "$result"
+ done <<- EOF
+ NULL EMPTY
+ 0 0
+ $nr_cpus WRITE_ERROR
+ $cpus_all 0-$((nr_cpus-1))
+ ${cpus_all}$nr_cpus WRITE_ERROR
+ 0,0 0
+ 0-0 0
+ 0-$((nr_cpus-1)) 0-$((nr_cpus-1))
+ -1 WRITE_ERROR
+ 0-$nr_cpus WRITE_ERROR
+ 0- WRITE_ERROR
+ 0--$((nr_cpus-1)) WRITE_ERROR
+ 0,1-$((nr_cpus-2)),$((nr_cpus-1)) 0-$((nr_cpus-1))
+ 0,1-$((nr_cpus-2)), 0-$((nr_cpus-2))
+ 0AAA WRITE_ERROR
+ AAA WRITE_ERROR
+ EOF
+ # while read cpus result
+}
+
+test_mems()
+{
+ cfile_name="mems"
+ while read mems result
+ do
+ base_op_test "$CPUSET/1/mems" "$mems" "$result"
+ done <<- EOF
+ NULL EMPTY
+ 0 0
+ $nr_mems WRITE_ERROR
+ $mems_all 0-$((nr_mems-1))
+ ${mems_all}$nr_mems WRITE_ERROR
+ 0,0 0
+ 0-0 0
+ 0-$((nr_mems-1)) 0-$((nr_mems-1))
+ -1 WRITE_ERROR
+ 0-$nr_mems WRITE_ERROR
+ 0- WRITE_ERROR
+ 0--$((nr_mems-1)) WRITE_ERROR
+ 0,1-$((nr_mems-2)),$((nr_mems-1)) 0-$((nr_mems-1))
+ 0,1-$((nr_mems-2)), 0-$((nr_mems-2))
+ 0AAA WRITE_ERROR
+ AAA WRITE_ERROR
+ EOF
+ # while read mems result
+}
+
+test_flags()
+{
+ for filename in cpu_exclusive mem_exclusive mem_hardwall \
+ memory_migrate memory_spread_page memory_spread_slab \
+ sched_load_balance memory_pressure_enabled
+ do
+ cfile_name="$filename"
+ while read flags result
+ do
+ base_op_test "$CPUSET/$filename" "$flags" "$result"
+ done <<- EOF
+ NULL 0
+ 0 0
+ 1 1
+ -1 WRITE_ERROR
+ A WRITE_ERROR
+ 2 1
+ EOF
+ # while read flags, result
+ done # for filename in flagfiles
+}
+
+test_domain()
+{
+ cfile_name="sched_relax_domain_level"
+ while read domain_level result
+ do
+ base_op_test "$CPUSET/sched_relax_domain_level" "$domain_level" "$result"
+ done <<- EOF
+ NULL 0
+ 0 0
+ 1 1
+ 2 2
+ 3 3
+ 4 4
+ 5 5
+ 6 WRITE_ERROR
+ -1 -1
+ -2 WRITE_ERROR
+ A WRITE_ERROR
+ EOF
+ # while read domain_level result
+}
+
+# attach_task_test <cpus> <mems> <expect>
+attach_task_test()
+{
+ local cpus=$1
+ local mems=$2
+ local expect=$3
+
+ local pid=
+ local ret=
+
+ setup
+ if [ $? -ne 0 ]; then
+ exit_status=1
+ cleanup
+ ((TST_COUNT++)) #BASHISM
+ return
+ fi
+
+ # create sub cpuset
+ mkdir "$CPUSET/sub_cpuset" > /dev/null
+ if [ $? -ne 0 ]; then
+ exit_status=1
+ cleanup
+ ((TST_COUNT++)) # BASHISM
+ return
+ fi
+
+ if [ "$cpus" != "NULL" ]; then
+ echo $cpus > "$CPUSET/sub_cpuset/cpus"
+ fi
+ if [ "$mems" != "NULL" ]; then
+ echo $mems > "$CPUSET/sub_cpuset/mems"
+ fi
+
+ cat /dev/zero > /dev/null &
+ pid=$!
+
+ # attach task into the cpuset group
+ echo $pid > "$CPUSET/sub_cpuset/tasks" 2> /dev/null
+ if [ $? -eq $expect ]; then
+ tst_resm TPASS "Attaching Task Test successed!!"
+ else
+ tst_resm TFAIL "Attaching Task Test failed!! cpus - \"$cpus\", mems - \"$mems\", Expect - \"$expect\", Fact - \"$ret\". (0 - Attach Success, 1 - Attach Fail)"
+ exit_status=1
+ fi
+
+ /bin/kill $pid &> /dev/null # BASHISM
+ cleanup
+ if [ $? -ne 0 ]; then
+ exit_status=1
+ fi
+ ((TST_COUNT++)) # BASHISM
+}
+
+
+test_attach_task()
+{
+ cfile_name="tasks"
+ while read cpus mems expect
+ do
+ attach_task_test "$cpus" "$mems" "$expect"
+ done <<- EOF
+ 0 NULL 1
+ 0 0 0
+ NULL 0 1
+ EOF
+ # while read cpus mems expect
+}
+
+test_readonly_cfiles()
+{
+ for filename in cpus mems memory_pressure
+ do
+ cfile_name="$filename(READONLY)"
+ base_op_test "$CPUSET/$filename" "0" "WRITE_ERROR"
+ done # for filename in readonly cfiles
+}
+
+# Case 1-3
+test_readonly_cfiles
+
+# Case 4-19
+test_cpus
+
+# Case 20-35
+test_mems
+
+# Case 36-83
+test_flags
+
+# Case 84-94
+test_domain
+
+# Case 95-97
+test_attach_task
+
+exit $exit_status
diff --git a/test/bashisms/unknown-fns.sh.out b/test/bashisms/unknown-fns.sh.out
new file mode 100644
index 0000000..82f0896
--- /dev/null
+++ b/test/bashisms/unknown-fns.sh.out
@@ -0,0 +1,10 @@
+possible bashism in bashisms/unknown-fns.sh line 100 ('$((n++))' should be '$n; $((n=n+1))'):
+ : $((TST_COUNT++)) #BASHISM
+possible bashism in bashisms/unknown-fns.sh line 215 ('((' should be '$(('):
+ ((TST_COUNT++)) #BASHISM
+possible bashism in bashisms/unknown-fns.sh line 224 ('((' should be '$(('):
+ ((TST_COUNT++)) # BASHISM
+possible bashism in bashisms/unknown-fns.sh line 247 (should be >word 2>&1):
+ /bin/kill $pid &> /dev/null # BASHISM
+possible bashism in bashisms/unknown-fns.sh line 252 ('((' should be '$(('):
+ ((TST_COUNT++)) # BASHISM
diff --git a/test/test_checkbashisms b/test/test_checkbashisms
index ded8a72..e510f08 100755
--- a/test/test_checkbashisms
+++ b/test/test_checkbashisms
@@ -19,15 +19,116 @@ WORKDIR="$(readlink -f "${0%/*}")"
. "${0%/*}/shunit2-helper-functions.sh"
+clean() {
+ cd "$WORKDIR"
+ runCommand "$1" "" "" 0
+}
+
found() {
cd "$WORKDIR"
runCommand "$1" "" "$2" 1
}
-testSource() {
+test_531327() {
+ clean "bashisms/531327.sh"
+}
+
+test_535368() {
+ clean "-f bashisms/535368.mk"
+}
+
+test_arith() {
+ found "bashisms/arith.sh" "$(cat bashisms/arith.sh.out)"
+}
+
+test_ash_setvar() {
+ found "bashisms/ash-setvar.sh" "$(cat bashisms/ash-setvar.sh.out)"
+}
+
+test_basic() {
+ found "-f bashisms/basic.mk" "$(cat bashisms/basic.mk.out)"
+}
+
+test_basic_bash() {
+ clean "-f bashisms/basic-bash.mk"
+}
+
+test_basic_bash_override() {
+ clean "-f bashisms/basic-bash-override.mk"
+}
+
+test_command() {
+ found "bashisms/command.sh" "$(cat bashisms/command.sh.out)"
+}
+
+test_comments_parsing_fns() {
+ found "bashisms/comments-parsing-fns.sh" "$(cat bashisms/comments-parsing-fns.sh.out)"
+}
+
+test_coproc() {
+ found "bashisms/coproc.sh" "$(cat bashisms/coproc.sh.out)"
+}
+
+test_dynamic_length() {
+ found "bashisms/dynamic-length.sh" "$(cat bashisms/dynamic-length.sh.out)"
+}
+
+test_fail2ban() {
+ clean "bashisms/fail2ban.sh"
+}
+
+test_fps() {
+ found "bashisms/fps.sh" "$(cat bashisms/fps.sh.out)"
+}
+
+test_gettext() {
+ found "bashisms/gettext.sh" "$(cat bashisms/gettext.sh.out)"
+}
+
+test_heredocs() {
+ found "bashisms/heredocs.sh" "$(cat bashisms/heredocs.sh.out)"
+}
+
+test_jobs() {
+ found "bashisms/jobs.sh" "$(cat bashisms/jobs.sh.out)"
+}
+
+test_line_continuation() {
+ found "bashisms/line-continuation.sh" "$(cat bashisms/line-continuation.sh.out)"
+}
+
+test_negations() {
+ found "bashisms/negations.sh" "$(cat bashisms/negations.sh.out)"
+}
+
+test_printf() {
+ found "bashisms/printf.sh" "$(cat bashisms/printf.sh.out)"
+}
+
+test_quoted_strings() {
+ found "bashisms/quoted-strings.sh" "$(cat bashisms/quoted-strings.sh.out)"
+}
+
+test_shell_vars() {
+ clean "-f bashisms/shell-vars.mk"
+}
+
+test_source() {
local result="possible bashism in bashisms/source line 2 (should be '.', not 'source'):
source foo.sh"
found "bashisms/source" "$result"
}
+test_special_case() {
+ found "bashisms/special-case.sh" "$(cat bashisms/special-case.sh.out)"
+}
+
+test_subshell_no_arith() {
+ clean "bashisms/subshell-no-arith.sh"
+}
+
+test_unknown_fns() {
+ found "bashisms/unknown-fns.sh" "$(cat bashisms/unknown-fns.sh.out)"
+}
+
. shunit2
--
Git repository for devscripts
More information about the devscripts-devel
mailing list