diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-10-02 17:39:31 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-10-02 17:39:31 +0200 |
commit | 5d6b8729ed7335c702022f4f3176573f4cf2cf5a (patch) | |
tree | bef985dae4fb3ea41e1a478a848d19039b0e5d8f | |
parent | 888527cceec2f58f1eae3acceddee928b5cb647a (diff) | |
download | busybox-w32-5d6b8729ed7335c702022f4f3176573f4cf2cf5a.tar.gz busybox-w32-5d6b8729ed7335c702022f4f3176573f4cf2cf5a.tar.bz2 busybox-w32-5d6b8729ed7335c702022f4f3176573f4cf2cf5a.zip |
hush testsuite: add many tests from ash testsuite
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
34 files changed, 254 insertions, 3 deletions
diff --git a/shell/ash_test/ash-quoting/dollar_repl_slash_bash1.tests b/shell/ash_test/ash-quoting/dollar_repl_slash_bash1.tests index 3fa2f186d..74dca1cc0 100755 --- a/shell/ash_test/ash-quoting/dollar_repl_slash_bash1.tests +++ b/shell/ash_test/ash-quoting/dollar_repl_slash_bash1.tests | |||
@@ -1,5 +1,5 @@ | |||
1 | # The bug here was triggered by: | 1 | # The bug here was triggered by: |
2 | # * performin pathname expansion because we see [ | 2 | # * performing pathname expansion because we see [ |
3 | # * replace operator did not escape \ in replace string | 3 | # * replace operator did not escape \ in replace string |
4 | 4 | ||
5 | IP=192.168.0.1 | 5 | IP=192.168.0.1 |
diff --git a/shell/hush_test/hush-invert/invert.right b/shell/hush_test/hush-invert/invert.right new file mode 100644 index 000000000..5a9239aa6 --- /dev/null +++ b/shell/hush_test/hush-invert/invert.right | |||
@@ -0,0 +1,10 @@ | |||
1 | 1 | ||
2 | 1 | ||
3 | 1 | ||
4 | 0 | ||
5 | 0 | ||
6 | 1 | ||
7 | 0 | ||
8 | 1 | ||
9 | 0 | ||
10 | 1 | ||
diff --git a/shell/hush_test/hush-invert/invert.tests b/shell/hush_test/hush-invert/invert.tests new file mode 100755 index 000000000..8393d95a4 --- /dev/null +++ b/shell/hush_test/hush-invert/invert.tests | |||
@@ -0,0 +1,19 @@ | |||
1 | # tests of return value inversion | ||
2 | # placeholder for future expansion | ||
3 | |||
4 | # user subshells (...) did this wrong in bash versions before 2.04 | ||
5 | |||
6 | ! ( echo hello | grep h >/dev/null 2>&1 ); echo $? | ||
7 | ! echo hello | grep h >/dev/null 2>&1 ; echo $? | ||
8 | |||
9 | ! true ; echo $? | ||
10 | ! false; echo $? | ||
11 | |||
12 | ! (false) ; echo $? | ||
13 | ! (true); echo $? | ||
14 | |||
15 | ! true | false ; echo $? | ||
16 | ! false | true ; echo $? | ||
17 | |||
18 | ! (true | false) ; echo $? | ||
19 | ! (false | true) ; echo $? | ||
diff --git a/shell/hush_test/hush-misc/heredoc4.right b/shell/hush_test/hush-misc/heredoc4.right new file mode 100644 index 000000000..371b092e2 --- /dev/null +++ b/shell/hush_test/hush-misc/heredoc4.right | |||
@@ -0,0 +1 @@ | |||
'$' | |||
diff --git a/shell/hush_test/hush-misc/heredoc4.tests b/shell/hush_test/hush-misc/heredoc4.tests new file mode 100755 index 000000000..642ddb324 --- /dev/null +++ b/shell/hush_test/hush-misc/heredoc4.tests | |||
@@ -0,0 +1,3 @@ | |||
1 | cat <<EOF | ||
2 | '$' | ||
3 | EOF | ||
diff --git a/shell/hush_test/hush-misc/last_amp.right b/shell/hush_test/hush-misc/last_amp.right new file mode 100644 index 000000000..3da21aec2 --- /dev/null +++ b/shell/hush_test/hush-misc/last_amp.right | |||
@@ -0,0 +1,2 @@ | |||
1 | 3 | ||
2 | End | ||
diff --git a/shell/hush_test/hush-misc/last_amp.tests b/shell/hush_test/hush-misc/last_amp.tests new file mode 100755 index 000000000..160937644 --- /dev/null +++ b/shell/hush_test/hush-misc/last_amp.tests | |||
@@ -0,0 +1,8 @@ | |||
1 | $THIS_SH -c 'echo 3&' | ||
2 | d=`date` | ||
3 | while test "`date`" = "$d"; do true; done | ||
4 | d1=`date` | ||
5 | $THIS_SH -c 'sleep 1&' | ||
6 | d2=`date` | ||
7 | test "$d1" = "$d2" || echo BAD | ||
8 | echo End | ||
diff --git a/shell/hush_test/hush-misc/local1.right b/shell/hush_test/hush-misc/local1.right new file mode 100644 index 000000000..a2d121df6 --- /dev/null +++ b/shell/hush_test/hush-misc/local1.right | |||
@@ -0,0 +1,4 @@ | |||
1 | A1:'A' | ||
2 | A2:'' | ||
3 | A3:'' | ||
4 | A4:'A' | ||
diff --git a/shell/hush_test/hush-misc/local1.tests b/shell/hush_test/hush-misc/local1.tests new file mode 100755 index 000000000..b1e675059 --- /dev/null +++ b/shell/hush_test/hush-misc/local1.tests | |||
@@ -0,0 +1,11 @@ | |||
1 | a=A | ||
2 | f() { | ||
3 | local a | ||
4 | # the above line unsets $a | ||
5 | echo "A2:'$a'" | ||
6 | unset a | ||
7 | echo "A3:'$a'" | ||
8 | } | ||
9 | echo "A1:'$a'" | ||
10 | f | ||
11 | echo "A4:'$a'" | ||
diff --git a/shell/hush_test/hush-misc/nulltick1.right b/shell/hush_test/hush-misc/nulltick1.right new file mode 100644 index 000000000..f90b8209e --- /dev/null +++ b/shell/hush_test/hush-misc/nulltick1.right | |||
@@ -0,0 +1,3 @@ | |||
1 | Test 1 | ||
2 | Test 2 | ||
3 | Done | ||
diff --git a/shell/hush_test/hush-misc/nulltick1.tests b/shell/hush_test/hush-misc/nulltick1.tests new file mode 100755 index 000000000..f81923de3 --- /dev/null +++ b/shell/hush_test/hush-misc/nulltick1.tests | |||
@@ -0,0 +1,3 @@ | |||
1 | echo Test ` ` 1 | ||
2 | echo Test `</dev/null` 2 | ||
3 | echo Done | ||
diff --git a/shell/hush_test/hush-quoting/dollar_repl_slash_bash1.right b/shell/hush_test/hush-quoting/dollar_repl_slash_bash1.right new file mode 100644 index 000000000..b212c246c --- /dev/null +++ b/shell/hush_test/hush-quoting/dollar_repl_slash_bash1.right | |||
@@ -0,0 +1,10 @@ | |||
1 | 192\.168\.0\.1 | ||
2 | 192\.168\.0\.1[ | ||
3 | 192\.168\.0\.1[ | ||
4 | 192\\.168\\.0\\.1[ | ||
5 | 192\.168\.0\.1[ | ||
6 | 192\.168\.0\.1 | ||
7 | 192\.168\.0\.1[ | ||
8 | 192\.168\.0\.1[ | ||
9 | 192\\.168\\.0\\.1[ | ||
10 | 192\.168\.0\.1[ | ||
diff --git a/shell/hush_test/hush-quoting/dollar_repl_slash_bash1.tests b/shell/hush_test/hush-quoting/dollar_repl_slash_bash1.tests new file mode 100755 index 000000000..74dca1cc0 --- /dev/null +++ b/shell/hush_test/hush-quoting/dollar_repl_slash_bash1.tests | |||
@@ -0,0 +1,21 @@ | |||
1 | # The bug here was triggered by: | ||
2 | # * performing pathname expansion because we see [ | ||
3 | # * replace operator did not escape \ in replace string | ||
4 | |||
5 | IP=192.168.0.1 | ||
6 | |||
7 | rm -f '192.168.0.1[' | ||
8 | echo "${IP//./\\.}" | ||
9 | echo "${IP//./\\.}"'[' # bug was here | ||
10 | echo "${IP//./\\.}[" # bug was here | ||
11 | echo "${IP//./\\\\.}[" # bug was here | ||
12 | echo "192\.168\.0\.1[" | ||
13 | |||
14 | echo >'192.168.0.1[' | ||
15 | echo "${IP//./\\.}" | ||
16 | echo "${IP//./\\.}"'[' # bug was here | ||
17 | echo "${IP//./\\.}[" # bug was here | ||
18 | echo "${IP//./\\\\.}[" # bug was here | ||
19 | echo "192\.168\.0\.1[" | ||
20 | |||
21 | rm -f '192.168.0.1[' | ||
diff --git a/shell/hush_test/hush-read/read_r.tests b/shell/hush_test/hush-read/read_r.tests index 2c4cc6106..1f0a18afc 100755 --- a/shell/hush_test/hush-read/read_r.tests +++ b/shell/hush_test/hush-read/read_r.tests | |||
@@ -1,2 +1,4 @@ | |||
1 | echo -e 'test\\\nbest' | (read reply; echo "$reply") | 1 | echo 'test\ |
2 | echo -e 'test\\\nbest' | (read -r reply; echo "$reply") | 2 | best' | (read reply; echo "$reply") |
3 | echo 'test\ | ||
4 | best' | (read -r reply; echo "$reply") | ||
diff --git a/shell/hush_test/hush-signals/reap1.right b/shell/hush_test/hush-signals/reap1.right new file mode 100644 index 000000000..7326d9603 --- /dev/null +++ b/shell/hush_test/hush-signals/reap1.right | |||
@@ -0,0 +1 @@ | |||
Ok | |||
diff --git a/shell/hush_test/hush-signals/reap1.tests b/shell/hush_test/hush-signals/reap1.tests new file mode 100755 index 000000000..bf1a1f908 --- /dev/null +++ b/shell/hush_test/hush-signals/reap1.tests | |||
@@ -0,0 +1,14 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | # Must not find us alive | ||
4 | { sleep 2; kill -9 $$; } 2>/dev/null & | ||
5 | |||
6 | sleep 1 & | ||
7 | PID=$! | ||
8 | |||
9 | # We must exit the loop in one second. | ||
10 | # We had bug 5304: builtins never waited for exited children | ||
11 | while kill -0 $PID >/dev/null 2>&1; do | ||
12 | true | ||
13 | done | ||
14 | echo Ok | ||
diff --git a/shell/hush_test/hush-signals/sigint1.right b/shell/hush_test/hush-signals/sigint1.right new file mode 100644 index 000000000..a9094b056 --- /dev/null +++ b/shell/hush_test/hush-signals/sigint1.right | |||
@@ -0,0 +1 @@ | |||
Sending SIGINT to main shell PID | |||
diff --git a/shell/hush_test/hush-signals/sigint1.tests b/shell/hush_test/hush-signals/sigint1.tests new file mode 100755 index 000000000..3d483d32a --- /dev/null +++ b/shell/hush_test/hush-signals/sigint1.tests | |||
@@ -0,0 +1,41 @@ | |||
1 | # What should happen if non-interactive shell gets SIGINT? | ||
2 | |||
3 | (sleep 1; echo Sending SIGINT to main shell PID; exec kill -INT $$) & | ||
4 | |||
5 | # We create a child which exits with 0 even on SIGINT | ||
6 | # (The complex command is necessary only if SIGINT is generated by ^C, | ||
7 | # in this testcase even bare "sleep 2" would do because | ||
8 | # in the testcase we don't send SIGINT *to the child*...) | ||
9 | $THIS_SH -c 'trap "exit 0" SIGINT; sleep 2' | ||
10 | |||
11 | # In one second, we (main shell) get SIGINT here. | ||
12 | # The question is whether we should, or should not, exit. | ||
13 | |||
14 | # bash will not stop here. It will execute next command(s). | ||
15 | |||
16 | # The rationale for this is described here: | ||
17 | # http://www.cons.org/cracauer/sigint.html | ||
18 | # | ||
19 | # Basically, bash will not exit on SIGINT immediately if it waits | ||
20 | # for a child. It will wait for the child to exit. | ||
21 | # If child exits NOT by dying on SIGINT, then bash will not exit. | ||
22 | # | ||
23 | # The idea is that the following script: | ||
24 | # | emacs file.txt | ||
25 | # | more cmds | ||
26 | # User may use ^C to interrupt editor's ops like search. But then | ||
27 | # emacs exits normally. User expects that script doesn't stop. | ||
28 | # | ||
29 | # This is a nice idea, but detecting "did process really exit | ||
30 | # with SIGINT?" is racy. Consider: | ||
31 | # | bash -c 'while true; do /bin/true; done' | ||
32 | # When ^C is pressed while bash waits for /bin/true to exit, | ||
33 | # it may happen that /bin/true exits with exitcode 0 before | ||
34 | # ^C is delivered to it as SIGINT. bash will see SIGINT, then | ||
35 | # it will see that child exited with 0, and bash will NOT EXIT. | ||
36 | |||
37 | # Therefore we do not implement bash behavior. | ||
38 | # I'd say that emacs need to put itself into a separate pgrp | ||
39 | # to isolate shell from getting stray SIGINTs from ^C. | ||
40 | |||
41 | echo Next command after SIGINT was executed | ||
diff --git a/shell/hush_test/hush-signals/signal2.right b/shell/hush_test/hush-signals/signal2.right new file mode 100644 index 000000000..a2af919c0 --- /dev/null +++ b/shell/hush_test/hush-signals/signal2.right | |||
@@ -0,0 +1,3 @@ | |||
1 | child sleeps | ||
2 | child exits as expected | ||
3 | parent exits | ||
diff --git a/shell/hush_test/hush-signals/signal2.tests b/shell/hush_test/hush-signals/signal2.tests new file mode 100755 index 000000000..df639ca2c --- /dev/null +++ b/shell/hush_test/hush-signals/signal2.tests | |||
@@ -0,0 +1,18 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | $THIS_SH -c ' | ||
4 | cleanup() { | ||
5 | echo "child exits as expected" | ||
6 | exit | ||
7 | } | ||
8 | trap cleanup HUP | ||
9 | echo "child sleeps" | ||
10 | sleep 1 | ||
11 | echo "BAD exit from child!" | ||
12 | ' & | ||
13 | |||
14 | child=$! | ||
15 | sleep 0.1 # let child install handler first | ||
16 | kill -HUP $child | ||
17 | wait | ||
18 | echo "parent exits" | ||
diff --git a/shell/hush_test/hush-signals/signal3.right b/shell/hush_test/hush-signals/signal3.right new file mode 100644 index 000000000..3113ba5cf --- /dev/null +++ b/shell/hush_test/hush-signals/signal3.right | |||
@@ -0,0 +1,4 @@ | |||
1 | child sleeps | ||
2 | child got HUP | ||
3 | child exits | ||
4 | parent exits | ||
diff --git a/shell/hush_test/hush-signals/signal3.tests b/shell/hush_test/hush-signals/signal3.tests new file mode 100755 index 000000000..b56c2d97e --- /dev/null +++ b/shell/hush_test/hush-signals/signal3.tests | |||
@@ -0,0 +1,17 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | $THIS_SH -c ' | ||
4 | hup() { | ||
5 | echo "child got HUP" | ||
6 | } | ||
7 | trap hup HUP | ||
8 | echo "child sleeps" | ||
9 | sleep 1 | ||
10 | echo "child exits" | ||
11 | ' & | ||
12 | |||
13 | child=$! | ||
14 | sleep 0.1 # let child install handler first | ||
15 | kill -HUP $child | ||
16 | wait | ||
17 | echo "parent exits" | ||
diff --git a/shell/hush_test/hush-signals/signal5.right b/shell/hush_test/hush-signals/signal5.right new file mode 100644 index 000000000..7cfd4110e --- /dev/null +++ b/shell/hush_test/hush-signals/signal5.right | |||
@@ -0,0 +1,12 @@ | |||
1 | Sleeping | ||
2 | Sleeping | ||
3 | Waiting | ||
4 | 2 sec passed, sending USR1 to parent | ||
5 | USR1 received | ||
6 | Wait exit code: 138 | ||
7 | Waiting | ||
8 | 3 sec passed, sending USR1 to parent | ||
9 | USR1 received | ||
10 | Wait exit code: 138 | ||
11 | Waiting | ||
12 | Wait returned 0 | ||
diff --git a/shell/hush_test/hush-signals/signal5.tests b/shell/hush_test/hush-signals/signal5.tests new file mode 100755 index 000000000..179bcdd80 --- /dev/null +++ b/shell/hush_test/hush-signals/signal5.tests | |||
@@ -0,0 +1,14 @@ | |||
1 | trap "echo USR1 received" USR1 | ||
2 | stub() { | ||
3 | echo "Sleeping" | ||
4 | sleep $1 | ||
5 | echo "$1 sec passed, sending USR1 to parent" | ||
6 | kill -USR1 $$ | ||
7 | } | ||
8 | stub 3 & | ||
9 | stub 2 & | ||
10 | sleep 1 | ||
11 | until { echo "Waiting"; wait; } do | ||
12 | echo "Wait exit code: $?" | ||
13 | done | ||
14 | echo "Wait returned 0" | ||
diff --git a/shell/hush_test/hush-signals/signal6.right b/shell/hush_test/hush-signals/signal6.right new file mode 100644 index 000000000..df4d9306a --- /dev/null +++ b/shell/hush_test/hush-signals/signal6.right | |||
@@ -0,0 +1,2 @@ | |||
1 | got TERM | ||
2 | Done: 0 | ||
diff --git a/shell/hush_test/hush-signals/signal6.tests b/shell/hush_test/hush-signals/signal6.tests new file mode 100755 index 000000000..3ce151060 --- /dev/null +++ b/shell/hush_test/hush-signals/signal6.tests | |||
@@ -0,0 +1,2 @@ | |||
1 | { trap "echo got TERM" TERM; sleep 3; }& sleep 1; kill $!; wait | ||
2 | echo Done: $? | ||
diff --git a/shell/hush_test/hush-signals/sigquit_exec.right b/shell/hush_test/hush-signals/sigquit_exec.right new file mode 100644 index 000000000..a8041929a --- /dev/null +++ b/shell/hush_test/hush-signals/sigquit_exec.right | |||
@@ -0,0 +1,2 @@ | |||
1 | SigIgn: 0000000000000000 | ||
2 | SigIgn: 0000000000000000 | ||
diff --git a/shell/hush_test/hush-signals/sigquit_exec.tests b/shell/hush_test/hush-signals/sigquit_exec.tests new file mode 100755 index 000000000..24bda6921 --- /dev/null +++ b/shell/hush_test/hush-signals/sigquit_exec.tests | |||
@@ -0,0 +1,4 @@ | |||
1 | # Should show no masked signals in both cases. | ||
2 | # We had a bug where SIGQUIT was masked on exec. | ||
3 | grep SigIgn: /proc/self/status | ||
4 | exec grep SigIgn: /proc/self/status | ||
diff --git a/shell/hush_test/hush-standalone/noexec_gets_no_env.right b/shell/hush_test/hush-standalone/noexec_gets_no_env.right new file mode 100644 index 000000000..8522dff31 --- /dev/null +++ b/shell/hush_test/hush-standalone/noexec_gets_no_env.right | |||
@@ -0,0 +1,4 @@ | |||
1 | VAR7=VAL | ||
2 | 0 | ||
3 | VAR8=VAL | ||
4 | 0 | ||
diff --git a/shell/hush_test/hush-standalone/noexec_gets_no_env.tests b/shell/hush_test/hush-standalone/noexec_gets_no_env.tests new file mode 100755 index 000000000..0d347bdcd --- /dev/null +++ b/shell/hush_test/hush-standalone/noexec_gets_no_env.tests | |||
@@ -0,0 +1,5 @@ | |||
1 | export VAR7=VAL | ||
2 | env | grep ^VAR7= | ||
3 | echo $? | ||
4 | VAR8=VAL env | grep ^VAR8= | ||
5 | echo $? | ||
diff --git a/shell/hush_test/hush-standalone/nofork_trashes_getopt.right b/shell/hush_test/hush-standalone/nofork_trashes_getopt.right new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/shell/hush_test/hush-standalone/nofork_trashes_getopt.right | |||
@@ -0,0 +1 @@ | |||
0 | |||
diff --git a/shell/hush_test/hush-standalone/nofork_trashes_getopt.tests b/shell/hush_test/hush-standalone/nofork_trashes_getopt.tests new file mode 100755 index 000000000..f42c50730 --- /dev/null +++ b/shell/hush_test/hush-standalone/nofork_trashes_getopt.tests | |||
@@ -0,0 +1,6 @@ | |||
1 | # In this test, rm is NOFORK and it modifies getopt internal state | ||
2 | rm -f non_existent_file | ||
3 | # Subsequent hexdump is run as NOEXEC, and thus still uses this state | ||
4 | hexdump </dev/null | ||
5 | # Did hexdump segfault etc? | ||
6 | echo $? | ||
diff --git a/shell/hush_test/hush-standalone/var_standalone1.right b/shell/hush_test/hush-standalone/var_standalone1.right new file mode 100644 index 000000000..37457fd74 --- /dev/null +++ b/shell/hush_test/hush-standalone/var_standalone1.right | |||
@@ -0,0 +1 @@ | |||
Done: 1 | |||
diff --git a/shell/hush_test/hush-standalone/var_standalone1.tests b/shell/hush_test/hush-standalone/var_standalone1.tests new file mode 100755 index 000000000..1e905ba75 --- /dev/null +++ b/shell/hush_test/hush-standalone/var_standalone1.tests | |||
@@ -0,0 +1,2 @@ | |||
1 | VAR=42 $THIS_SH -c 'unset VAR; env | grep ^VAR' | ||
2 | echo Done: $? | ||