Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. #!/bin/sh
  2.  
  3. if [ ! -z "$srcdir" ]; then
  4.    testdir=$srcdir/glcpp/tests
  5.    glcpp=`pwd`/glcpp/glcpp
  6. else
  7.    testdir=.
  8.    glcpp=../glcpp
  9. fi
  10.  
  11. trap 'rm $test.valgrind-errors; exit 1' INT QUIT
  12.  
  13. usage ()
  14. {
  15.     cat <<EOF
  16. Usage: glcpp [options...]
  17.  
  18. Run the test suite for mesa's GLSL pre-processor.
  19.  
  20. Valid options include:
  21.  
  22.         --valgrind      Run the test suite a second time under valgrind
  23. EOF
  24. }
  25.  
  26. test_specific_args ()
  27. {
  28.     test="$1"
  29.  
  30.     grep 'glcpp-args:' "$test" | sed -e 's,^.*glcpp-args: *,,'
  31. }
  32.  
  33. # Parse command-line options
  34. for option; do
  35.     if [ "${option}" = '--help' ] ; then
  36.         usage
  37.         exit 0
  38.     elif [ "${option}" = '--valgrind' ] ; then
  39.         do_valgrind=yes
  40.     else
  41.         echo "Unrecognized option: $option" >&2
  42.         echo >&2
  43.         usage
  44.         exit 1
  45.     fi
  46. done
  47.  
  48. total=0
  49. pass=0
  50. clean=0
  51.  
  52. echo "====== Testing for correctness ======"
  53. for test in $testdir/*.c; do
  54.     echo -n "Testing $test..."
  55.     $glcpp $(test_specific_args $test) < $test > $test.out 2>&1
  56.     total=$((total+1))
  57.     if cmp $test.expected $test.out >/dev/null 2>&1; then
  58.         echo "PASS"
  59.         pass=$((pass+1))
  60.     else
  61.         echo "FAIL"
  62.         diff -u $test.expected $test.out
  63.     fi
  64. done
  65.  
  66. echo ""
  67. echo "$pass/$total tests returned correct results"
  68. echo ""
  69.  
  70. if [ "$do_valgrind" = "yes" ]; then
  71.     echo "====== Testing for valgrind cleanliness ======"
  72.     for test in $testdir/*.c; do
  73.         echo -n "Testing $test with valgrind..."
  74.         valgrind --error-exitcode=31 --log-file=$test.valgrind-errors $glcpp $(test_specific_args $test) < $test >/dev/null 2>&1
  75.         if [ "$?" = "31" ]; then
  76.             echo "ERRORS"
  77.             cat $test.valgrind-errors
  78.         else
  79.             echo "CLEAN"
  80.             clean=$((clean+1))
  81.             rm $test.valgrind-errors
  82.         fi
  83.     done
  84.  
  85.     echo ""
  86.     echo "$pass/$total tests returned correct results"
  87.     echo "$clean/$total tests are valgrind-clean"
  88. fi
  89.  
  90. if [ "$pass" = "$total" ] && [ "$do_valgrind" != "yes" ] || [ "$pass" = "$total" ]; then
  91.     exit 0
  92. else
  93.     exit 1
  94. fi
  95.  
  96.