Add a test_regenerate target for regenerating failing tests
[cloog.git] / test / checker.sh
blob3fde644f1bc0cb9c06a77b2d2d036c90d81bb162
1 #!/bin/sh
3 # /**-------------------------------------------------------------------**
4 # ** CLooG **
5 # **-------------------------------------------------------------------**
6 # ** checker.sh **
7 # **-------------------------------------------------------------------**
8 # ** First version: November 16th 2011 **
9 # **-------------------------------------------------------------------**/
12 #/*****************************************************************************
13 # * CLooG : the Chunky Loop Generator (experimental) *
14 # *****************************************************************************
15 # * *
16 # * Copyright (C) 2003 Cedric Bastoul *
17 # * *
18 # * This library is free software; you can redistribute it and/or *
19 # * modify it under the terms of the GNU Lesser General Public *
20 # * License as published by the Free Software Foundation; either *
21 # * version 2.1 of the License, or (at your option) any later version. *
22 # * *
23 # * This library is distributed in the hope that it will be useful, *
24 # * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
26 # * Lesser General Public License for more details. *
27 # * *
28 # * You should have received a copy of the GNU Lesser General Public *
29 # * License along with this library; if not, write to the Free Software *
30 # * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
31 # * Boston, MA 02110-1301 USA *
32 # * *
33 # * CLooG, the Chunky Loop Generator *
34 # * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr *
35 # * *
36 # *****************************************************************************/
38 # This is the main test script of CLooG. It checks that CLooG generates
39 # a convenient output for an input set of tests, according to some
40 # parameters (see below). Two checking policies are possible: simply
41 # compare the generated codes or compare the executions of the generated
42 # codes. The reference output files must be present: if we are checking a
43 # file foo.cloog, either foo.c or foo.f must exist in the case of a simple
44 # code generation checking, and either foo.good.c or foo.good.f must exist
45 # in the case of a run check.
47 TEST_NAME="$1" ## Name of the group of files to test
49 TEST_FILES="$2" ## List of test file prefixes and individual options
50 ## spaces between the elements of one test are
51 ## represented with '%', e.g., "file -f -1" is
52 ## "file%-f%-1".
54 TEST_GLOBAL_OPTIONS="$3" ## Options for all the tests in the group
56 TEST_INPUT_EXTENSION="$4" ## Extension of the input file
58 TEST_OUTPUT_EXTENSION="$5" ## Extension of the generated file
60 TEST_RUN="$6" ## "1" if the checking policy is to generate,
61 ## compile and run, generate only otherwise
63 TEST_REGENERATE="$7" ## "regenerate" to replace the original file with
64 ## the generated one in the case of a check fail
65 ## !!! USE WITH CARE !!!
67 failedtest=0;
68 cloog=$top_builddir/cloog$EXEEXT
69 echo " /*-----------------------------------------------*"
70 echo " * Testing CLooG: $TEST_NAME test set "
71 echo " *-----------------------------------------------*/"
72 for x in $TEST_FILES; do
73 name=`echo $x | sed 's/%/ /g' | cut -d\ -f1`;
74 individual_options=`echo $x | sed 's/%/ /g' | cut -s -d\ -f2-`;
75 input="$srcdir/$name.$TEST_INPUT_EXTENSION";
76 output="$srcdir/$name.$TEST_OUTPUT_EXTENSION";
77 options="$individual_options $TEST_GLOBAL_OPTIONS";
79 echo "Check file $input \c";
80 if [ "$options" = " " ]; then
81 echo "(no option), \c"
82 else
83 echo "(options $options), \c";
84 fi;
86 if [ "$TEST_RUN" = "1" ]; then
87 generate_test=$srcdir/generate_test$EXEEXT
88 test_run=$srcdir/test_run$EXEEXT
89 good="$srcdir/$name.good.$TEST_OUTPUT_EXTENSION";
91 echo "generating... \c";
92 $cloog $options -q -callable 1 $input > test_test.c;
93 $generate_test < $input > test_main.c;
95 echo "compiling... \c";
96 # TODO: (nd Cedric) The following line is to deal with the (F*CKING !!!)
97 # space in PACKAGE_STRING, introduced by AC_INIT and which, for
98 # some reason, seems to be the source of a problem with my shell.
99 # Maybe there is a better way to solve the problem...
100 COMPILE=`echo $COMPILE | sed 's/\\\ /_SPACE_/g'`;
101 $COMPILE -c test_test.c;
102 $COMPILE -Dtest=good -c $good -o test_good.o;
103 $LINK test_main.c test_test.o test_good.o > /dev/null;
105 echo "comparing... \c";
106 $test_run;
107 result=$?;
108 rm -f $test_run;
109 else
110 echo "generating... \c";
111 $cloog $options -q $input > cloog_temp;
112 diff -u -w --ignore-matching-lines='CLooG' $output cloog_temp;
113 result=$?;
114 if [ "$result" -ne "0" ] && [ "$TEST_REGENERATE" = "regenerate" ]; then
115 echo -e "\033[31mREGENERATING... \033[0m";
116 cp cloog_temp $output;
118 rm -f cloog_temp;
121 if [ "$result" -ne "0" ]; then
122 echo -e "\033[31mFAIL: $output is not the same\033[0m";
123 failedtest=`expr $failedtest + 1`;
124 else
125 echo "PASS";
127 done;
129 if [ $failedtest != 0 ]; then
130 echo "\033[31m[CLooG] FAIL: $failedtest tests failed in $TEST_NAME\033[0m";
131 else
132 echo "[CLooG] PASS: $TEST_NAME passed :-) !";
134 exit $failedtest