6 #include <isl_constraint.h>
10 /* Construct the basic set { [i] : 5 <= i <= N } */
11 void test_construction(struct isl_ctx *ctx)
14 struct isl_basic_set *bset;
15 struct isl_constraint *c;
19 bset = isl_basic_set_universe(ctx, 1, 1);
21 c = isl_inequality_alloc(isl_dim_copy(bset->dim));
22 isl_int_set_si(v, -1);
23 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
25 isl_constraint_set_coefficient(c, isl_dim_param, 0, v);
26 bset = isl_basic_set_add_constraint(bset, c);
28 c = isl_inequality_alloc(isl_dim_copy(bset->dim));
30 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
31 isl_int_set_si(v, -5);
32 isl_constraint_set_constant(c, v);
33 bset = isl_basic_set_add_constraint(bset, c);
35 isl_basic_set_free(bset);
40 void test_application_case(struct isl_ctx *ctx, const char *name)
42 char filename[PATH_MAX];
45 struct isl_basic_set *bset1, *bset2;
46 struct isl_basic_map *bmap;
48 n = snprintf(filename, sizeof(filename),
49 "%s/test_inputs/%s.omega", srcdir, name);
50 assert(n < sizeof(filename));
51 input = fopen(filename, "r");
54 bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_OMEGA);
55 bmap = isl_basic_map_read_from_file(ctx, input, 0, ISL_FORMAT_OMEGA);
57 bset1 = isl_basic_set_apply(bset1, bmap);
59 bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_OMEGA);
61 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
63 isl_basic_set_free(bset1);
64 isl_basic_set_free(bset2);
69 void test_application(struct isl_ctx *ctx)
71 test_application_case(ctx, "application");
72 test_application_case(ctx, "application2");
75 void test_affine_hull_case(struct isl_ctx *ctx, const char *name)
77 char filename[PATH_MAX];
80 struct isl_basic_set *bset1, *bset2;
82 n = snprintf(filename, sizeof(filename),
83 "%s/test_inputs/%s.polylib", srcdir, name);
84 assert(n < sizeof(filename));
85 input = fopen(filename, "r");
88 bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
89 bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
91 bset1 = isl_basic_set_affine_hull(bset1);
93 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
95 isl_basic_set_free(bset1);
96 isl_basic_set_free(bset2);
101 void test_affine_hull(struct isl_ctx *ctx)
103 test_affine_hull_case(ctx, "affine2");
104 test_affine_hull_case(ctx, "affine");
107 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
109 char filename[PATH_MAX];
112 struct isl_basic_set *bset1, *bset2;
115 n = snprintf(filename, sizeof(filename),
116 "%s/test_inputs/%s.polylib", srcdir, name);
117 assert(n < sizeof(filename));
118 input = fopen(filename, "r");
121 bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
122 bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
124 set = isl_basic_set_union(bset1, bset2);
125 bset1 = isl_set_convex_hull(set);
127 bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
129 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
131 isl_basic_set_free(bset1);
132 isl_basic_set_free(bset2);
137 void test_convex_hull(struct isl_ctx *ctx)
139 test_convex_hull_case(ctx, "convex0");
140 test_convex_hull_case(ctx, "convex1");
141 test_convex_hull_case(ctx, "convex2");
142 test_convex_hull_case(ctx, "convex3");
143 test_convex_hull_case(ctx, "convex4");
144 test_convex_hull_case(ctx, "convex5");
145 test_convex_hull_case(ctx, "convex6");
146 test_convex_hull_case(ctx, "convex7");
147 test_convex_hull_case(ctx, "convex8");
148 test_convex_hull_case(ctx, "convex9");
149 test_convex_hull_case(ctx, "convex10");
150 test_convex_hull_case(ctx, "convex11");
153 void test_gist_case(struct isl_ctx *ctx, const char *name)
155 char filename[PATH_MAX];
158 struct isl_basic_set *bset1, *bset2;
161 n = snprintf(filename, sizeof(filename),
162 "%s/test_inputs/%s.polylib", srcdir, name);
163 assert(n < sizeof(filename));
164 input = fopen(filename, "r");
167 bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
168 bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
170 bset1 = isl_basic_set_gist(bset1, bset2);
172 bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
174 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
176 isl_basic_set_free(bset1);
177 isl_basic_set_free(bset2);
182 void test_gist(struct isl_ctx *ctx)
184 test_gist_case(ctx, "gist1");
191 srcdir = getenv("srcdir");
193 ctx = isl_ctx_alloc();
194 test_construction(ctx);
195 test_application(ctx);
196 test_affine_hull(ctx);
197 test_convex_hull(ctx);