Debian Codegraph @

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