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