root/trunk/testall.sh

Revision 2099, 2.5 kB (checked in by dsugar, 7 months ago)

Fix up parsing of command line arguments

  • Property svn:executable set to *
Line 
1 #!/bin/bash
2
3 shopt -s extglob
4 STARTDIR=`pwd`
5
6 BUILD=1
7 INFO=0
8 SEMANTIC=0
9 POLHEADERS=0
10
11 ALLTESTS=""
12
13 while [ ! -z $1 ]; do
14         case $1 in
15        
16                 -[iI])
17                         BUILD=0;
18                         INFO=1;
19                         shift;
20                 ;;
21        
22                 -[rR])
23                         BUILD=0;
24                         shift;
25                 ;;
26        
27                 -[sS])
28                         shift;
29                         POLHEADERS=$1;
30                         SEMANTIC=1;
31                         shift;
32                 ;;
33        
34                 +([0-9]))
35                         ALLTESTS=$ALLTESTS" test"$1;
36                         shift;
37                 ;;
38
39                 -[hH])
40                         echo
41                         echo "Usage: $0 [number]+"
42                         echo "-i display info about each test"
43                         echo "-r run only - do not rebuild compiler"
44                         echo "-s <path> also run semantic diff <path - path to reference policy header - with cdsframework support files>"
45                         echo "-h help"
46                         echo "number - one or more test numbers to run only the specified tests"
47                         echo
48                         exit;
49                 ;;
50
51                 *)
52                         echo Unknown option - $1
53                         shift;
54                 ;;
55         esac
56 done;
57
58 # list of all tests
59 if [ -z "$ALLTESTS" ]; then
60         ALLTESTS=`ls test | egrep test[0-9]{4}`
61 fi
62
63 LIBSELINUX_DIR=`pwd`/libselinuxjava-plugin/swig
64 LIBSELINUX=$LIBSELINUX_DIR/libselinuxjava.so
65
66 if [ $BUILD -eq 1 ]; then
67         echo Compiling
68 # build command line test program if it doesn't exist
69 #if [ ! -e build/com/tresys/framework/compiler/Compiler.java ]; then
70         ant -f compilerbuild.xml clean
71         ant -f libselinuxjava-plugin/swig/antbuild.xml -Dtarget_arch=`uname -m` -Djava_target_dir=`pwd`/framework-plugin/src/com/tresys/framework/compiler/linkage/libselinuxjava/ -Dtarget_dir=$LIBSELINUX_DIR
72         ant -f compilerbuild.xml compile
73 #fi;
74 fi;
75
76 #check to make sure that support for semantic diff has been set up
77 if [ $SEMANTIC -eq 1 ]; then
78         if [ $POLHEADERS ]; then
79                 if [ ! -f $POLHEADERS/support/cdsframework.spt ]; then
80                         echo "Missing CDS Framework support file in headers"
81                         SEMANTIC=0
82                 fi
83         else
84                 echo "POLHEADERS environment variable not set, will not perform semantic diff"
85                 SEMANTIC=0
86         fi
87 fi
88
89
90 declare -a ERRORTESTS
91
92 # loop through each test directory
93 for TEST in $ALLTESTS; do
94         DIR=test/$TEST
95         echo -n Test: $TEST " "
96    
97         if [ $INFO -eq 0 ]; then
98                 if [ ! -e $DIR/test.sh ]; then
99                         echo - skipping test
100                         ERRORTESTS[${#ERRORTESTS[*]}]=$TEST
101                         continue
102                 fi;
103        
104                 cd $DIR
105                 source test.sh
106                 cd $STARTDIR
107                 if [ $RESULT -ne 0 ]; then
108                         ERRORTESTS[${#ERRORTESTS[*]}]=$TEST
109                 fi;
110         fi;
111
112         if [ $INFO -eq 1 ]; then
113                 echo -n ",\""
114                 if [ -e $DIR/README ]; then
115                         cat $DIR/README
116                 else
117                         echo -n Missing!
118                 fi;
119                 echo  -n "\""
120                 echo
121         fi;
122 done;
123
124 if [ $INFO -eq 0 ]; then
125         echo
126         echo
127                 # report each test that failed
128         if [ ${#ERRORTESTS} -gt 0 ]; then
129                 echo The following tests have errors
130                 echo ${ERRORTESTS[@]}
131         else
132                 echo All tests ran successfully
133         fi;
134 fi;
Note: See TracBrowser for help on using the browser.