]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/cvs/contrib/debug_check_log.sh
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / cvs / contrib / debug_check_log.sh
1 #!/bin/sh
2
3 # Copyright (C) 2000-2005 The Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 #
16 # This program is intended to take a check.log file generated by a failed run of
17 # sanity.sh as input and run expr line by line on it.  It seems a much easier
18 # way of spotting a single failed line in a 100 line test result.
19 #
20
21 #
22 # Contributed by Derek R. Price <derek.price@openavenue.com>
23 #
24
25
26
27 usage ()
28 {
29         echo "\
30 usage: $0 [-afh] [file...]
31
32        -a          process alternate pattern
33        -f          process first pattern (default)
34        -h          print this text
35
36      file          files to process (default = check.log)"
37 }
38
39 # Do a line by line match with expr
40 #
41 # INPUTS
42 #    $1 = text file name
43 #    $2 = pattern file name
44 expr_line_by_line ()
45 {
46         dcl_line=0
47         dcl_wrong=
48         # We are assuming a newline at the end of the file.  The way sanity.sh
49         # uses echo to create the log message guarantees this newline and since
50         # expr ignores the last newline when the anchor is present anyhow, no
51         # information is being lost in the transition
52         while test $dcl_line -lt `wc -l <$1` -a $dcl_line -lt `wc -l <$2`; do
53                 dcl_line=`expr $dcl_line + 1`
54                 if test `sed -ne${dcl_line}p <$1 |wc -c` -eq 1 \
55                                 -a `sed -ne${dcl_line}p <$2 |wc -c` -eq 1; then
56                         # This is a workaround for what I am calling a bug in GNU
57                         # expr - it won't match the empty string to the empty
58                         # string.  In this case the assumption is that a single
59                         # character is always a newline.  Since we already checked
60                         # for the end of the file, we know sed will echo the
61                         # newline.
62                         : 
63                 elif expr "`sed -ne${dcl_line}p <$1`" : \
64                                 "`sed -ne${dcl_line}p <$2`\$" >/dev/null; then
65                         :
66                 else
67                         echo "$dcl_line: `sed -ne${dcl_line}p <$1`"
68                         echo "$dcl_line: `sed -ne${dcl_line}p <$2`\$"
69                         dcl_wrong="$dcl_wrong $dcl_line"
70                 fi
71         done
72         if test `wc -l <$1` -ne `wc -l <$2`; then
73                 echo "output & pattern contain differing number of lines"
74         elif test -z "$dcl_wrong"; then
75                 echo "no mismatched lines"
76         else
77                 echo "mismatched lines: $dcl_wrong"
78         fi
79 }
80
81 # Process a single check.log file
82 #
83 # INPUTS
84 #    $1 = filename
85 process_check_log ()
86 {
87         # abort if we can't find any expressions
88         if grep '^\*\* got: $' <$1 >/dev/null; then
89                 :
90         else
91                 echo "WARNING:  No expressions in file: $1" >&2
92                 echo "          Either not a check.log or sanity.sh exited for some other reason," >&2
93                 echo "          like bad exit status.  Try tail." >&2
94                 return
95         fi
96
97         dcl_exprfiles=""
98         if grep '^\*\* or: $' <$1 >/dev/null; then
99                 # file contains a second regex
100                 if test $dcl_dofirst -eq 1; then
101                         # get the first pattern
102                         sed -ne '/^\*\* expected: $/,/^\*\* or: $/p' <$1 >/tmp/dcle$$
103                         dcl_exprfiles="$dcl_exprfiles /tmp/dcle$$"
104                 fi
105                 if test $dcl_doalternate -eq 1; then
106                         # get the alternate pattern
107                         sed -ne '/^\*\* or: $/,/^\*\* got: $/p' <$1 >/tmp/dclo$$
108                         dcl_exprfiles="$dcl_exprfiles /tmp/dclo$$"
109                 else
110                         echo "WARNING:  Ignoring alternate pattern in file: $1" >&2
111                 fi
112         else
113                 # file doesn't contain a second regex
114                 if test $dcl_dofirst = 1; then
115                         # get the only pattern
116                         sed -ne '/^\*\* expected: $/,/^\*\* got: $/p' <$1 >/tmp/dcle$$
117                         dcl_exprfiles="$dcl_exprfiles /tmp/dcle$$"
118                 fi
119                 if test $dcl_doalternate -eq 1; then
120                         echo "WARNING:  No alternate pattern in file:  $1" >&2
121                 fi
122         fi
123
124         # and get the actual output
125         sed -ne '/^\*\* got: $/,$p' <$1 >/tmp/dclg$$
126         sed -ne '1D
127 $D
128 p' </tmp/dclg$$ >/tmp/dclh$$
129         mv /tmp/dclh$$ /tmp/dclg$$
130
131         # compare the output against each pattern requested
132         for dcl_f in $dcl_exprfiles; do
133                 sed -ne '1D
134 $D
135 p' <$dcl_f >/tmp/dclp$$
136                 mv /tmp/dclp$$ $dcl_f
137
138                 case $dcl_f in
139                         /tmp/dcle*)
140                                 echo "********** $1 : Primary **********"
141                                 ;;
142                         /tmp/dclo*)
143                                 echo "********** $1 : Alternate **********"
144                                 ;;
145                 esac
146
147                 expr_line_by_line /tmp/dclg$$ $dcl_f
148
149                 rm $dcl_f
150         done
151
152         rm /tmp/dclg$$
153 }
154
155 ###
156 ### MAIN
157 ###
158
159 # set up defaults
160 dcl_doalternate=0
161 dcl_dofirst=0
162
163 # process options
164 while getopts afh arg; do
165         case $arg in
166                 a)
167                         dcl_doalternate=1
168                         ;;
169                 f)
170                         dcl_dofirst=1
171                         ;;
172                 \?|h)
173                         usage
174                         exit 1
175                         ;;
176         esac
177 done
178
179 # dispose of processed args
180 shift `expr $OPTIND - 1`
181 OPTIND=1
182
183 # set the default mode
184 if test $dcl_doalternate -eq 0; then
185         dcl_dofirst=1
186 fi
187
188 # set default arg
189 if test $# -eq 0; then
190         if test -f src/check.log && test -r src/check.log; then
191                 set src/check.log
192         else
193                 set check.log
194         fi
195 fi
196
197 for file in "$@"; do
198         process_check_log $file;
199 done
200
201 exit 0