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