1#!/bin/sh
2#
3#   /**-------------------------------------------------------------------**
4#    **                              CLooG                                **
5#    **-------------------------------------------------------------------**
6#    **                           checker.sh                              **
7#    **-------------------------------------------------------------------**
8#    **                 First version: November 16th 2011                 **
9#    **-------------------------------------------------------------------**/
10#
11
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# *****************************************************************************/
37
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.
46
47TEST_NAME="$1"             ## Name of the group of files to test
48
49TEST_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".
53
54TEST_GLOBAL_OPTIONS="$3"   ## Options for all the tests in the group
55
56TEST_INPUT_EXTENSION="$4"  ## Extension of the input file
57
58TEST_OUTPUT_EXTENSION="$5" ## Extension of the generated file
59
60TEST_RUN="$6"              ## "1" if the checking policy is to generate,
61                           ## compile and run, generate only otherwise
62
63failedtest=0;
64cloog=$top_builddir/cloog$EXEEXT
65echo "             /*-----------------------------------------------*"
66echo "              *       Testing CLooG: $TEST_NAME test set       "
67echo "              *-----------------------------------------------*/"
68for x in $TEST_FILES; do
69    name=`echo $x | sed 's/%/ /g' | cut -d\  -f1`;
70    individual_options=`echo $x | sed 's/%/ /g' | cut -s -d\  -f2-`;
71    input="$srcdir/$name.$TEST_INPUT_EXTENSION";
72    output="$srcdir/$name.$TEST_OUTPUT_EXTENSION";
73    options="$individual_options $TEST_GLOBAL_OPTIONS";
74
75    echo "Check file $input \c";
76    if [ "$options" = " " ]; then
77        echo "(no option), \c"
78    else
79        echo "(options $options), \c";
80    fi;
81
82    if [ "$TEST_RUN" = "1" ]; then
83	generate_test=$srcdir/generate_test$EXEEXT
84	test_run=$srcdir/test_run$EXEEXT
85	good="$srcdir/$name.good.$TEST_OUTPUT_EXTENSION";
86
87	echo "generating... \c";
88	$cloog $options -q -callable 1 $input > test_test.c;
89	$generate_test < $input > test_main.c;
90
91	echo "compiling... \c";
92# TODO: (nd Cedric) The following line is to deal with the (F*CKING !!!)
93#       space in PACKAGE_STRING, introduced by AC_INIT and which, for
94#       some reason, seems to be the source of a problem with my shell.
95#       Maybe there is a better way to solve the problem...
96	COMPILE=`echo $COMPILE | sed 's/\\\ /_SPACE_/g'`;
97	$COMPILE -c test_test.c;
98	$COMPILE -Dtest=good -c $good -o test_good.o;
99	$LINK test_main.c test_test.o test_good.o > /dev/null;
100
101	echo "comparing... \c";
102	$test_run;
103	result=$?;
104	rm -f $test_run;
105    else
106	echo "generating... \c";
107	$cloog $options -q $input > cloog_temp;
108	diff -u -w --ignore-matching-lines='CLooG' cloog_temp $output;
109	result=$?;
110	rm -f cloog_temp;
111    fi;
112
113    if [ "$result" -ne "0" ]; then
114        echo -e "\033[31mFAIL: $output is not the same\033[0m";
115        failedtest=`expr $failedtest + 1`;
116    else
117        echo "PASS";
118    fi;
119done;
120
121if [ $failedtest != 0 ]; then
122    echo "\033[31m[CLooG] FAIL: $failedtest tests failed in $TEST_NAME\033[0m";
123else
124    echo "[CLooG] PASS: $TEST_NAME passed :-) !";
125fi
126exit $failedtest
127