3 # /**-------------------------------------------------------------------**
5 # **-------------------------------------------------------------------**
7 # **-------------------------------------------------------------------**
8 # ** First version: November 16th 2011 **
9 # **-------------------------------------------------------------------**/
12 #/*****************************************************************************
13 # * CLooG : the Chunky Loop Generator (experimental) *
14 # *****************************************************************************
16 # * Copyright (C) 2003 Cedric Bastoul *
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. *
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. *
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 *
33 # * CLooG, the Chunky Loop Generator *
34 # * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr *
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
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_TYPE
="$6" ## - "generate" to simply test code generation
62 ## - "regenerate" to replace the original file with
63 ## the generated one in the case of a check fail
64 ## !!! USE WITH CARE !!!
65 ## - "valgrind" to test the valgrind output on
67 ## - "run" if the checking policy is to generate,
68 ## compile and run, generate only otherwise
71 cloog
=$top_builddir/cloog
$EXEEXT
72 echo " /*-----------------------------------------------*"
73 echo " * Testing CLooG: $TEST_NAME test set "
74 echo " *-----------------------------------------------*/"
75 for x
in $TEST_FILES; do
76 name
=`echo $x | sed 's/%/ /g' | cut -d\ -f1`;
77 individual_options
=`echo $x | sed 's/%/ /g' | cut -s -d\ -f2-`;
78 input
="$srcdir/$name.$TEST_INPUT_EXTENSION";
79 output
="$srcdir/$name.$TEST_OUTPUT_EXTENSION";
80 options
="$individual_options $TEST_GLOBAL_OPTIONS";
82 echo "Check file $input \c";
83 if [ "$options" = " " ]; then
84 echo "(no option), \c"
86 echo "(options $options), \c";
89 if [ "$TEST_TYPE" = "run" ]; then
90 generate_test
=$srcdir/generate_test
$EXEEXT
91 test_run
=$srcdir/test_run
$EXEEXT
92 good
="$srcdir/$name.good.$TEST_OUTPUT_EXTENSION";
94 echo "generating... \c";
95 $cloog $options -q -callable 1 $input > test_test.c
;
96 $generate_test < $input > test_main.c
;
98 echo "compiling... \c";
99 # TODO: (nd Cedric) The following line is to deal with the (F*CKING !!!)
100 # space in PACKAGE_STRING, introduced by AC_INIT and which, for
101 # some reason, seems to be the source of a problem with my shell.
102 # Maybe there is a better way to solve the problem...
103 COMPILE
=`echo $COMPILE | sed 's/\\\ /_SPACE_/g'`;
104 $COMPILE -c test_test.c
;
105 $COMPILE -Dtest=good
-c $good -o test_good.o
;
106 $LINK test_main.c test_test.o test_good.o
> /dev
/null
;
108 echo "comparing... \c";
112 elif [ "$TEST_TYPE" = "valgrind" ]; then
113 echo "generating... \c";
114 # valgrind --leak-check=full --error-exitcode=1 \
115 libtool
--mode=execute valgrind
--error-exitcode=1 \
116 $cloog $options -q $input > /dev
/null
2> cloog_temp
;
118 leaks
=`grep "in use at exit" cloog_temp | cut -f 2 -d ':'`
119 if [ "$errors" = "1" ]; then
120 echo -e "\033[31mMemory error detected... \033[0m";
123 elif [ "$leaks" != " 0 bytes in 0 blocks" ]; then
124 echo -e "\033[31mMemory leak detected... \033[0m";
132 echo "generating... \c";
133 $cloog $options -q $input > cloog_temp
;
134 diff -u -w --ignore-matching-lines='CLooG' $output cloog_temp
;
136 if [ "$result" -ne "0" ] && [ "$TEST_TYPE" = "regenerate" ]; then
137 echo -e "\033[31mREGENERATING... \033[0m";
138 cp cloog_temp
$output;
143 if [ "$result" -ne "0" ]; then
144 echo -e "\033[31mFAIL: $output has a problem\033[0m";
145 failedtest
=`expr $failedtest + 1`;
151 if [ $failedtest != 0 ]; then
152 echo "\033[31m[CLooG] FAIL: $failedtest tests failed in $TEST_NAME\033[0m";
154 echo "[CLooG] PASS: $TEST_NAME passed :-) !";