2
/*+-----------------------------------------------------------------**
4
**-----------------------------------------------------------------**
6
**-----------------------------------------------------------------**
7
** First version: 01/10/2010 **
8
**-----------------------------------------------------------------**
11
*****************************************************************************
12
* OpenScop: Structures and formats for polyhedral tools to talk together *
13
*****************************************************************************
14
* ,___,,_,__,,__,,__,,__,,_,__,,_,__,,__,,___,_,__,,_,__, *
15
* / / / // // // // / / / // // / / // / /|,_, *
16
* / / / // // // // / / / // // / / // / / / /\ *
17
* |~~~|~|~~~|~~~|~~~|~~~|~|~~~|~|~~~|~~~|~~~|~|~~~|~|~~~|/_/ \ *
18
* | G |C| P | = | L | P |=| = |C| = | = | = |=| = |=| C |\ \ /\ *
19
* | R |l| o | = | e | l |=| = |a| = | = | = |=| = |=| L | \# \ /\ *
20
* | A |a| l | = | t | u |=| = |n| = | = | = |=| = |=| o | |\# \ \ *
21
* | P |n| l | = | s | t |=| = |d| = | = | = | | |=| o | | \# \ \ *
22
* | H | | y | | e | o | | = |l| | | = | | | | G | | \ \ \ *
23
* | I | | | | e | | | | | | | | | | | | | \ \ \ *
24
* | T | | | | | | | | | | | | | | | | | \ \ \ *
25
* | E | | | | | | | | | | | | | | | | | \ \ \ *
26
* | * |*| * | * | * | * |*| * |*| * | * | * |*| * |*| * | / \* \ \ *
27
* | O |p| e | n | S | c |o| p |-| L | i | b |r| a |r| y |/ \ \ / *
28
* '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---' '--' *
30
* Copyright (C) 2008 University Paris-Sud 11 and INRIA *
32
* (3-clause BSD license) *
33
* Redistribution and use in source and binary forms, with or without *
34
* modification, are permitted provided that the following conditions *
37
* 1. Redistributions of source code must retain the above copyright notice, *
38
* this list of conditions and the following disclaimer. *
39
* 2. Redistributions in binary form must reproduce the above copyright *
40
* notice, this list of conditions and the following disclaimer in the *
41
* documentation and/or other materials provided with the distribution. *
42
* 3. The name of the author may not be used to endorse or promote products *
43
* derived from this software without specific prior written permission. *
45
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR *
46
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES *
47
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. *
48
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, *
49
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT *
50
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
51
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
52
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
53
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF *
54
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
56
* OpenScop Library, a library to manipulate OpenScop formats and data *
57
* structures. Written by: *
58
* Cedric Bastoul <Cedric.Bastoul@u-psud.fr> and *
59
* Louis-Noel Pouchet <Louis-Noel.Pouchet@inria.fr> *
61
*****************************************************************************/
71
//#define FORK // Comment that if you want only one process
72
// (best for debugging with valgrind but bad
73
// for make check since any error will
76
#define TEST_DIR "." // Directory to scan for OpenScop files
77
#define TEST_SUFFIX ".scop" // Suffix of OpenScop files
82
* This function tests an onpenscop file. A test has six steps:
83
* 1. read the file to raise the data up to OpenScop data structures,
84
* 2. clone the data structures,
85
* 3. compare the clone and the original one,
86
* 4. dump the data structures to a new OpenScop file,
87
* 5. read the generated file,
88
* 6. compare the data structures.
89
* If everything went well, the data structure of the two scops are the same.
90
* \param input_name The name of the input file.
91
* \param verbose Verbose option (1 to set, 0 not to set).
92
* \return 1 if the test is successful, 0 otherwise.
94
int test_file(char * input_name, int verbose) {
101
FILE * input_file, * output_file;
102
osl_scop_p input_scop;
103
osl_scop_p output_scop;
104
osl_scop_p cloned_scop;
106
printf("\nTesting file %s... \n", input_name);
108
// PART I. Raise from file.
109
input_file = fopen(input_name, "r");
110
if (input_file == NULL) {
112
fprintf(stderr, "\nError: unable to open file %s\n", input_name);
115
input_scop = osl_scop_read(input_file);
118
// PART II. Clone and test.
119
cloned_scop = osl_scop_clone(input_scop);
120
// Compare the two scops.
121
if (cloning = osl_scop_equal(input_scop, cloned_scop))
122
printf("- cloning succeeded\n");
124
printf("- cloning failed\n");
126
// PART III. Dump to file and test.
127
output_name = tmpnam(NULL);
128
output_file = fopen(output_name, "w");
129
//osl_scop_dump(stdout, input_scop);
130
//osl_scop_print(stdout, input_scop);
131
osl_scop_print(output_file, input_scop);
134
// Raise the generated file to data structures.
135
output_file = fopen(output_name, "r");
136
output_scop = osl_scop_read(output_file);
137
//osl_scop_dump(stdout, output_scop);
141
printf("\n\n*************************************************\n\n");
142
osl_scop_dump(stdout, output_scop);
143
osl_scop_print(stdout, output_scop);
144
printf("\n*************************************************\n\n");
147
// Compare the two scops.
148
if (dumping = osl_scop_equal(input_scop, output_scop))
149
printf("- dumping succeeded\n");
151
printf("- dumping failed\n");
154
if (equal = (cloning + dumping > 0) ? 1 : 0)
155
printf("Success :-)\n");
157
printf("Failure :-(\n");
160
osl_scop_free(input_scop);
161
osl_scop_free(cloned_scop);
162
osl_scop_free(output_scop);
170
* OpenScop test program.
171
* Usage: osl_test [-v] [osl_file]
172
* This program scans a directory for openscop files and test each of them.
173
* Optionnally the user can provide a file name to check this file only. A
174
* verbose option is also provided to output more information during tests.
176
int main(int argc, char * argv[]) {
177
int total = 0; // Total number of tests.
178
int success = 0; // Number of successes.
179
int verbose = 0; // 1 if the verbose option is set, 0 otherwise.
180
int dirtest = 1; // 1 if we check a whole directory, 0 for a single file.
181
int fileidx = 0; // Index of the file to check in argv (0 if none).
187
// Process the command line information
188
if (((argc > 1) && (!strcmp(argv[1], "-v"))) ||
189
((argc > 2) && (!strcmp(argv[2], "-v"))))
192
if ((argc > 3) || ((argc == 3) && (!verbose))) {
193
fprintf(stderr, "usage: osl_test [-v] [osl_file]\n");
197
if ((argc - verbose) > 1) {
199
fileidx = (!strcmp(argv[1], "-v")) ? 2 : 1;
202
// Proceed with the test(s), either directory or single file
204
suffix_length = strlen(TEST_SUFFIX);
206
// For each file in the directory to check...
207
dir = opendir(TEST_DIR);
208
while ((dp = readdir(dir)) != NULL) {
209
d_namlen = strlen(dp->d_name);
210
// If the file has the convenient suffix...
211
if ((d_namlen > suffix_length) &&
212
(!strcmp(dp->d_name+(d_namlen-suffix_length), TEST_SUFFIX))) {
217
exit(test_file(dp->d_name, verbose) ? 0 : 1);
219
if (!WEXITSTATUS(report))
222
success += test_file(dp->d_name, verbose);
230
success = test_file(argv[fileidx], verbose);
234
printf("\n +-----------------------+\n");
235
printf(" | OpenScop Test Summary |\n");
236
printf(" |-----------------------|\n");
237
printf(" | total %4d |\n", total);
238
printf(" | success(es) %4d |\n", success);
239
printf(" | failure(s) %4d |\n", total - success);
240
printf(" +-----------------------+\n\n");
242
// Return 0 if all tests were successful, 1 otherwise.