xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/misc/tst.include.ksh (revision 4fceebdf03eeac0d7c58a4f70cc19b00a8c40a73)
1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or http://www.opensolaris.org/os/licensing.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26#pragma ident	"%Z%%M%	%I%	%E% SMI"
27
28if [ $# != 1 ]; then
29	echo expected one argument: '<'dtrace-path'>'
30	exit 2
31fi
32
33dtrace=$1
34CC=/usr/sfw/bin/gcc
35CFLAGS=
36
37doit()
38{
39	file=$1
40	ofile=$2
41	errfile=$3
42	cfile=${TMPDIR:-/tmp}/inc.$$.$file.c
43	cofile=${TMPDIR:-/tmp}/inc.$$.$file
44	cat > $cfile <<EOF
45#include <sys/$file>
46void
47main()
48{}
49EOF
50	if $CC $CFLAGS -o $cofile $cfile >/dev/null 2>&1; then
51		$dtrace -xerrtags -C -s /dev/stdin \
52		    >/dev/null 2>$errfile <<EOF
53#include <sys/$file>
54BEGIN
55{
56	exit(0);
57}
58EOF
59		if [ $? -ne 0 ]; then
60			echo $inc failed: `cat $errfile | head -1` > $ofile
61		else
62			echo $inc succeeded > $ofile
63		fi
64		rm -f $errfile
65	fi
66
67	rm -f $cofile $cfile 2>/dev/null
68}
69
70if [ ! -x $CC ]; then
71	echo "$0: bad compiler: $CC" >& 2
72	exit 1
73fi
74
75concurrency=`psrinfo | wc -l`
76let concurrency=concurrency*4
77let i=0
78
79files=/usr/include/sys/*.h
80
81#
82# There are a few files in /usr/include/sys that are known to be bad -- usually
83# because they include static globals (!) or function bodies (!!) in the header
84# file.  Hopefully these remain sufficiently few that the O(#files * #badfiles)
85# algorithm, below, doesn't become a problem.  (And yes, writing scripts in
86# something other than ksh1888 would probably be a good idea.)  If this script
87# becomes a problem, kindly fix it by reducing the number of bad files!  (That
88# is, fix it by fixing the broken file, not the broken script.)
89#
90badfiles="ctype.h eri_msg.h ser_sync.h sbpro.h"
91
92for inc in $files; do
93	file=`basename $inc`
94	for bad in $badfiles; do
95		if [ "$file" = "$bad" ]; then
96			continue 2
97		fi
98	done
99
100	ofile=${TMPDIR:-/tmp}/inc.$file.$$.out
101	errfile=${TMPDIR:-/tmp}/inc.$file.$$.err
102	doit $file $ofile $errfile &
103	let i=i+1
104
105	if [ $i -eq $concurrency ]; then
106		#
107		# This isn't optimal -- it creates a highly fluctuating load
108		# as we wait for all work to complete -- but it's an easy
109		# way of parallelizing work.
110		#
111		wait
112		let i=0
113	fi
114done
115
116wait
117
118bigofile=${TMPDIR:-/tmp}/inc.$$.out
119
120for inc in $files; do
121	file=`basename $inc`
122	ofile=${TMPDIR:-/tmp}/inc.$file.$$.out
123
124	if [ -f $ofile ]; then
125		cat $ofile >> $bigofile
126		rm $ofile
127	fi
128done
129
130status=$(grep "failed:" $bigofile | wc -l)
131cat $bigofile
132rm -f $bigofile
133exit $status
134