c5fdd9221fe703a1549de5f9bf9a10dd9243be31
[platform/upstream/isl.git] / isl_test.c
1 #include <assert.h>
2 #include <stdio.h>
3 #include <limits.h>
4 #include <isl_ctx.h>
5 #include <isl_set.h>
6
7 static char *srcdir;
8
9 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
10 {
11         char filename[PATH_MAX];
12         FILE *input;
13         int n;
14         struct isl_basic_set *bset1, *bset2;
15         struct isl_set *set;
16
17         n = snprintf(filename, sizeof(filename),
18                         "%s/test_inputs/%s.polylib", srcdir, name);
19         assert(n < sizeof(filename));
20         input = fopen(filename, "r");
21         assert(input);
22
23         bset1 = isl_basic_set_read_from_file(ctx, input, ISL_FORMAT_POLYLIB);
24         bset2 = isl_basic_set_read_from_file(ctx, input, ISL_FORMAT_POLYLIB);
25
26         set = isl_basic_set_union(ctx, bset1, bset2);
27         bset1 = isl_set_convex_hull(ctx, set);
28
29         bset2 = isl_basic_set_read_from_file(ctx, input, ISL_FORMAT_POLYLIB);
30
31         assert(isl_basic_set_is_equal(ctx, bset1, bset2) == 1);
32
33         isl_basic_set_free(ctx, bset1);
34         isl_basic_set_free(ctx, bset2);
35
36         fclose(input);
37 }
38
39 void test_convex_hull(struct isl_ctx *ctx)
40 {
41         test_convex_hull_case(ctx, "convex0");
42         test_convex_hull_case(ctx, "convex1");
43         test_convex_hull_case(ctx, "convex2");
44         test_convex_hull_case(ctx, "convex3");
45         test_convex_hull_case(ctx, "convex4");
46         test_convex_hull_case(ctx, "convex5");
47         test_convex_hull_case(ctx, "convex6");
48         test_convex_hull_case(ctx, "convex7");
49 }
50
51 int main()
52 {
53         struct isl_ctx *ctx;
54
55         srcdir = getenv("srcdir");
56
57         ctx = isl_ctx_alloc();
58         test_convex_hull(ctx);
59         isl_ctx_free(ctx);
60         return 0;
61 }