add isl_set_fix_dim_si
[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_affine_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
16         n = snprintf(filename, sizeof(filename),
17                         "%s/test_inputs/%s.polylib", srcdir, name);
18         assert(n < sizeof(filename));
19         input = fopen(filename, "r");
20         assert(input);
21
22         bset1 = isl_basic_set_read_from_file(ctx, input, ISL_FORMAT_POLYLIB);
23         bset2 = isl_basic_set_read_from_file(ctx, input, ISL_FORMAT_POLYLIB);
24
25         bset1 = isl_basic_set_affine_hull(ctx, bset1);
26
27         assert(isl_basic_set_is_equal(ctx, bset1, bset2) == 1);
28
29         isl_basic_set_free(ctx, bset1);
30         isl_basic_set_free(ctx, bset2);
31
32         fclose(input);
33 }
34
35 void test_affine_hull(struct isl_ctx *ctx)
36 {
37         test_affine_hull_case(ctx, "affine2");
38         test_affine_hull_case(ctx, "affine");
39 }
40
41 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
42 {
43         char filename[PATH_MAX];
44         FILE *input;
45         int n;
46         struct isl_basic_set *bset1, *bset2;
47         struct isl_set *set;
48
49         n = snprintf(filename, sizeof(filename),
50                         "%s/test_inputs/%s.polylib", srcdir, name);
51         assert(n < sizeof(filename));
52         input = fopen(filename, "r");
53         assert(input);
54
55         bset1 = isl_basic_set_read_from_file(ctx, input, ISL_FORMAT_POLYLIB);
56         bset2 = isl_basic_set_read_from_file(ctx, input, ISL_FORMAT_POLYLIB);
57
58         set = isl_basic_set_union(ctx, bset1, bset2);
59         bset1 = isl_set_convex_hull(ctx, set);
60
61         bset2 = isl_basic_set_read_from_file(ctx, input, ISL_FORMAT_POLYLIB);
62
63         assert(isl_basic_set_is_equal(ctx, bset1, bset2) == 1);
64
65         isl_basic_set_free(ctx, bset1);
66         isl_basic_set_free(ctx, bset2);
67
68         fclose(input);
69 }
70
71 void test_convex_hull(struct isl_ctx *ctx)
72 {
73         test_convex_hull_case(ctx, "convex0");
74         test_convex_hull_case(ctx, "convex1");
75         test_convex_hull_case(ctx, "convex2");
76         test_convex_hull_case(ctx, "convex3");
77         test_convex_hull_case(ctx, "convex4");
78         test_convex_hull_case(ctx, "convex5");
79         test_convex_hull_case(ctx, "convex6");
80         test_convex_hull_case(ctx, "convex7");
81 }
82
83 int main()
84 {
85         struct isl_ctx *ctx;
86
87         srcdir = getenv("srcdir");
88
89         ctx = isl_ctx_alloc();
90         test_affine_hull(ctx);
91         test_convex_hull(ctx);
92         isl_ctx_free(ctx);
93         return 0;
94 }