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