xref: /onnv-gate/usr/src/cmd/dtrace/test/tst/common/misc/tst.include.ksh (revision 3944:75371f172291)
12633Sahl#
22633Sahl# CDDL HEADER START
32633Sahl#
42633Sahl# The contents of this file are subject to the terms of the
52633Sahl# Common Development and Distribution License (the "License").
62633Sahl# You may not use this file except in compliance with the License.
72633Sahl#
82633Sahl# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92633Sahl# or http://www.opensolaris.org/os/licensing.
102633Sahl# See the License for the specific language governing permissions
112633Sahl# and limitations under the License.
122633Sahl#
132633Sahl# When distributing Covered Code, include this CDDL HEADER in each
142633Sahl# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
152633Sahl# If applicable, add the following below this CDDL HEADER, with the
162633Sahl# fields enclosed by brackets "[]" replaced with your own identifying
172633Sahl# information: Portions Copyright [yyyy] [name of copyright owner]
182633Sahl#
192633Sahl# CDDL HEADER END
202633Sahl#
212633Sahl
222633Sahl#
23*3944Sahl# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
242633Sahl# Use is subject to license terms.
252633Sahl#
26*3944Sahl# ident	"%Z%%M%	%I%	%E% SMI"
272633Sahl
282804Stomeeif [ $# != 1 ]; then
292804Stomee	echo expected one argument: '<'dtrace-path'>'
302804Stomee	exit 2
312804Stomeefi
322804Stomee
332804Stomeedtrace=$1
342633SahlCC=/usr/sfw/bin/gcc
352633SahlCFLAGS=
362633Sahl
372633Sahldoit()
382633Sahl{
392633Sahl	file=$1
402633Sahl	ofile=$2
412633Sahl	errfile=$3
422633Sahl	cfile=${TMPDIR:-/tmp}/inc.$$.$file.c
432633Sahl	cofile=${TMPDIR:-/tmp}/inc.$$.$file
442633Sahl	cat > $cfile <<EOF
452633Sahl#include <sys/$file>
462633Sahlvoid
472633Sahlmain()
482633Sahl{}
492633SahlEOF
502633Sahl	if $CC $CFLAGS -o $cofile $cfile >/dev/null 2>&1; then
512804Stomee		$dtrace -xerrtags -C -s /dev/stdin \
522633Sahl		    >/dev/null 2>$errfile <<EOF
532633Sahl#include <sys/$file>
542633SahlBEGIN
552633Sahl{
562633Sahl	exit(0);
572633Sahl}
582633SahlEOF
592633Sahl		if [ $? -ne 0 ]; then
602633Sahl			echo $inc failed: `cat $errfile | head -1` > $ofile
612633Sahl		else
622633Sahl			echo $inc succeeded > $ofile
632633Sahl		fi
642633Sahl		rm -f $errfile
652633Sahl	fi
662633Sahl
672633Sahl	rm -f $cofile $cfile 2>/dev/null
682633Sahl}
692633Sahl
702633Sahlif [ ! -x $CC ]; then
712633Sahl	echo "$0: bad compiler: $CC" >& 2
722633Sahl	exit 1
732633Sahlfi
742633Sahl
752633Sahlconcurrency=`psrinfo | wc -l`
762633Sahllet concurrency=concurrency*4
772633Sahllet i=0
782633Sahl
792633Sahlfiles=/usr/include/sys/*.h
802633Sahl
812633Sahl#
822633Sahl# There are a few files in /usr/include/sys that are known to be bad -- usually
832633Sahl# because they include static globals (!) or function bodies (!!) in the header
842633Sahl# file.  Hopefully these remain sufficiently few that the O(#files * #badfiles)
852633Sahl# algorithm, below, doesn't become a problem.  (And yes, writing scripts in
862633Sahl# something other than ksh1888 would probably be a good idea.)  If this script
872633Sahl# becomes a problem, kindly fix it by reducing the number of bad files!  (That
882633Sahl# is, fix it by fixing the broken file, not the broken script.)
892633Sahl#
90*3944Sahlbadfiles="ctype.h eri_msg.h ser_sync.h sbpro.h neti.h hook_event.h \
91*3944Sahl    bootconf.h bootstat.h dtrace.h dumphdr.h exacct_impl.h fasttrap.h \
92*3944Sahl    kobj.h kobj_impl.h ksyms.h lockstat.h smedia.h stat.h utsname.h"
932633Sahl
942633Sahlfor inc in $files; do
952633Sahl	file=`basename $inc`
962633Sahl	for bad in $badfiles; do
972633Sahl		if [ "$file" = "$bad" ]; then
982633Sahl			continue 2
992633Sahl		fi
1002633Sahl	done
1012633Sahl
1022633Sahl	ofile=${TMPDIR:-/tmp}/inc.$file.$$.out
1032633Sahl	errfile=${TMPDIR:-/tmp}/inc.$file.$$.err
1042633Sahl	doit $file $ofile $errfile &
1052633Sahl	let i=i+1
1062633Sahl
1072633Sahl	if [ $i -eq $concurrency ]; then
1082633Sahl		#
1092633Sahl		# This isn't optimal -- it creates a highly fluctuating load
1102633Sahl		# as we wait for all work to complete -- but it's an easy
1112633Sahl		# way of parallelizing work.
1122633Sahl		#
1132633Sahl		wait
1142633Sahl		let i=0
1152633Sahl	fi
1162633Sahldone
1172633Sahl
1182633Sahlwait
1192633Sahl
1202633Sahlbigofile=${TMPDIR:-/tmp}/inc.$$.out
1212633Sahl
1222633Sahlfor inc in $files; do
1232633Sahl	file=`basename $inc`
1242633Sahl	ofile=${TMPDIR:-/tmp}/inc.$file.$$.out
1252633Sahl
1262633Sahl	if [ -f $ofile ]; then
1272633Sahl		cat $ofile >> $bigofile
1282633Sahl		rm $ofile
1292633Sahl	fi
1302633Sahldone
1312633Sahl
1322633Sahlstatus=$(grep "failed:" $bigofile | wc -l)
1332633Sahlcat $bigofile
1342633Sahlrm -f $bigofile
1352633Sahlexit $status
136