Debian Codegraph @

tools/cgreen_runner_output_diff

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/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=`unamescip-shell system . . uname. -o 1>/dev/nullscip-shell filesystem . . `/dev/null`. 2>/dev/nullscip-shell filesystem . . `/dev/null`.; echoscip-shell system . . echo. $?`
16 if [scip-shell system . . `[`. $unameo -eq 0 ]; then
17 OS=`unamescip-shell system . . uname. -o`
18 else
19 OS=`unamescip-shell system . . 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 echoscip-shell system . . echo. "ERROR: $0 can't handle OS=$OS"
42 exit 2
43 ;;
44 esac
45
46 # Handle arguments
47 if [scip-shell system . . `[`. $# -ne 3 ]; then
48 echoscip-shell system . . 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=$(perlscip-shell system . . perl. -e 'use Cwd "abs_path"; print abs_path(@ARGV[0])' -- "$sourcedir")
57 if [scip-shell system . . `[`. $(unamescip-shell system . . 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=`echoscip-shell system . . echo. $sourcedir | sedscip-shell system . . 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 [scip-shell system . . `[`. -z "$CGREEN_PER_TEST_TIMEOUT" ]; then
71 printfscip-shell system . . printf. "Comparing output of ${name} to expected: "
72 else
73 printfscip-shell system . . 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 catscip-shell system . . cat. "${name}.error" >> "${name}.output"
79
80 tempfile=`mktempscip-shell system . . mktemp.`
81
82
83 # sed commands to normalize...
84 # - line numbers in error messages
85 echoscip-shell system . . echo. "s/:[0-9]+:/:000:/g" > $tempfile
86
87 # - timing info
88 echoscip-shell system . . echo. "s/in [0-9]+ms\./in 0ms\./g" >> $tempfile
89
90 # - library prefix
91 echoscip-shell system . . echo. s/\"${prefix}${name}\"/\"${name}\"/g >> $tempfile
92
93 # - source path, ensure parenthesis are not interpreted by sed -E
94 echoscip-shell system . . echo. s%.*${sourcedir//[\(\)]/.}/%%g >> $tempfile
95
96 # Do normalization using the commands in the tempfile and the specified commandfile
97 sedscip-shell system . . sed. -E -f "${tempfile}" -f "${commandfile}" "${name}.output" > "${name}.output.normalized"
98
99 # Check for color capability
100 if testscip-shell system . . test. -t 1; then
101 ncolors=$(tputscip-shell system . . tput. colors)
102
103 if testscip-shell system . . test. -n "$ncolors" && testscip-shell system . . test. $ncolors -ge 8; then
104 green="$(tputscip-shell system . . tput. setaf 2)"
105 normal="$(tputscip-shell system . . tput. sgr0)"
106 fi
107 fi
108
109 # Compare normalized output to expected
110 cmpscip-shell system . . cmp. -s "${name}.output.normalized" "${sourcedir}/${expected}"
111
112 # If not the same, show diff
113 rc=$?
114 if [scip-shell system . . `[`. $rc -ne 0 ]
115 then
116 echoscip-shell system . . echo.
117 diffscip-shell system . . diff. -c "${name}.output.normalized" "${sourcedir}/${expected}"
118 else
119 echoscip-shell system . . echo. ${green}Ok${normal}
120 fi
121 exit $rc