Subversion Repositories Kolibri OS

Rev

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

  1. #!/bin/bash
  2. #
  3. # This is a simple script to convert the XML testcaes to C source file, compile it, run it, and report the result.
  4. # Usage:
  5. # This script is designed to run under the libdom/test directory.
  6. #
  7. # domts="testcases" dtd="dom1-interfaces.xml" level="level1" ./run-test.sh
  8. #
  9. # The above command will convert the XML testcase in directory testcases/tests/level/core and
  10. # use dom1-interfaces.xml to convert it.
  11. # This script will generate a output/ directory in libdom/test, and in that directory, there is a same structure
  12. # as in DOMTS XML testcases files.
  13. #
  14. #  This file is part of libdom test suite.
  15. #  Licensed under the MIT License,
  16. #                                http://www.opensource.org/licenses/mit-license.php
  17. #  Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
  18.  
  19. level=${level:-"level1"};
  20. module=${module:-"core"};
  21. domts=${domts:?"The \$domts must be assigned some value"};
  22. output=${output:-"output"};
  23. dtd=${dtd:?"The DTD file must be given"};
  24.  
  25. testdir="$domts"/tests/"$level"/"$module"
  26. log="$output"/"$level"/"$module"/test.log;
  27.  
  28. src="testutils/comparators.c testutils/domtsasserts.c testutils/foreach.c testutils/list.c testutils/load.c testutils/utils.c testutils/domtscondition.c"
  29. domdir="../build-Linux-Linux-debug-lib-static"
  30. ldflags="-L$libdir  -L$libdir -lxml2 $(pkg-config --libs libdom libwapcaplet libparserutils libhubbub)"
  31. cflags="-Itestutils/ -I../bindings/xml  -I../include -I../bindings/hubbub $(pkg-config --cflags libwapcaplet libparserutils libhubbub)"
  32.  
  33. total=0;
  34. fail=0;
  35. pass=0;
  36. conversion=0;
  37. compile=0;
  38. run=0;
  39. nsupport=0;
  40.  
  41. # Create the directories if necessary
  42. if [ ! -e "$ouput" ]; then
  43.         mkdir -p "$output";
  44. fi
  45. if [ ! -e "$level" ]; then
  46.         mkdir -p "$output"/"$level";
  47. fi
  48. if [ ! -e "$module" ]; then
  49.         mkdir -p "$output"/"$level"/"$module";
  50. fi
  51.  
  52. # Prepare the test files
  53. if [ -e "files" ]; then
  54.         rm -fr files;
  55. fi
  56. cp -fr "$testdir/files" ./;
  57.  
  58. while read test; do
  59.         total=$(($total+1));
  60.  
  61.         file=`basename "$test"`;
  62.         name=${file%%.xml};
  63.        
  64.         cfile="$output"/"$level"/"$module"/"$name".c;
  65.         ofile="$output"/"$level"/"$module"/"$name";
  66.         tfile="$testdir"/"$file";
  67.  
  68.         echo -n "$file:";
  69.  
  70.         # Generate the test C program
  71.         out=`perl transform.pl "$dtd" "$tfile" 2>&1  >"${cfile}.unindent"`;
  72.         if [ "$?" != "0" ]; then
  73.                 fail=$((fail+1));
  74.                 conversion=$((conversion+1));
  75.                 echo "$tfile Conversion Error:" >& 3;
  76.                 echo "Please make sure you have XML::XPath perl module installed!" >& 3;
  77.                 echo "$out" >&3;
  78.                 echo -e "----------------------------------------\n\n" >& 3;
  79.                 echo "failed!";
  80.                 rm -fr "${cfile}.unindent";
  81.                 continue;
  82.         fi
  83.         out=`indent "${cfile}.unindent" -o "$cfile" 2>&1`;
  84.         if [ "$?" != "0" ]; then
  85.                 rm -fr "${cfile}.unindent";
  86.                 fail=$((fail+1));
  87.                 conversion=$((conversion+1));
  88.                 echo "$tfile Conversion Error:" >& 3;
  89.                 echo "$out" >& 3;
  90.                 echo -e "----------------------------------------\n\n" >& 3;
  91.                 echo "failed!";
  92.                 continue;
  93.         fi
  94.         rm -fr "${cfile}.unindent";
  95.  
  96.         # Compile it now
  97.         out=` ( gcc -g $cflags $src $cfile $ldflags -o "$ofile" ) 2>&1`;
  98.         if [ "$?" != "0" ]; then
  99.                 fail=$((fail+1));
  100.                 compile=$((compile+1));
  101.                 echo "$tfile Compile Error:" >& 3;
  102.                 echo "$out" >& 3;
  103.                 echo -e "----------------------------------------\n\n" >& 3;
  104.                 echo "failed!";
  105.                 continue;
  106.         fi
  107.        
  108.         # Run the test and test the result
  109.         cd files;
  110.         out=$(../$ofile 2>&1);
  111.         ret="$?";
  112.         if [ "$ret" != "0" ]; then
  113.                 cd ..;
  114.                 fail=$((fail+1));
  115.                 if [ "$ret" == "9" ]; then
  116.                         nsupport=$((nsupport+1))
  117.                         echo "$tfile Not Support:" >& 3;
  118.                         echo "$out" >& 3;
  119.                         echo -e "----------------------------------------\n\n" >& 3;
  120.                         echo "not supported!";
  121.                 else
  122.                         run=$((run+1));
  123.                         echo "$tfile Run Error:" >& 3;
  124.                         echo "$out" >& 3;
  125.                         echo -e "----------------------------------------\n\n" >& 3;
  126.                         echo "failed!";
  127.                 fi
  128.                 continue;
  129.         fi
  130.         cd ..;
  131.  
  132.         pass=$((pass+1));
  133.         echo "passed.";
  134.  
  135. done 3>"$log" < <(perl -ne 'if ($_ =~ /href=\"(.*\.xml)\"/) { print "$1\n"; }' -- "$testdir"/alltests.xml);
  136.  
  137. echo "Total:  $total" | tee >>"$log";
  138. echo "Passed: $pass" | tee >>"$log";
  139. echo "Failed: $fail" | tee >>"$log";
  140. echo "Conversion Error: $conversion" | tee >>"$log";
  141. echo "Compile Error:    $compile" | tee >>"$log";
  142. echo "Run Error:        $run"   | tee >>"$log";
  143. echo "Not Support:      $nsupport" | tee >>"$log";
  144.  
  145. cat "$log";
  146.