6 #include <isl_constraint.h>
10 /* Construct the basic set { [i] : 5 <= i <= N } */
11 void test_construction(struct isl_ctx *ctx)
15 struct isl_basic_set *bset;
16 struct isl_constraint *c;
20 dim = isl_dim_set_alloc(ctx, 1, 1);
21 bset = isl_basic_set_universe(dim);
23 c = isl_inequality_alloc(isl_dim_copy(bset->dim));
24 isl_int_set_si(v, -1);
25 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
27 isl_constraint_set_coefficient(c, isl_dim_param, 0, v);
28 bset = isl_basic_set_add_constraint(bset, c);
30 c = isl_inequality_alloc(isl_dim_copy(bset->dim));
32 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
33 isl_int_set_si(v, -5);
34 isl_constraint_set_constant(c, v);
35 bset = isl_basic_set_add_constraint(bset, c);
37 isl_basic_set_free(bset);
42 void test_application_case(struct isl_ctx *ctx, const char *name)
44 char filename[PATH_MAX];
47 struct isl_basic_set *bset1, *bset2;
48 struct isl_basic_map *bmap;
50 n = snprintf(filename, sizeof(filename),
51 "%s/test_inputs/%s.omega", srcdir, name);
52 assert(n < sizeof(filename));
53 input = fopen(filename, "r");
56 bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_OMEGA);
57 bmap = isl_basic_map_read_from_file(ctx, input, 0, ISL_FORMAT_OMEGA);
59 bset1 = isl_basic_set_apply(bset1, bmap);
61 bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_OMEGA);
63 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
65 isl_basic_set_free(bset1);
66 isl_basic_set_free(bset2);
71 void test_application(struct isl_ctx *ctx)
73 test_application_case(ctx, "application");
74 test_application_case(ctx, "application2");
77 void test_affine_hull_case(struct isl_ctx *ctx, const char *name)
79 char filename[PATH_MAX];
82 struct isl_basic_set *bset1, *bset2;
84 n = snprintf(filename, sizeof(filename),
85 "%s/test_inputs/%s.polylib", srcdir, name);
86 assert(n < sizeof(filename));
87 input = fopen(filename, "r");
90 bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
91 bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
93 bset1 = isl_basic_set_affine_hull(bset1);
95 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
97 isl_basic_set_free(bset1);
98 isl_basic_set_free(bset2);
103 void test_affine_hull(struct isl_ctx *ctx)
105 test_affine_hull_case(ctx, "affine2");
106 test_affine_hull_case(ctx, "affine");
109 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
111 char filename[PATH_MAX];
114 struct isl_basic_set *bset1, *bset2;
117 n = snprintf(filename, sizeof(filename),
118 "%s/test_inputs/%s.polylib", srcdir, name);
119 assert(n < sizeof(filename));
120 input = fopen(filename, "r");
123 bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
124 bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
126 set = isl_basic_set_union(bset1, bset2);
127 bset1 = isl_set_convex_hull(set);
129 bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
131 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
133 isl_basic_set_free(bset1);
134 isl_basic_set_free(bset2);
139 void test_convex_hull(struct isl_ctx *ctx)
141 test_convex_hull_case(ctx, "convex0");
142 test_convex_hull_case(ctx, "convex1");
143 test_convex_hull_case(ctx, "convex2");
144 test_convex_hull_case(ctx, "convex3");
145 test_convex_hull_case(ctx, "convex4");
146 test_convex_hull_case(ctx, "convex5");
147 test_convex_hull_case(ctx, "convex6");
148 test_convex_hull_case(ctx, "convex7");
149 test_convex_hull_case(ctx, "convex8");
150 test_convex_hull_case(ctx, "convex9");
151 test_convex_hull_case(ctx, "convex10");
152 test_convex_hull_case(ctx, "convex11");
155 void test_gist_case(struct isl_ctx *ctx, const char *name)
157 char filename[PATH_MAX];
160 struct isl_basic_set *bset1, *bset2;
163 n = snprintf(filename, sizeof(filename),
164 "%s/test_inputs/%s.polylib", srcdir, name);
165 assert(n < sizeof(filename));
166 input = fopen(filename, "r");
169 bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
170 bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
172 bset1 = isl_basic_set_gist(bset1, bset2);
174 bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
176 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
178 isl_basic_set_free(bset1);
179 isl_basic_set_free(bset2);
184 void test_gist(struct isl_ctx *ctx)
186 test_gist_case(ctx, "gist1");
193 srcdir = getenv("srcdir");
195 ctx = isl_ctx_alloc();
196 test_construction(ctx);
197 test_application(ctx);
198 test_affine_hull(ctx);
199 test_convex_hull(ctx);