]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/misc/tst.include.ksh
Upgrade to version 3.1.4
[FreeBSD/FreeBSD.git] / cddl / contrib / opensolaris / cmd / dtrace / test / tst / common / misc / tst.include.ksh
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 2007 Sun Microsystems, Inc.  All rights reserved.
24 # Use is subject to license terms.
25 #
26 # ident "%Z%%M% %I%     %E% SMI"
27
28 if [ $# != 1 ]; then
29         echo expected one argument: '<'dtrace-path'>'
30         exit 2
31 fi
32
33 dtrace=$1
34 CFLAGS=
35
36 doit()
37 {
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()
47 {}
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
54 {
55         exit(0);
56 }
57 EOF
58                 if [ $? -ne 0 ]; then
59                         echo $inc failed: `cat $errfile | head -1` > $ofile
60                 else
61                         echo $inc succeeded > $ofile
62                 fi
63                 rm -f $errfile
64         fi
65
66         rm -f $cofile $cfile 2>/dev/null
67 }
68
69 concurrency=`psrinfo | wc -l`
70 let concurrency=concurrency*4
71 let i=0
72
73 files=/usr/include/sys/*.h
74
75 #
76 # There are a few files in /usr/include/sys that are known to be bad -- usually
77 # because they include static globals (!) or function bodies (!!) in the header
78 # file.  Hopefully these remain sufficiently few that the O(#files * #badfiles)
79 # algorithm, below, doesn't become a problem.  (And yes, writing scripts in
80 # something other than ksh1888 would probably be a good idea.)  If this script
81 # becomes a problem, kindly fix it by reducing the number of bad files!  (That
82 # is, fix it by fixing the broken file, not the broken script.)
83 #
84 badfiles="ctype.h eri_msg.h ser_sync.h sbpro.h neti.h hook_event.h \
85     bootconf.h bootstat.h dtrace.h dumphdr.h exacct_impl.h fasttrap.h \
86     kobj.h kobj_impl.h ksyms.h lockstat.h smedia.h stat.h utsname.h"
87
88 for inc in $files; do
89         file=`basename $inc`
90         for bad in $badfiles; do
91                 if [ "$file" = "$bad" ]; then
92                         continue 2 
93                 fi
94         done
95
96         ofile=${TMPDIR:-/tmp}/inc.$file.$$.out
97         errfile=${TMPDIR:-/tmp}/inc.$file.$$.err
98         doit $file $ofile $errfile &
99         let i=i+1
100
101         if [ $i -eq $concurrency ]; then
102                 #
103                 # This isn't optimal -- it creates a highly fluctuating load
104                 # as we wait for all work to complete -- but it's an easy
105                 # way of parallelizing work.
106                 #
107                 wait
108                 let i=0
109         fi
110 done
111
112 wait
113
114 bigofile=${TMPDIR:-/tmp}/inc.$$.out
115
116 for inc in $files; do
117         file=`basename $inc`
118         ofile=${TMPDIR:-/tmp}/inc.$file.$$.out
119
120         if [ -f $ofile ]; then
121                 cat $ofile >> $bigofile
122                 rm $ofile
123         fi
124 done
125
126 status=$(grep "failed:" $bigofile | wc -l)
127 cat $bigofile
128 rm -f $bigofile
129 exit $status