diff options
Diffstat (limited to '')
-rw-r--r-- | tests/misc/dev-tcp.tests | 16 | ||||
-rw-r--r-- | tests/misc/perf-script | 81 | ||||
-rw-r--r-- | tests/misc/perftest | 10 | ||||
-rw-r--r-- | tests/misc/read-nchars.tests | 11 | ||||
-rw-r--r-- | tests/misc/redir-t2.sh | 17 | ||||
-rw-r--r-- | tests/misc/run-r2.sh | 1 | ||||
-rw-r--r-- | tests/misc/sigint-1.sh | 9 | ||||
-rw-r--r-- | tests/misc/sigint-2.sh | 7 | ||||
-rw-r--r-- | tests/misc/sigint-3.sh | 11 | ||||
-rw-r--r-- | tests/misc/sigint-4.sh | 13 | ||||
-rw-r--r-- | tests/misc/test-minus-e.1 | 9 | ||||
-rw-r--r-- | tests/misc/test-minus-e.2 | 11 | ||||
-rw-r--r-- | tests/misc/wait-bg.tests | 25 |
13 files changed, 221 insertions, 0 deletions
diff --git a/tests/misc/dev-tcp.tests b/tests/misc/dev-tcp.tests new file mode 100644 index 0000000..0f3a228 --- /dev/null +++ b/tests/misc/dev-tcp.tests @@ -0,0 +1,16 @@ +exec 9<>/dev/tcp/129.22.8.162/25 + +read banner <&9 +echo "$banner" + +echo quit >&9 + +read msg <&9 +echo "$msg" + +exec 9<&- + +# nifty date command that queries the date/time server +cat < /dev/tcp/129.22.8.102/13 + +exit 0 diff --git a/tests/misc/perf-script b/tests/misc/perf-script new file mode 100644 index 0000000..e1172a9 --- /dev/null +++ b/tests/misc/perf-script @@ -0,0 +1,81 @@ +#!/bin/bash + +typeset -i m2 m1 M n2 n1 N m n +typeset -i MM=5 NN=5 + +case $# in + 0) : + ;; + 1) MM=$1; NN=$1 + ;; + 2) MM=$1; NN=$2 + ;; + *) echo 1>&2 "Usage: $0 [m [n]]" + ;; +esac + +EMPTYLINE=: # echo +echo 'a = { ' # mathematica + +let "M=1" # for (M=1; M<=MM; M++) +while let "M <= MM"; do + let "N=1" # for (N=1; N<=NN; N++) + while let "N <= NN"; do + + let "m1 = M - 1" + let "m2 = M + 1" + let "n1 = N - 1" + let "n2 = N + 1" + + + echo -n '{ ' # math + let "m=1" # for(m=1; m<=MM; m++) + while let "m <= MM"; do + let "n=1" # for(n=1; n<=NN; n++) + while let "n <= NN"; do + + let "x = (m-m1)*(m-M)*(m-m2)" + let "y = (n-n1)*(n-N)*(n-n2)" + + if let "(x*x + (n-N)*(n-N)) * ((m-M)*(m-M) + y*y)"; then + echo -n "0," + else # neighbour + echo -n "1," + fi + + let "n=n+1" + done + echo -n " "; let "m=m+1" # ". " + done + echo '},' + + + let "N=N+1" + $EMPTYLINE + done + $EMPTYLINE + let "M=M+1" +done + +echo '}' + + + +echo -n 'o = { ' +let "m=1" +while let "m <= MM"; do + let "n=1" + while let "n <= NN"; do + echo -n "1," + let "n=n+1" + done + let "m=m+1" +done +echo " }" + + +echo 'x = LinearSolve[a,o] ' + +exit 0 + + diff --git a/tests/misc/perftest b/tests/misc/perftest new file mode 100644 index 0000000..ee3f2c6 --- /dev/null +++ b/tests/misc/perftest @@ -0,0 +1,10 @@ +# originally from Mike Haertel +foo() { case $1 in a*) ;; *) ;; esac ;} +bar() { case $1 in [abc]*) ;; *);; esac ;} +baz() { case $1 in xyzzy) ;; *) ;; esac ;} +for x in /usr/lib/*/* +do + foo $x + bar $x + baz $x +done diff --git a/tests/misc/read-nchars.tests b/tests/misc/read-nchars.tests new file mode 100644 index 0000000..40b1f98 --- /dev/null +++ b/tests/misc/read-nchars.tests @@ -0,0 +1,11 @@ +# interactive + +# from tty +read -n 3 -p 'enter three chars: ' xyz +echo +echo $xyz + +# using readline +read -p 'enter 3 chars: ' -e -n 3 abc +# readline outputs a newline for us, so we don't need the extra echo +echo $abc diff --git a/tests/misc/redir-t2.sh b/tests/misc/redir-t2.sh new file mode 100644 index 0000000..44b2624 --- /dev/null +++ b/tests/misc/redir-t2.sh @@ -0,0 +1,17 @@ +read line1 + +echo read line 1 \"$line1\" + +exec 4<&0 + +exec 0</dev/tty + +read line2 + +echo line read from tty = \"$line2\" + +exec 0<&4 + +read line3 + +echo read line 3 \"$line3\" diff --git a/tests/misc/run-r2.sh b/tests/misc/run-r2.sh new file mode 100644 index 0000000..0321a1b --- /dev/null +++ b/tests/misc/run-r2.sh @@ -0,0 +1 @@ +../../bash ./redir-t2.sh < /etc/passwd diff --git a/tests/misc/sigint-1.sh b/tests/misc/sigint-1.sh new file mode 100644 index 0000000..7b74c30 --- /dev/null +++ b/tests/misc/sigint-1.sh @@ -0,0 +1,9 @@ +echo before trap +trap 'echo caught sigint' 2 +echo after trap + +for i in 1 2 3 +do + echo $i + sleep 5 +done diff --git a/tests/misc/sigint-2.sh b/tests/misc/sigint-2.sh new file mode 100644 index 0000000..69eaf56 --- /dev/null +++ b/tests/misc/sigint-2.sh @@ -0,0 +1,7 @@ +echo before loop + +for i in 1 2 3 +do + echo $i + sleep 5 +done diff --git a/tests/misc/sigint-3.sh b/tests/misc/sigint-3.sh new file mode 100644 index 0000000..2627fe6 --- /dev/null +++ b/tests/misc/sigint-3.sh @@ -0,0 +1,11 @@ +sleep 5 & +sleep 5 & +sleep 5 & + +echo wait 1 +wait + +echo wait 2 +wait + +exit diff --git a/tests/misc/sigint-4.sh b/tests/misc/sigint-4.sh new file mode 100644 index 0000000..587dd26 --- /dev/null +++ b/tests/misc/sigint-4.sh @@ -0,0 +1,13 @@ +trap 'echo sigint' 2 + +sleep 5 & +sleep 5 & +sleep 5 & + +echo wait 1 +wait + +echo wait 2 +wait + +exit diff --git a/tests/misc/test-minus-e.1 b/tests/misc/test-minus-e.1 new file mode 100644 index 0000000..77cc3f2 --- /dev/null +++ b/tests/misc/test-minus-e.1 @@ -0,0 +1,9 @@ +touch .file +while set -e ; test -r .file ; do + echo -n "stop loop? " + read reply + case "$reply" in + y*) rm .file non-dash-file ;; + esac + set +e +done diff --git a/tests/misc/test-minus-e.2 b/tests/misc/test-minus-e.2 new file mode 100644 index 0000000..f66966e --- /dev/null +++ b/tests/misc/test-minus-e.2 @@ -0,0 +1,11 @@ +touch .file +set -e +while set +e ; test -r .file ; do + echo -n "stop loop? [yes to quit] " + read reply + if [ "$reply" = yes ] ; then + rm .file non-dash-file + fi + set -e +done +rm -f .file diff --git a/tests/misc/wait-bg.tests b/tests/misc/wait-bg.tests new file mode 100644 index 0000000..95c98b0 --- /dev/null +++ b/tests/misc/wait-bg.tests @@ -0,0 +1,25 @@ +#! /bin/bash + +i=0 +while [ $i -lt $1 ] +do + /bin/sh -c "sleep 4; exit 0" & + rv=$? + pid=$! + eval bg_pid_$i=$pid + echo $$: Job $i: pid is $pid rv=$rv + i=$((i + 1)) +done + + + +i=0 +while [ $i -lt $1 ] +do + eval wpid=\$bg_pid_$i + echo Waiting for job $i '('pid $wpid')' + wait $wpid + rv=$? + echo Return value is $rv + i=$((i + 1)) +done |