Debian Codegraph @

tools/cgreen_xml_output_diff

raw symbols SCIP
1 #!/bin/bash
2 #
3 # Will run the cgreen-runner in directory ../tools
4 # on library with name $1 (e.g. 'lib${name}.so')
5 # generating XML output that will be compared to
6 # sources are in $2 for...
7 # ...expected output file name in $3
8 # ...and commands to normalize output (in the file normalize_{name}.sed)
9 #
10 # TODO: refactor the duplication in this and cgreen_xml_output_diff to something
11 # not having the duplication, common sub-script, maybe?
12 #
13 # TODO: make 'prefix' and 'extension' into arguments instead of evaluating them here
14
15 # Determine OS
16 unameo=`uname -o 1>/dev/null 2>/dev/null; echo $?`
17 if [ $unameo -eq 0 ]; then
18 OS=`uname -o`
19 else
20 OS=`uname -s`
21 fi
22
23 # Set up library prefix and extension
24 case "$OS" in
25 Darwin)
26 prefix=lib
27 extension=dylib
28 ;;
29 GNU/Linux|FreeBSD)
30 prefix=lib
31 extension=so
32 ;;
33 Cygwin)
34 prefix=cyg
35 extension=dll
36 ;;
37 Msys)
38 prefix=msys-
39 extension=dll
40 ;;
41 *)
42 echo "ERROR: $0 can't handle OS=$OS"
43 exit 2
44 ;;
45 esac
46
47 # Handle arguments
48 if [ $# -ne 3 ]; then
49 echo "ERROR: $0 requires exactly 3 arguments"
50 exit 2
51 fi
52
53 # TODO: don't shift
54 name=$1; shift 1
55
56 sourcedir=$1 ; shift 1
57 sourcedir=$(perl -e 'use Cwd "abs_path"; print abs_path(@ARGV[0])' -- "$sourcedir")
58 if [ $(uname -n) = thoni64 ]; then
59 # On my Cygwin machine I have linked /home to c:/Users so absolute paths don't match
60 # what runner prints, so try to replace that
61 # TODO: generalize this...
62 sourcedir=`echo $sourcedir | sed -e s#/cygdrive/c/Users#/home#`
63 fi
64
65 # TODO: don't shift
66 expected=$1 ; shift 1
67
68 commandfile="${sourcedir}/normalize_${name}.sed"
69
70 # Do it!
71 if [ -z "$CGREEN_PER_TEST_TIMEOUT" ]; then
72 printf "Comparing output of ${name} to expected: "
73 else
74 printf "Comparing output of ${name} to expected with CGREEN_PER_TEST_TIMEOUT=$CGREEN_PER_TEST_TIMEOUT: "
75 fi
76
77 # Run runner on library store output and error
78 ../tools/cgreen-runner -x X "${prefix}${name}.${extension}" > "${name}.output" 2> "${name}.error"
79 cat "${name}.error" >> "${name}.output"
80 cat X-*${name}.xml X-*${name}-default.xml >> "${name}.output"
81
82 tempfile=`mktemp`
83
84 # sed commands to normalize...
85 # - line numbers in error messages
86 echo "s/:[0-9]+:/:/g" > $tempfile
87
88 # - timing info
89 echo "s/in [0-9]+ms\./in 0ms\./g" >> $tempfile
90
91 # - library prefix
92 echo s/\"${prefix}${name}\"/\"${name}\"/g >> $tempfile
93
94 # - source path, ensure parenthesis are not interpreted by sed -E
95 # but allow any characters before sourcedir in the string
96 echo s%\".*${sourcedir//[\(\)]/.}/%\"%g >> $tempfile
97
98 # Do normalization using the commands in the tempfile and the specified commandfile
99 sed -E -f "${tempfile}" -f "${commandfile}" "${name}.output" > "${name}.output.normalized"
100
101 # Check for color capability
102 if test -t 1; then
103 ncolors=$(tput colors)
104
105 if test -n "$ncolors" && test $ncolors -ge 8; then
106 green="$(tput setaf 2)"
107 normal="$(tput sgr0)"
108 fi
109 fi
110
111 # Compare normalized output to expected
112 cmp -s "${name}.output.normalized" "${sourcedir}/${expected}"
113
114 # If not the same, show diff
115 rc=$?
116 if [ $rc -ne 0 ]
117 then
118 echo
119 diff -c "${name}.output.normalized" "${sourcedir}/${expected}"
120 else
121 echo ${green}Ok${normal}
122 fi
123 exit $rc