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 a XML testcae 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-single-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$domdir -ldom -L/usr/local/lib  -lwapcaplet -L/usr/lib -lxml2 -lhubbub -lparserutils"
  31. #ldflags="-L/usr/lib -lm -lz -L$domdir -ldom -L/usr/local/lib  -lwapcaplet -lxml2 -lhubbub -lparserutils"
  32. cflags="-Itestutils/ -I../bindings/xml  -I../include -I../bindings/hubbub -I/usr/local/include"
  33.  
  34. total=0;
  35. fail=0;
  36. pass=0;
  37. conversion=0;
  38. compile=0;
  39. run=0;
  40. nsupport=0;
  41.  
  42. # Create the directories if necessary
  43. if [ ! -e "$ouput" ]; then
  44.         mkdir -p "$output";
  45. fi
  46. if [ ! -e "$level" ]; then
  47.         mkdir -p "$output"/"$level";
  48. fi
  49. if [ ! -e "$module" ]; then
  50.         mkdir -p "$output"/"$level"/"$module";
  51. fi
  52.  
  53. # Prepare the test files
  54. if [ -e "files" ]; then
  55.         rm -fr files;
  56. fi
  57. cp -fr "$testdir/files" ./;
  58.  
  59. while read test; do
  60.         total=$(($total+1));
  61.  
  62.         file=`basename "$test"`;
  63.         name=${file%%.xml};
  64.        
  65.         cfile="$output"/"$level"/"$module"/"$name".c;
  66.         ofile="$output"/"$level"/"$module"/"$name";
  67.         tfile="$testdir"/"$file";
  68.  
  69.         echo -n "$file:";
  70.  
  71.         # Generate the test C program
  72.         out=`perl transform.pl "$dtd" "$tfile" 2>&1  >"${cfile}.unindent"`;
  73.         if [ "$?" != "0" ]; then
  74.                 fail=$((fail+1));
  75.                 conversion=$((conversion+1));
  76.                 echo "$tfile Conversion Error:" >& 3;
  77.                 echo "Please make sure you have XML::XPath perl module installed!" >& 3;
  78.                 echo "$out" >&3;
  79.                 echo -e "----------------------------------------\n\n" >& 3;
  80.                 echo "failed!";
  81.                 rm -fr "${cfile}.unindent";
  82.                 continue;
  83.         fi
  84.         out=`indent "${cfile}.unindent" -o "$cfile" 2>&1`;
  85.         if [ "$?" != "0" ]; then
  86.                 rm -fr "${cfile}.unindent";
  87.                 fail=$((fail+1));
  88.                 conversion=$((conversion+1));
  89.                 echo "$tfile Conversion Error:" >& 3;
  90.                 echo "$out" >& 3;
  91.                 echo -e "----------------------------------------\n\n" >& 3;
  92.                 echo "failed!";
  93.                 continue;
  94.         fi
  95.         rm -fr "${cfile}.unindent";
  96.  
  97.         # Compile it now
  98.         out=` ( gcc -g $cflags $src $cfile $ldflags -o "$ofile" ) 2>&1`;
  99.         if [ "$?" != "0" ]; then
  100.                 fail=$((fail+1));
  101.                 compile=$((compile+1));
  102.                 echo "$tfile Compile Error:" >& 3;
  103.                 echo "$out" >& 3;
  104.                 echo -e "----------------------------------------\n\n" >& 3;
  105.                 echo "failed!";
  106.                 continue;
  107.         fi
  108.        
  109.         # Run the test and test the result
  110.         cd files;
  111.         out=$(../$ofile 2>&1);
  112.         ret="$?";
  113.         if [ "$ret" != "0" ]; then
  114.                 cd ..;
  115.                 fail=$((fail+1));
  116.                 if [ "$ret" == "9" ]; then
  117.                         nsupport=$((nsupport+1))
  118.                         echo "$tfile Not Support:" >& 3;
  119.                         echo "$out" >& 3;
  120.                         echo -e "----------------------------------------\n\n" >& 3;
  121.                         echo "not supported!";
  122.                 else
  123.                         run=$((run+1));
  124.                         echo "$tfile Run Error:" >& 3;
  125.                         echo "$out" >& 3;
  126.                         echo -e "----------------------------------------\n\n" >& 3;
  127.                         echo "failed!";
  128.                 fi
  129.                 continue;
  130.         fi
  131.         cd ..;
  132.  
  133.         pass=$((pass+1));
  134.         echo "passed.";
  135.  
  136. done 3>&1 < <(echo $1);
  137.  
  138. echo "Total:  $total";
  139. echo "Passed: $pass";
  140. echo "Failed: $fail";
  141. echo "Conversion Error: $conversion";
  142. echo "Compile Error:    $compile";
  143. echo "Run Error:        $run";
  144. echo "Not Support:      $nsupport";
  145.