8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / dtrace / test / tst / common / misc / tst.include.ksh
blob5b57805d12f5dba07610faf7286bac41eb3be20a
2 # CDDL HEADER START
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.
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.
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]
19 # CDDL HEADER END
23 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
27 if [ $# != 1 ]; then
28 echo expected one argument: '<'dtrace-path'>'
29 exit 2
32 dtrace=$1
33 CC=`which gcc`
34 CFLAGS=
36 doit()
38 file=$1
39 ofile=$2
40 errfile=$3
41 cfile=${TMPDIR:-/tmp}/inc.$$.$file.c
42 cofile=${TMPDIR:-/tmp}/inc.$$.$file
43 cat > $cfile <<EOF
44 #include <sys/$file>
45 void
46 main()
48 EOF
49 if $CC $CFLAGS -o $cofile $cfile >/dev/null 2>&1; then
50 $dtrace -xerrtags -C -s /dev/stdin \
51 >/dev/null 2>$errfile <<EOF
52 #include <sys/$file>
53 BEGIN
55 exit(0);
57 EOF
58 if [ $? -ne 0 ]; then
59 echo $inc failed: `cat $errfile | head -1` > $ofile
60 else
61 echo $inc succeeded > $ofile
63 rm -f $errfile
66 rm -f $cofile $cfile 2>/dev/null
69 if [ ! -x $CC ]; then
70 echo "$0: bad compiler: $CC" >& 2
71 exit 1
74 concurrency=`psrinfo | wc -l`
75 let concurrency=concurrency*4
76 let i=0
78 files=/usr/include/sys/*.h
81 # There are a few files in /usr/include/sys that are known to be bad -- usually
82 # because they include static globals (!) or function bodies (!!) in the header
83 # file. Hopefully these remain sufficiently few that the O(#files * #badfiles)
84 # algorithm, below, doesn't become a problem. (And yes, writing scripts in
85 # something other than ksh would probably be a good idea.) If this script
86 # becomes a problem, kindly fix it by reducing the number of bad files! (That
87 # is, fix it by fixing the broken file, not the broken script.)
89 badfiles="\
90 bootconf.h \
91 bootstat.h \
92 ctype.h \
93 dtrace.h \
94 dumphdr.h \
95 exacct_impl.h \
96 fasttrap.h \
97 hook_event.h \
98 iscsi_authclient.h \
99 kiconv_ja.h \
100 kiconv_ja_jis_to_unicode.h \
101 kiconv_ja_unicode_to_jis.h \
102 kobj.h \
103 kobj_impl.h \
104 ksyms.h \
105 lockstat.h \
106 neti.h \
107 rds.h \
108 ser_sync.h \
109 smbios_impl.h \
110 smedia.h \
111 sockfilter.h \
112 stat.h \
113 u8_textprep_data.h \
114 utsname.h \
115 vnic.h"
117 for inc in $files; do
118 file=`basename $inc`
119 for bad in $badfiles; do
120 if [ "$file" = "$bad" ]; then
121 continue 2
123 done
125 ofile=${TMPDIR:-/tmp}/inc.$file.$$.out
126 errfile=${TMPDIR:-/tmp}/inc.$file.$$.err
127 doit $file $ofile $errfile &
128 let i=i+1
130 if [ $i -eq $concurrency ]; then
132 # This isn't optimal -- it creates a highly fluctuating load
133 # as we wait for all work to complete -- but it's an easy
134 # way of parallelizing work.
136 wait
137 let i=0
139 done
141 wait
143 bigofile=${TMPDIR:-/tmp}/inc.$$.out
145 for inc in $files; do
146 file=`basename $inc`
147 ofile=${TMPDIR:-/tmp}/inc.$file.$$.out
149 if [ -f $ofile ]; then
150 cat $ofile >> $bigofile
151 rm $ofile
153 done
155 status=$(grep "failed:" $bigofile | wc -l)
156 cat $bigofile
157 rm -f $bigofile
158 exit $status