aboutsummaryrefslogtreecommitdiff
path: root/bin/sh/tests/execution
diff options
context:
space:
mode:
Diffstat (limited to 'bin/sh/tests/execution')
-rw-r--r--bin/sh/tests/execution/Makefile53
-rw-r--r--bin/sh/tests/execution/bg1.03
-rw-r--r--bin/sh/tests/execution/bg10.04
-rw-r--r--bin/sh/tests/execution/bg10.0.stdout1
-rw-r--r--bin/sh/tests/execution/bg2.05
-rw-r--r--bin/sh/tests/execution/bg3.05
-rw-r--r--bin/sh/tests/execution/bg4.06
-rw-r--r--bin/sh/tests/execution/bg5.04
-rw-r--r--bin/sh/tests/execution/bg6.04
-rw-r--r--bin/sh/tests/execution/bg6.0.stdout1
-rw-r--r--bin/sh/tests/execution/bg7.05
-rw-r--r--bin/sh/tests/execution/bg8.05
-rw-r--r--bin/sh/tests/execution/bg9.05
-rw-r--r--bin/sh/tests/execution/fork1.010
-rw-r--r--bin/sh/tests/execution/fork2.09
-rw-r--r--bin/sh/tests/execution/fork3.04
-rw-r--r--bin/sh/tests/execution/func1.04
-rw-r--r--bin/sh/tests/execution/func2.012
-rw-r--r--bin/sh/tests/execution/func3.07
-rw-r--r--bin/sh/tests/execution/hash1.012
-rw-r--r--bin/sh/tests/execution/int-cmd1.03
-rw-r--r--bin/sh/tests/execution/killed1.08
-rw-r--r--bin/sh/tests/execution/killed2.010
-rw-r--r--bin/sh/tests/execution/not1.04
-rw-r--r--bin/sh/tests/execution/not2.06
-rw-r--r--bin/sh/tests/execution/path1.015
-rw-r--r--bin/sh/tests/execution/redir1.027
-rw-r--r--bin/sh/tests/execution/redir2.029
-rw-r--r--bin/sh/tests/execution/redir3.03
-rw-r--r--bin/sh/tests/execution/redir4.04
-rw-r--r--bin/sh/tests/execution/redir5.03
-rw-r--r--bin/sh/tests/execution/redir6.021
-rw-r--r--bin/sh/tests/execution/redir7.021
-rw-r--r--bin/sh/tests/execution/set-n1.07
-rw-r--r--bin/sh/tests/execution/set-n2.05
-rw-r--r--bin/sh/tests/execution/set-n3.04
-rw-r--r--bin/sh/tests/execution/set-n4.03
-rw-r--r--bin/sh/tests/execution/set-x1.08
-rw-r--r--bin/sh/tests/execution/set-x2.09
-rw-r--r--bin/sh/tests/execution/set-x3.09
-rw-r--r--bin/sh/tests/execution/shellproc1.011
-rw-r--r--bin/sh/tests/execution/subshell1.06
-rw-r--r--bin/sh/tests/execution/subshell1.0.stdout2
-rw-r--r--bin/sh/tests/execution/subshell2.010
-rw-r--r--bin/sh/tests/execution/subshell3.04
-rw-r--r--bin/sh/tests/execution/subshell4.03
-rw-r--r--bin/sh/tests/execution/unknown1.029
-rw-r--r--bin/sh/tests/execution/var-assign1.03
48 files changed, 426 insertions, 0 deletions
diff --git a/bin/sh/tests/execution/Makefile b/bin/sh/tests/execution/Makefile
new file mode 100644
index 000000000000..302d0d824c41
--- /dev/null
+++ b/bin/sh/tests/execution/Makefile
@@ -0,0 +1,53 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+FILESDIR= ${TESTSBASE}/bin/sh/execution
+KYUAFILE= no
+
+FILES= bg1.0
+FILES+= bg2.0
+FILES+= bg3.0
+FILES+= bg4.0
+FILES+= bg5.0
+FILES+= bg6.0 bg6.0.stdout
+FILES+= bg7.0
+FILES+= bg8.0
+FILES+= bg9.0
+FILES+= bg10.0 bg10.0.stdout
+FILES+= fork1.0
+FILES+= fork2.0
+FILES+= fork3.0
+FILES+= func1.0
+FILES+= func2.0
+FILES+= func3.0
+FILES+= hash1.0
+FILES+= int-cmd1.0
+FILES+= killed1.0
+FILES+= killed2.0
+FILES+= not1.0
+FILES+= not2.0
+FILES+= path1.0
+FILES+= redir1.0
+FILES+= redir2.0
+FILES+= redir3.0
+FILES+= redir4.0
+FILES+= redir5.0
+FILES+= redir6.0
+FILES+= redir7.0
+FILES+= set-n1.0
+FILES+= set-n2.0
+FILES+= set-n3.0
+FILES+= set-n4.0
+FILES+= set-x1.0
+FILES+= set-x2.0
+FILES+= set-x3.0
+FILES+= shellproc1.0
+FILES+= subshell1.0 subshell1.0.stdout
+FILES+= subshell2.0
+FILES+= subshell3.0
+FILES+= subshell4.0
+FILES+= unknown1.0
+FILES+= var-assign1.0
+
+.include <bsd.test.mk>
diff --git a/bin/sh/tests/execution/bg1.0 b/bin/sh/tests/execution/bg1.0
new file mode 100644
index 000000000000..edb92ae2ddd0
--- /dev/null
+++ b/bin/sh/tests/execution/bg1.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+: `false` &
diff --git a/bin/sh/tests/execution/bg10.0 b/bin/sh/tests/execution/bg10.0
new file mode 100644
index 000000000000..44a25dc23b2e
--- /dev/null
+++ b/bin/sh/tests/execution/bg10.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+# The redirection overrides the </dev/null implicit in a background command.
+
+echo yes | ${SH} -c '{ cat & wait; } <&0'
diff --git a/bin/sh/tests/execution/bg10.0.stdout b/bin/sh/tests/execution/bg10.0.stdout
new file mode 100644
index 000000000000..7cfab5b05d62
--- /dev/null
+++ b/bin/sh/tests/execution/bg10.0.stdout
@@ -0,0 +1 @@
+yes
diff --git a/bin/sh/tests/execution/bg2.0 b/bin/sh/tests/execution/bg2.0
new file mode 100644
index 000000000000..2e2fbc53bd26
--- /dev/null
+++ b/bin/sh/tests/execution/bg2.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+f() { return 42; }
+f
+: | : &
diff --git a/bin/sh/tests/execution/bg3.0 b/bin/sh/tests/execution/bg3.0
new file mode 100644
index 000000000000..359fc6f476e6
--- /dev/null
+++ b/bin/sh/tests/execution/bg3.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+f() { return 42; }
+f
+(:) &
diff --git a/bin/sh/tests/execution/bg4.0 b/bin/sh/tests/execution/bg4.0
new file mode 100644
index 000000000000..25e4f4e34fa5
--- /dev/null
+++ b/bin/sh/tests/execution/bg4.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+x=''
+: ${x:=1} &
+wait
+exit ${x:-0}
diff --git a/bin/sh/tests/execution/bg5.0 b/bin/sh/tests/execution/bg5.0
new file mode 100644
index 000000000000..cc9ceaa41d4e
--- /dev/null
+++ b/bin/sh/tests/execution/bg5.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+# A background command has an implicit </dev/null redirection.
+
+echo bad | ${SH} -c '{ cat & wait; }'
diff --git a/bin/sh/tests/execution/bg6.0 b/bin/sh/tests/execution/bg6.0
new file mode 100644
index 000000000000..b0faf9e73708
--- /dev/null
+++ b/bin/sh/tests/execution/bg6.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+# The redirection overrides the </dev/null implicit in a background command.
+
+echo yes | ${SH} -c '{ cat & wait; } </dev/stdin'
diff --git a/bin/sh/tests/execution/bg6.0.stdout b/bin/sh/tests/execution/bg6.0.stdout
new file mode 100644
index 000000000000..7cfab5b05d62
--- /dev/null
+++ b/bin/sh/tests/execution/bg6.0.stdout
@@ -0,0 +1 @@
+yes
diff --git a/bin/sh/tests/execution/bg7.0 b/bin/sh/tests/execution/bg7.0
new file mode 100644
index 000000000000..f771edc56cde
--- /dev/null
+++ b/bin/sh/tests/execution/bg7.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+# The redirection does not apply to the background command, and therefore
+# does not override the implicit </dev/null.
+
+echo bad | ${SH} -c '</dev/null; { cat & wait; }'
diff --git a/bin/sh/tests/execution/bg8.0 b/bin/sh/tests/execution/bg8.0
new file mode 100644
index 000000000000..33667cb1922b
--- /dev/null
+++ b/bin/sh/tests/execution/bg8.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+# The redirection does not apply to the background command, and therefore
+# does not override the implicit </dev/null.
+
+echo bad | ${SH} -c 'command eval \) </dev/null 2>/dev/null; { cat & wait; }'
diff --git a/bin/sh/tests/execution/bg9.0 b/bin/sh/tests/execution/bg9.0
new file mode 100644
index 000000000000..64fde3e3e333
--- /dev/null
+++ b/bin/sh/tests/execution/bg9.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+# The redirection does not apply to the background command, and therefore
+# does not override the implicit </dev/null.
+
+echo bad | ${SH} -c 'command eval eval \\\) \</dev/null 2>/dev/null; { cat & wait; }'
diff --git a/bin/sh/tests/execution/fork1.0 b/bin/sh/tests/execution/fork1.0
new file mode 100644
index 000000000000..2eeac79ae8c3
--- /dev/null
+++ b/bin/sh/tests/execution/fork1.0
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+shname=${SH%% *}
+shname=${shname##*/}
+
+result=$(${SH} -c 'ps -p $$ -o comm=')
+test "$result" = "ps" || exit 1
+
+result=$(${SH} -c 'ps -p $$ -o comm=; :')
+test "$result" = "$shname" || exit 1
diff --git a/bin/sh/tests/execution/fork2.0 b/bin/sh/tests/execution/fork2.0
new file mode 100644
index 000000000000..62a25379123c
--- /dev/null
+++ b/bin/sh/tests/execution/fork2.0
@@ -0,0 +1,9 @@
+# $FreeBSD$
+
+result=$(${SH} -c '(/bin/sleep 1)& sleep 0.1; ps -p $! -o comm=; kill $!')
+test "$result" = sleep || exit 1
+
+result=$(${SH} -c '{ trap "echo trapped" EXIT; (/usr/bin/true); } & wait')
+test "$result" = trapped || exit 1
+
+exit 0
diff --git a/bin/sh/tests/execution/fork3.0 b/bin/sh/tests/execution/fork3.0
new file mode 100644
index 000000000000..3cb678c2d08a
--- /dev/null
+++ b/bin/sh/tests/execution/fork3.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+result=$(${SH} -c 'f() { ps -p $$ -o comm=; }; f')
+test "$result" = "ps"
diff --git a/bin/sh/tests/execution/func1.0 b/bin/sh/tests/execution/func1.0
new file mode 100644
index 000000000000..29fcc077b592
--- /dev/null
+++ b/bin/sh/tests/execution/func1.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+MALLOC_OPTIONS=J ${SH} -c 'g() { g() { :; }; :; }; g' &&
+MALLOC_OPTIONS=J ${SH} -c 'g() { unset -f g; :; }; g'
diff --git a/bin/sh/tests/execution/func2.0 b/bin/sh/tests/execution/func2.0
new file mode 100644
index 000000000000..9830b5e8a7cf
--- /dev/null
+++ b/bin/sh/tests/execution/func2.0
@@ -0,0 +1,12 @@
+# $FreeBSD$
+# The empty pairs of braces here are to test that this does not cause a crash.
+
+f() { }
+f
+hash -v f >/dev/null
+f() { { }; }
+f
+hash -v f >/dev/null
+f() { { } }
+f
+hash -v f >/dev/null
diff --git a/bin/sh/tests/execution/func3.0 b/bin/sh/tests/execution/func3.0
new file mode 100644
index 000000000000..e0ed581f85ef
--- /dev/null
+++ b/bin/sh/tests/execution/func3.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+# This may fail when parsing or when defining the function, or the definition
+# may silently do nothing. In no event may the function be executed.
+
+${SH} -c 'unset() { echo overriding function executed, bad; }; v=1; unset v; exit "${v-0}"' 2>/dev/null
+:
diff --git a/bin/sh/tests/execution/hash1.0 b/bin/sh/tests/execution/hash1.0
new file mode 100644
index 000000000000..a645c2aef735
--- /dev/null
+++ b/bin/sh/tests/execution/hash1.0
@@ -0,0 +1,12 @@
+# $FreeBSD$
+
+T=`mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX"` || exit
+trap 'rm -rf "${T}"' 0
+PATH=$T:$PATH
+ls -ld . >/dev/null
+cat <<EOF >"$T/ls"
+:
+EOF
+chmod 755 "$T/ls"
+PATH=$PATH
+ls -ld .
diff --git a/bin/sh/tests/execution/int-cmd1.0 b/bin/sh/tests/execution/int-cmd1.0
new file mode 100644
index 000000000000..a1f097b774d6
--- /dev/null
+++ b/bin/sh/tests/execution/int-cmd1.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+! echo echo bad | $SH -ic 'fi' 2>/dev/null
diff --git a/bin/sh/tests/execution/killed1.0 b/bin/sh/tests/execution/killed1.0
new file mode 100644
index 000000000000..41d3e055723e
--- /dev/null
+++ b/bin/sh/tests/execution/killed1.0
@@ -0,0 +1,8 @@
+# $FreeBSD$
+# Sometimes the "Killed" message is not flushed soon enough and it
+# is redirected along with the output of a builtin.
+# Do not change the semicolon to a newline as it would hide the bug.
+
+exec 3>&1
+exec >/dev/null 2>&1
+${SH} -c 'kill -9 $$'; : >&3 2>&3
diff --git a/bin/sh/tests/execution/killed2.0 b/bin/sh/tests/execution/killed2.0
new file mode 100644
index 000000000000..7ff3fe2900d1
--- /dev/null
+++ b/bin/sh/tests/execution/killed2.0
@@ -0,0 +1,10 @@
+# $FreeBSD$
+# Most shells print a message when a foreground job is killed by a signal.
+# POSIX allows this, provided the message is sent to stderr, not stdout.
+# Some trickery is needed to capture the message as redirecting stderr of
+# the command itself does not affect it. The colon command ensures that
+# the subshell forks for ${SH}.
+
+exec 3>&1
+r=`(${SH} -c 'kill $$'; :) 2>&1 >&3`
+[ -n "$r" ]
diff --git a/bin/sh/tests/execution/not1.0 b/bin/sh/tests/execution/not1.0
new file mode 100644
index 000000000000..12c6265a9282
--- /dev/null
+++ b/bin/sh/tests/execution/not1.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+f() { ! return $1; }
+f 0 && ! f 1
diff --git a/bin/sh/tests/execution/not2.0 b/bin/sh/tests/execution/not2.0
new file mode 100644
index 000000000000..1b128d096716
--- /dev/null
+++ b/bin/sh/tests/execution/not2.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+while :; do
+ ! break
+ exit 3
+done
diff --git a/bin/sh/tests/execution/path1.0 b/bin/sh/tests/execution/path1.0
new file mode 100644
index 000000000000..50829d629a4d
--- /dev/null
+++ b/bin/sh/tests/execution/path1.0
@@ -0,0 +1,15 @@
+# $FreeBSD$
+# Some builtins should not be overridable via PATH.
+
+set -e
+T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX)
+trap 'rm -rf ${T}' 0
+echo '#!/bin/sh
+echo bad' >"$T/cd"
+chmod 755 "$T/cd"
+cd /bin
+oPATH=$PATH
+PATH=$T:$PATH:%builtin
+cd /
+PATH=$oPATH
+[ "$(pwd)" = / ]
diff --git a/bin/sh/tests/execution/redir1.0 b/bin/sh/tests/execution/redir1.0
new file mode 100644
index 000000000000..dd0011f064b0
--- /dev/null
+++ b/bin/sh/tests/execution/redir1.0
@@ -0,0 +1,27 @@
+# $FreeBSD$
+trap ': $((brokenpipe+=1))' PIPE
+
+P=${TMPDIR:-/tmp}
+cd $P
+T=$(mktemp -d sh-test.XXXXXX)
+cd $T
+
+brokenpipe=0
+mkfifo fifo1 fifo2
+read dummy >fifo2 <fifo1 &
+{
+ exec 4>fifo2
+} 3<fifo2 # Formerly, sh would keep fd 3 and a duplicate of it open.
+echo dummy >fifo1
+if [ $brokenpipe -ne 0 ]; then
+ rc=3
+fi
+wait
+echo dummy >&4 2>/dev/null
+if [ $brokenpipe -eq 1 ]; then
+ : ${rc:=0}
+fi
+
+rm fifo1 fifo2
+rmdir ${P}/${T}
+exit ${rc:-3}
diff --git a/bin/sh/tests/execution/redir2.0 b/bin/sh/tests/execution/redir2.0
new file mode 100644
index 000000000000..1588105f599a
--- /dev/null
+++ b/bin/sh/tests/execution/redir2.0
@@ -0,0 +1,29 @@
+# $FreeBSD$
+trap ': $((brokenpipe+=1))' PIPE
+
+P=${TMPDIR:-/tmp}
+cd $P
+T=$(mktemp -d sh-test.XXXXXX)
+cd $T
+
+brokenpipe=0
+mkfifo fifo1 fifo2
+{
+ {
+ exec ${SH} -c 'exec <fifo1; read dummy'
+ } 7<&- # fifo2 should be kept open, but not passed to programs
+ true
+} 7<fifo2 &
+
+exec 4>fifo2
+exec 3>fifo1
+echo dummy >&4 2>/dev/null
+if [ $brokenpipe -eq 1 ]; then
+ : ${rc:=0}
+fi
+echo dummy >&3
+wait
+
+rm fifo1 fifo2
+rmdir ${P}/${T}
+exit ${rc:-3}
diff --git a/bin/sh/tests/execution/redir3.0 b/bin/sh/tests/execution/redir3.0
new file mode 100644
index 000000000000..d68e4504ed3d
--- /dev/null
+++ b/bin/sh/tests/execution/redir3.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+3>&- 3>&-
diff --git a/bin/sh/tests/execution/redir4.0 b/bin/sh/tests/execution/redir4.0
new file mode 100644
index 000000000000..57054c17c45f
--- /dev/null
+++ b/bin/sh/tests/execution/redir4.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+{ echo bad 0>&3; } 2>/dev/null 3>/dev/null 3>&-
+exit 0
diff --git a/bin/sh/tests/execution/redir5.0 b/bin/sh/tests/execution/redir5.0
new file mode 100644
index 000000000000..707ca68f737a
--- /dev/null
+++ b/bin/sh/tests/execution/redir5.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+{ (echo bad) >/dev/null; } </dev/null
diff --git a/bin/sh/tests/execution/redir6.0 b/bin/sh/tests/execution/redir6.0
new file mode 100644
index 000000000000..4e3ac0cae055
--- /dev/null
+++ b/bin/sh/tests/execution/redir6.0
@@ -0,0 +1,21 @@
+# $FreeBSD$
+
+failures=0
+
+check() {
+ if [ "$2" != "$3" ]; then
+ echo "Failure at $1" >&2
+ failures=$((failures + 1))
+ fi
+}
+
+check $LINENO "$(trap "echo bye" EXIT; : >/dev/null)" bye
+check $LINENO "$(trap "echo bye" EXIT; { :; } >/dev/null)" bye
+check $LINENO "$(trap "echo bye" EXIT; (:) >/dev/null)" bye
+check $LINENO "$(trap "echo bye" EXIT; (: >/dev/null))" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; : >/dev/null')" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; { :; } >/dev/null')" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; (:) >/dev/null')" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; (: >/dev/null)')" bye
+
+exit $((failures > 0))
diff --git a/bin/sh/tests/execution/redir7.0 b/bin/sh/tests/execution/redir7.0
new file mode 100644
index 000000000000..2487bcf2fc0d
--- /dev/null
+++ b/bin/sh/tests/execution/redir7.0
@@ -0,0 +1,21 @@
+# $FreeBSD$
+
+failures=0
+
+check() {
+ if [ "$2" != "$3" ]; then
+ echo "Failure at $1" >&2
+ failures=$((failures + 1))
+ fi
+}
+
+check $LINENO "$(trap "echo bye" EXIT; f() { :; }; f >/dev/null)" bye
+check $LINENO "$(trap "echo bye" EXIT; f() { :; }; { f; } >/dev/null)" bye
+check $LINENO "$(trap "echo bye" EXIT; f() { :; }; (f) >/dev/null)" bye
+check $LINENO "$(trap "echo bye" EXIT; f() { :; }; (f >/dev/null))" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; f() { :; }; f >/dev/null')" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; f() { :; }; { f; } >/dev/null')" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; f() { :; }; (f) >/dev/null')" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; f() { :; }; (f >/dev/null)')" bye
+
+exit $((failures > 0))
diff --git a/bin/sh/tests/execution/set-n1.0 b/bin/sh/tests/execution/set-n1.0
new file mode 100644
index 000000000000..14c9b9396ada
--- /dev/null
+++ b/bin/sh/tests/execution/set-n1.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+v=$( ($SH -n <<'EOF'
+for
+EOF
+) 2>&1 >/dev/null)
+[ $? -ne 0 ] && [ -n "$v" ]
diff --git a/bin/sh/tests/execution/set-n2.0 b/bin/sh/tests/execution/set-n2.0
new file mode 100644
index 000000000000..c7f31629f474
--- /dev/null
+++ b/bin/sh/tests/execution/set-n2.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+$SH -n <<'EOF'
+echo bad
+EOF
diff --git a/bin/sh/tests/execution/set-n3.0 b/bin/sh/tests/execution/set-n3.0
new file mode 100644
index 000000000000..24a9159fdeb9
--- /dev/null
+++ b/bin/sh/tests/execution/set-n3.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+v=$( ($SH -nc 'for') 2>&1 >/dev/null)
+[ $? -ne 0 ] && [ -n "$v" ]
diff --git a/bin/sh/tests/execution/set-n4.0 b/bin/sh/tests/execution/set-n4.0
new file mode 100644
index 000000000000..36985084b26b
--- /dev/null
+++ b/bin/sh/tests/execution/set-n4.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+$SH -nc 'echo bad'
diff --git a/bin/sh/tests/execution/set-x1.0 b/bin/sh/tests/execution/set-x1.0
new file mode 100644
index 000000000000..7fe1dbf1076b
--- /dev/null
+++ b/bin/sh/tests/execution/set-x1.0
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+key='must_contain_this'
+{ r=`set -x; { : "$key"; } 2>&1 >/dev/null`; } 2>/dev/null
+case $r in
+*"$key"*) true ;;
+*) false ;;
+esac
diff --git a/bin/sh/tests/execution/set-x2.0 b/bin/sh/tests/execution/set-x2.0
new file mode 100644
index 000000000000..56d54e38d251
--- /dev/null
+++ b/bin/sh/tests/execution/set-x2.0
@@ -0,0 +1,9 @@
+# $FreeBSD$
+
+key='must contain this'
+PS4="$key+ "
+{ r=`set -x; { :; } 2>&1 >/dev/null`; } 2>/dev/null
+case $r in
+*"$key"*) true ;;
+*) false ;;
+esac
diff --git a/bin/sh/tests/execution/set-x3.0 b/bin/sh/tests/execution/set-x3.0
new file mode 100644
index 000000000000..1ca57aca6baa
--- /dev/null
+++ b/bin/sh/tests/execution/set-x3.0
@@ -0,0 +1,9 @@
+# $FreeBSD$
+
+key='must contain this'
+PS4='$key+ '
+{ r=`set -x; { :; } 2>&1 >/dev/null`; } 2>/dev/null
+case $r in
+*"$key"*) true ;;
+*) false ;;
+esac
diff --git a/bin/sh/tests/execution/shellproc1.0 b/bin/sh/tests/execution/shellproc1.0
new file mode 100644
index 000000000000..1326bc27f1c1
--- /dev/null
+++ b/bin/sh/tests/execution/shellproc1.0
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+T=`mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX"` || exit
+trap 'rm -rf "${T}"' 0
+cat <<EOF >"$T/testshellproc"
+printf 'this '
+echo is a test
+EOF
+chmod 755 "$T/testshellproc"
+PATH=$T:$PATH
+[ "`testshellproc`" = "this is a test" ]
diff --git a/bin/sh/tests/execution/subshell1.0 b/bin/sh/tests/execution/subshell1.0
new file mode 100644
index 000000000000..347806ed45ac
--- /dev/null
+++ b/bin/sh/tests/execution/subshell1.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+(eval "cd /
+v=$(printf %0100000d 1)
+echo \${#v}")
+echo end
diff --git a/bin/sh/tests/execution/subshell1.0.stdout b/bin/sh/tests/execution/subshell1.0.stdout
new file mode 100644
index 000000000000..8c71af3cd79f
--- /dev/null
+++ b/bin/sh/tests/execution/subshell1.0.stdout
@@ -0,0 +1,2 @@
+100000
+end
diff --git a/bin/sh/tests/execution/subshell2.0 b/bin/sh/tests/execution/subshell2.0
new file mode 100644
index 000000000000..32164495c9ca
--- /dev/null
+++ b/bin/sh/tests/execution/subshell2.0
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+f() {
+ x=2
+}
+(
+ x=1
+ f
+ [ "$x" = 2 ]
+)
diff --git a/bin/sh/tests/execution/subshell3.0 b/bin/sh/tests/execution/subshell3.0
new file mode 100644
index 000000000000..9a87acb15e1c
--- /dev/null
+++ b/bin/sh/tests/execution/subshell3.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+(false; exit) && exit 3
+exit 0
diff --git a/bin/sh/tests/execution/subshell4.0 b/bin/sh/tests/execution/subshell4.0
new file mode 100644
index 000000000000..b39edb12eb2c
--- /dev/null
+++ b/bin/sh/tests/execution/subshell4.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+(eval "set v=1"; false) && echo bad; :
diff --git a/bin/sh/tests/execution/unknown1.0 b/bin/sh/tests/execution/unknown1.0
new file mode 100644
index 000000000000..45f541e6eeea
--- /dev/null
+++ b/bin/sh/tests/execution/unknown1.0
@@ -0,0 +1,29 @@
+# $FreeBSD$
+
+nosuchtool 2>/dev/null
+[ $? -ne 127 ] && exit 1
+/var/empty/nosuchtool 2>/dev/null
+[ $? -ne 127 ] && exit 1
+(nosuchtool) 2>/dev/null
+[ $? -ne 127 ] && exit 1
+(/var/empty/nosuchtool) 2>/dev/null
+[ $? -ne 127 ] && exit 1
+/ 2>/dev/null
+[ $? -ne 126 ] && exit 1
+PATH=/usr bin 2>/dev/null
+[ $? -ne 126 ] && exit 1
+
+dummy=$(nosuchtool 2>/dev/null)
+[ $? -ne 127 ] && exit 1
+dummy=$(/var/empty/nosuchtool 2>/dev/null)
+[ $? -ne 127 ] && exit 1
+dummy=$( (nosuchtool) 2>/dev/null)
+[ $? -ne 127 ] && exit 1
+dummy=$( (/var/empty/nosuchtool) 2>/dev/null)
+[ $? -ne 127 ] && exit 1
+dummy=$(/ 2>/dev/null)
+[ $? -ne 126 ] && exit 1
+dummy=$(PATH=/usr bin 2>/dev/null)
+[ $? -ne 126 ] && exit 1
+
+exit 0
diff --git a/bin/sh/tests/execution/var-assign1.0 b/bin/sh/tests/execution/var-assign1.0
new file mode 100644
index 000000000000..26e54249c1cc
--- /dev/null
+++ b/bin/sh/tests/execution/var-assign1.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+[ "$(HOME=/etc HOME=/ cd && pwd)" = / ]