1178476Sjb#
2178476Sjb# CDDL HEADER START
3178476Sjb#
4178476Sjb# The contents of this file are subject to the terms of the
5178476Sjb# Common Development and Distribution License (the "License").
6178476Sjb# You may not use this file except in compliance with the License.
7178476Sjb#
8178476Sjb# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9178476Sjb# or http://www.opensolaris.org/os/licensing.
10178476Sjb# See the License for the specific language governing permissions
11178476Sjb# and limitations under the License.
12178476Sjb#
13178476Sjb# When distributing Covered Code, include this CDDL HEADER in each
14178476Sjb# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15178476Sjb# If applicable, add the following below this CDDL HEADER, with the
16178476Sjb# fields enclosed by brackets "[]" replaced with your own identifying
17178476Sjb# information: Portions Copyright [yyyy] [name of copyright owner]
18178476Sjb#
19178476Sjb# CDDL HEADER END
20178476Sjb#
21178476Sjb
22178476Sjb#
23178476Sjb# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24178476Sjb# Use is subject to license terms.
25178476Sjb#
26178476Sjb# ident	"%Z%%M%	%I%	%E% SMI"
27178476Sjb
28178476Sjb#
29178476Sjb# This script tests that the proc:::exit probe fires with the correct argument
30178476Sjb# when the process core dumps.  The problematic bit here is making sure that
31178476Sjb# a process _can_ dump core -- if core dumps are disabled on both a global
32178476Sjb# and per-process basis, this test will fail.  Rather than having this test
33178476Sjb# muck with coreadm(1M) settings, it will fail explicitly in this case and
34178476Sjb# provide a hint as to the problem.  In general, machines should never be
35178476Sjb# running with both per-process and global core dumps disabled -- so this
36178476Sjb# should be a non-issue in practice.
37178476Sjb#
38178476Sjb# If this fails, the script will run indefinitely; it relies on the harness
39178476Sjb# to time it out.
40178476Sjb#
41178476Sjbscript()
42178476Sjb{
43178476Sjb	$dtrace -s /dev/stdin <<EOF
44178476Sjb	proc:::exit
45178476Sjb	/curpsinfo->pr_ppid == $child &&
46178534Sjb	    execargs == "$longsleep" && args[0] == CLD_DUMPED/
47178476Sjb	{
48178476Sjb		exit(0);
49178476Sjb	}
50178476Sjb
51178476Sjb	proc:::exit
52178476Sjb	/curpsinfo->pr_ppid == $child &&
53178534Sjb	    execargs == "$longsleep" && args[0] != CLD_DUMPED/
54178476Sjb	{
55178534Sjb		printf("Child process could did dump core.");
56178476Sjb		exit(1);
57178476Sjb	}
58178476SjbEOF
59178476Sjb}
60178476Sjb
61178476Sjbsleeper()
62178476Sjb{
63178476Sjb	while true; do
64178476Sjb		$longsleep &
65178534Sjb		/bin/sleep 1
66178476Sjb		kill -SEGV $!
67178476Sjb	done
68178534Sjb	/bin/rm -f $corefile
69178476Sjb}
70178476Sjb
71178476Sjbif [ $# != 1 ]; then
72178476Sjb	echo expected one argument: '<'dtrace-path'>'
73178476Sjb	exit 2
74178476Sjbfi
75178476Sjb
76178476Sjbdtrace=$1
77178534Sjblongsleep="/bin/sleep 10000"
78178534Sjbcorefile=/tmp/sleep.core
79178476Sjb
80178476Sjbsleeper &
81178476Sjbchild=$!
82178476Sjb
83178476Sjbscript
84178476Sjbstatus=$?
85178476Sjb
86178534Sjb#pstop $child
87178534Sjb#pkill -P $child
88178476Sjbkill $child
89178534Sjb#prun $child
90178476Sjb
91178534Sjb/bin/rm -f $corefile
92178476Sjbexit $status
93