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