input/output test in make check
[openscop.git] / tests / openscop_test.c
blobb4218ba5a0d46586369273243908ecf78b954fff
2 /*+-----------------------------------------------------------------**
3 ** OpenScop Library **
4 **-----------------------------------------------------------------**
5 ** test.c **
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 * '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---' '--' *
29 * *
30 * Copyright (C) 2008 University Paris-Sud 11 and INRIA *
31 * *
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 *
35 * are met: *
36 * *
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. *
44 * *
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. *
55 * *
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> *
60 * *
61 *****************************************************************************/
63 #include <stdlib.h>
64 #include <stdio.h>
65 #include <dirent.h>
66 #include <string.h>
67 #include <openscop/openscop.h>
69 #define TEST_DIR "." // Directory to scan for OpenScop files
70 #define TEST_SUFFIX ".scop" // Suffix of OpenScop files
72 /**
73 * OpenScop test program.
74 * This program scans a directory for openscop files and test each of them.
75 * A test has four steps:
76 * 1. read the file to raise the data up to OpenScop data structures,
77 * 2. dump the data structures to a new OpenScop file,
78 * 3. read the generated file,
79 * 4. compare the data structures.
80 * If everything went well, the data structure of the two scops are the same.
82 int main(int argc, char * argv[])
84 int success = 0;
85 int failure = 0;
86 int suffix_length;
87 char * output_name;
88 FILE * input_file, * output_file;
89 DIR * dir;
90 struct dirent * dp;
91 openscop_scop_p input_scop;
92 openscop_scop_p output_scop;
94 if (argc != 1)
96 fprintf(stderr, "usage: openscop_test\n");
97 exit(1);
100 suffix_length = strlen(TEST_SUFFIX);
102 // For each file in the directory to check...
103 dir = opendir(TEST_DIR);
104 while ((dp = readdir(dir)) != NULL)
106 // If the file has the convenient suffix...
107 if ((dp->d_namlen > suffix_length) &&
108 (strcmp(dp->d_name+(dp->d_namlen-suffix_length), TEST_SUFFIX) == 0))
110 printf("Testing file %20s... ", dp->d_name);
112 // Raise the OpenScop file format to OpenScop data structures.
113 input_file = fopen(dp->d_name, "r");
114 input_scop = openscop_scop_read(input_file);
115 fclose(input_file);
117 // Dump the OpenScop data structures to OpenScop file format.
118 output_name = tmpnam(NULL);
119 output_file = fopen(output_name, "w");
120 openscop_scop_print_dot_scop(output_file, input_scop);
121 fclose(output_file);
123 // Raise the generated file to data structures.
124 output_file = fopen(output_name, "r");
125 output_scop = openscop_scop_read(output_file);
126 fclose(output_file);
128 // Compare the two scops.
129 if (openscop_scop_equal(input_scop, output_scop) == 1)
131 printf("Success :-)\n");
132 success++;
134 else
136 printf("Failure :-(\n", argv[1]);
137 failure++;
140 /* Save the planet. */
141 openscop_scop_free(input_scop);
142 openscop_scop_free(output_scop);
143 remove(output_name);
147 closedir(dir);
148 printf("\n +-----------------------+\n");
149 printf(" | OpenScop Test Summary |\n");
150 printf(" |-----------------------|\n");
151 printf(" | total %4d |\n", success+failure);
152 printf(" | success(es) %4d |\n", success);
153 printf(" | failure(s) %4d |\n", failure);
154 printf(" +-----------------------+\n\n");
156 if (failure)
157 return 1;
158 else
159 return 0;