7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# CDDL HEADER START
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# The contents of this file are subject to the terms of the
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# Common Development and Distribution License (the "License").
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# You may not use this file except in compliance with the License.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# or http://www.opensolaris.org/os/licensing.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# See the License for the specific language governing permissions
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# and limitations under the License.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# When distributing Covered Code, include this CDDL HEADER in each
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# If applicable, add the following below this CDDL HEADER, with the
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# fields enclosed by brackets "[]" replaced with your own identifying
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# information: Portions Copyright [yyyy] [name of copyright owner]
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# CDDL HEADER END
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# This test checks whether ksh93 (like ksh88) generates calls a
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# CHLD/SIGCHLD trap for background jobs and _not_ for foreground jobs.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# This was reported as CR #6722134 ("*ksh93* (20080624_snapshot)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# doesn't execute CHLD trap"):
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# -- snip --
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# With "set -o monitor" on and "set -o notify" off, ksh88 executes the CHLD
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# trap while waiting for interactive input when a background job completes.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# ksh93 appears not to execute the CHLD trap when a background job terminates.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# Probably related: I noticed that with no CHLD trap set, but -o monitor and
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# -o notify set, there should be a similar asynchronous job completion notice.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# It works in ksh88 but not in this ksh93 build.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# -- snip --
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# test setup
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinfunction err_exit
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin{
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin print -u2 -n "\t"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin print -u2 -r ${Command}[$1]: "${@:2}"
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner (( Errors < 127 && Errors++ ))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin}
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinalias err_exit='err_exit $LINENO'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzset -o nounset
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland MainzCommand=${0##*/}
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chininteger Errors=0
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin##
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin## test one:
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin##
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chins="$($SHELL -c '
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinset -o errexit
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chininteger i
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chintrap "print got_child" SIGCHLD
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinsleep 5 &
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinsleep 7 &
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinfor ((i=0 ; i < 15 ; i++)) ; do
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin print $i
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sleep 1
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin # external, non-background command for which a SIGCHLD should
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin # _not_ be fired
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin /bin/true >/dev/null
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chindone
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinprint "loop finished"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinwait
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinprint "done"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin' 2>&1 )" || err_exit "test loop failed."
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$s" == ~(Er)$'14\nloop finished\ndone' ]] || err_exit "Expected '14\nloop finished\ndone' at the end of the output, got ${s}."
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$s" == ~(El)$'0\n1\n2' ]] || err_exit "Expected '0\n1\n2' as at the beginning of the output, got ${s}."
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chininteger count
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin(( count=$(fgrep "got_child" <<< "$s" | wc -l) )) || err_exit "counting failed."
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin(( count == 2 )) || err_exit "Expected count==2, got count==${count}."
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin##
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin## test two:
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin## (same as test "one" except that this test has one more "sleep" child)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin##
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chins="$($SHELL -c '
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinset -o errexit
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chininteger i
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chintrap "print got_child" SIGCHLD
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinsleep 5 &
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinsleep 7 &
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinsleep 9 &
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinfor ((i=0 ; i < 15 ; i++)) ; do
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin print $i
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sleep 1
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin # external, non-background command for which a SIGCHLD should
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin # _not_ be fired
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin /bin/true >/dev/null
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chindone
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinprint "loop finished"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinwait
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinprint "done"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin' 2>&1 )" || err_exit "test loop failed."
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$s" == ~(Er)$'14\nloop finished\ndone' ]] || err_exit "Expected '14\nloop finished\ndone' at the end of the output, got ${s}."
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$s" == ~(El)$'0\n1\n2' ]] || err_exit "Expected '0\n1\n2' as at the beginning of the output, got ${s}."
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin(( count=$(fgrep "got_child" <<< "$s" | wc -l) )) || err_exit "counting failed."
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin(( count == 3 )) || err_exit "Expected count==3, got count==${count}."
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# tests done
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinexit $((Errors))