#include <isl_options_private.h>
#include <isl/vertices.h>
+#define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
+
static char *srcdir;
static char *get_filename(isl_ctx *ctx, const char *name, const char *suffix) {
isl_map_free(map);
}
-void test_parse_map_equal(isl_ctx *ctx, const char *str, const char *str2)
+int test_parse_map_equal(isl_ctx *ctx, const char *str, const char *str2)
{
isl_map *map, *map2;
+ int equal;
map = isl_map_read_from_str(ctx, str);
map2 = isl_map_read_from_str(ctx, str2);
- assert(map && map2 && isl_map_is_equal(map, map2));
+ equal = isl_map_is_equal(map, map2);
isl_map_free(map);
isl_map_free(map2);
+
+ if (equal < 0)
+ return -1;
+ if (!equal)
+ isl_die(ctx, isl_error_unknown, "maps not equal",
+ return -1);
+
+ return 0;
}
void test_parse_pwqp(isl_ctx *ctx, const char *str)
isl_pw_aff_free(pwaff);
}
-void test_parse(struct isl_ctx *ctx)
+int test_parse(struct isl_ctx *ctx)
{
isl_map *map, *map2;
const char *str, *str2;
str = "{ [x,y] : [([x/2]+y)/3] >= 1 }";
str2 = "{ [x, y] : 2y >= 6 - x }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
- test_parse_map_equal(ctx, "{ [x,y] : x <= min(y, 2*y+3) }",
- "{ [x,y] : x <= y, 2*y + 3 }");
+ if (test_parse_map_equal(ctx, "{ [x,y] : x <= min(y, 2*y+3) }",
+ "{ [x,y] : x <= y, 2*y + 3 }") < 0)
+ return -1;
str = "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
- test_parse_map_equal(ctx, "{ [x,y] : x >= min(y, 2*y+3) }", str);
+ if (test_parse_map_equal(ctx, "{ [x,y] : x >= min(y, 2*y+3) }",
+ str) < 0)
+ return -1;
str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
map = isl_map_read_from_str(ctx, str);
str = "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
str2 = "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
str = "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
str2 = "{ [i,j] -> [min(i,j)] }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
str = "{ [i,j] : i != j }";
str2 = "{ [i,j] : i < j or i > j }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
str = "{ [i,j] : (i+1)*2 >= j }";
str2 = "{ [i, j] : j <= 2 + 2i }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
str = "{ [i] -> [i > 0 ? 4 : 5] }";
str2 = "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
str = "[N=2,M] -> { [i=[(M+N)/4]] }";
str2 = "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
str = "{ [x] : x >= 0 }";
str2 = "{ [x] : x-0 >= 0 }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
str = "{ [i] : ((i > 10)) }";
str2 = "{ [i] : i >= 11 }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
str = "{ [i] -> [0] }";
str2 = "{ [i] -> [0 * i] }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
test_parse_map(ctx, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
test_parse_pwaff(ctx, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
test_parse_pwqp(ctx, "{ [x] -> ([(x)/2] * [(x)/3]) }");
+
+ if (test_parse_map_equal(ctx, "{ [a] -> [b] : (not false) }",
+ "{ [a] -> [b] : true }") < 0)
+ return -1;
+
+ return 0;
}
void test_read(struct isl_ctx *ctx)
isl_map_free(map2);
}
-void test_div(struct isl_ctx *ctx)
+static int test_div(isl_ctx *ctx)
{
+ const char *str;
isl_int v;
isl_space *dim;
+ isl_set *set;
isl_local_space *ls;
struct isl_basic_set *bset;
struct isl_constraint *c;
isl_basic_set_free(bset);
isl_int_clear(v);
+
+ str = "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
+ "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
+ set = isl_set_read_from_str(ctx, str);
+ set = isl_set_compute_divs(set);
+ isl_set_free(set);
+ if (!set)
+ return -1;
+
+ return 0;
}
void test_application_case(struct isl_ctx *ctx, const char *name)
return 0;
}
+int test_coalesce_unbounded_wrapping(isl_ctx *ctx)
+{
+ int r = 0;
+ int bounded;
+
+ bounded = isl_options_get_coalesce_bounded_wrapping(ctx);
+ isl_options_set_coalesce_bounded_wrapping(ctx, 0);
+
+ if (test_coalesce_set(ctx,
+ "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
+ "-x - y + 1 >= 0 and -3 <= z <= 3;"
+ "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
+ "x-z + 20 >= 0 and x+z + 20 >= 0 and "
+ "-10 <= y <= 0}", 1) < 0)
+ goto error;
+ if (test_coalesce_set(ctx,
+ "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1) < 0)
+ goto error;
+ if (test_coalesce_set(ctx,
+ "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1) < 0)
+ goto error;
+
+ if (0) {
+error:
+ r = -1;
+ }
+
+ isl_options_set_coalesce_bounded_wrapping(ctx, bounded);
+
+ return r;
+}
+
int test_coalesce(struct isl_ctx *ctx)
{
const char *str;
test_coalesce_set(ctx,
"{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
"(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
- test_coalesce_set(ctx,
- "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
- "-x - y + 1 >= 0 and -3 <= z <= 3;"
- "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
- "x-z + 20 >= 0 and x+z + 20 >= 0 and -10 <= y <= 0}", 1);
- if (test_coalesce_set(ctx,
- "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1) < 0)
+ if (test_coalesce_unbounded_wrapping(ctx) < 0)
return -1;
if (test_coalesce_set(ctx, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0) < 0)
return -1;
- if (test_coalesce_set(ctx,
- "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1) < 0)
- return -1;
if (test_coalesce_set(ctx, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1) < 0)
return -1;
if (test_coalesce_set(ctx, "{ [0,0]; [i,i] : 1 <= i <= 10 }", 1) < 0)
if (test_coalesce_set(ctx, "{ [a, b] : exists e : 2e = a and "
"a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }", 0) < 0)
return -1;
+ if (test_coalesce_set(ctx,
+ "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
+ "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
+ "j >= 1 and j' <= i + j - i' and i >= 1; "
+ "[1, 1, 1, 1] }", 0) < 0)
+ return -1;
+ if (test_coalesce_set(ctx, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
+ "[i,j] : exists a : j = 3a }", 1) < 0)
+ return -1;
return 0;
}
isl_set_free(set2);
}
-void test_factorize(isl_ctx *ctx)
+int test_factorize(isl_ctx *ctx)
{
const char *str;
isl_basic_set *bset;
"3i5 >= -2i0 - i2 + 3i4 }";
bset = isl_basic_set_read_from_str(ctx, str);
f = isl_basic_set_factorizer(bset);
- assert(f);
isl_basic_set_free(bset);
isl_factorizer_free(f);
+ if (!f)
+ isl_die(ctx, isl_error_unknown,
+ "failed to construct factorizer", return -1);
str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
"i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
"9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
bset = isl_basic_set_read_from_str(ctx, str);
f = isl_basic_set_factorizer(bset);
- assert(f);
isl_basic_set_free(bset);
isl_factorizer_free(f);
+ if (!f)
+ isl_die(ctx, isl_error_unknown,
+ "failed to construct factorizer", return -1);
+
+ return 0;
}
static int check_injective(__isl_take isl_map *map, void *user)
return 0;
}
+static int aff_plain_is_equal(__isl_keep isl_aff *aff, const char *str)
+{
+ isl_aff *aff2;
+ int equal;
+
+ if (!aff)
+ return -1;
+
+ aff2 = isl_aff_read_from_str(isl_aff_get_ctx(aff), str);
+ equal = isl_aff_plain_is_equal(aff, aff2);
+ isl_aff_free(aff2);
+
+ return equal;
+}
+
+static int aff_check_plain_equal(__isl_keep isl_aff *aff, const char *str)
+{
+ int equal;
+
+ equal = aff_plain_is_equal(aff, str);
+ if (equal < 0)
+ return -1;
+ if (!equal)
+ isl_die(isl_aff_get_ctx(aff), isl_error_unknown,
+ "result not as expected", return -1);
+ return 0;
+}
+
int test_aff(isl_ctx *ctx)
{
const char *str;
isl_set *set;
- isl_space *dim;
+ isl_space *space;
isl_local_space *ls;
isl_aff *aff;
- int zero;
+ int zero, equal;
- dim = isl_space_set_alloc(ctx, 0, 1);
- ls = isl_local_space_from_space(dim);
+ space = isl_space_set_alloc(ctx, 0, 1);
+ ls = isl_local_space_from_space(space);
aff = isl_aff_zero_on_domain(ls);
aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
if (!zero)
isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
+ aff = isl_aff_read_from_str(ctx, "{ [-1] }");
+ aff = isl_aff_scale_down_ui(aff, 64);
+ aff = isl_aff_floor(aff);
+ equal = aff_check_plain_equal(aff, "{ [-1] }");
+ isl_aff_free(aff);
+ if (equal < 0)
+ return -1;
+
return 0;
}
return 0;
}
+int test_slice(isl_ctx *ctx)
+{
+ const char *str;
+ isl_map *map;
+ int equal;
+
+ str = "{ [i] -> [j] }";
+ map = isl_map_read_from_str(ctx, str);
+ map = isl_map_equate(map, isl_dim_in, 0, isl_dim_out, 0);
+ equal = map_check_equal(map, "{ [i] -> [i] }");
+ isl_map_free(map);
+ if (equal < 0)
+ return -1;
+
+ str = "{ [i] -> [j] }";
+ map = isl_map_read_from_str(ctx, str);
+ map = isl_map_equate(map, isl_dim_in, 0, isl_dim_in, 0);
+ equal = map_check_equal(map, "{ [i] -> [j] }");
+ isl_map_free(map);
+ if (equal < 0)
+ return -1;
+
+ str = "{ [i] -> [j] }";
+ map = isl_map_read_from_str(ctx, str);
+ map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_out, 0);
+ equal = map_check_equal(map, "{ [i] -> [-i] }");
+ isl_map_free(map);
+ if (equal < 0)
+ return -1;
+
+ str = "{ [i] -> [j] }";
+ map = isl_map_read_from_str(ctx, str);
+ map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_in, 0);
+ equal = map_check_equal(map, "{ [0] -> [j] }");
+ isl_map_free(map);
+ if (equal < 0)
+ return -1;
+
+ str = "{ [i] -> [j] }";
+ map = isl_map_read_from_str(ctx, str);
+ map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_out, 0);
+ equal = map_check_equal(map, "{ [i] -> [j] : i > j }");
+ isl_map_free(map);
+ if (equal < 0)
+ return -1;
+
+ str = "{ [i] -> [j] }";
+ map = isl_map_read_from_str(ctx, str);
+ map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_in, 0);
+ equal = map_check_equal(map, "{ [i] -> [j] : false }");
+ isl_map_free(map);
+ if (equal < 0)
+ return -1;
+
+ return 0;
+}
+
+struct {
+ const char *name;
+ int (*fn)(isl_ctx *ctx);
+} tests [] = {
+ { "div", &test_div },
+ { "slice", &test_slice },
+ { "fixed power", &test_fixed_power },
+ { "sample", &test_sample },
+ { "output", &test_output },
+ { "vertices", &test_vertices },
+ { "fixed", &test_fixed },
+ { "equal", &test_equal },
+ { "product", &test_product },
+ { "dim_max", &test_dim_max },
+ { "affine", &test_aff },
+ { "injective", &test_injective },
+ { "schedule", &test_schedule },
+ { "union_pw", &test_union_pw },
+ { "parse", &test_parse },
+ { "single-valued", &test_sv },
+ { "affine hull", &test_affine_hull },
+ { "coalesce", &test_coalesce },
+ { "factorize", &test_factorize },
+};
+
int main()
{
+ int i;
struct isl_ctx *ctx;
srcdir = getenv("srcdir");
assert(srcdir);
ctx = isl_ctx_alloc();
- if (test_fixed_power(ctx) < 0)
- goto error;
- if (test_sample(ctx) < 0)
- goto error;
- if (test_output(ctx) < 0)
- goto error;
- if (test_vertices(ctx) < 0)
- goto error;
- if (test_fixed(ctx) < 0)
- goto error;
- if (test_equal(ctx) < 0)
- goto error;
- if (test_product(ctx) < 0)
- goto error;
- if (test_dim_max(ctx) < 0)
- goto error;
- if (test_aff(ctx) < 0)
- goto error;
- if (test_injective(ctx) < 0)
- goto error;
- if (test_schedule(ctx) < 0)
- goto error;
- if (test_union_pw(ctx) < 0)
- goto error;
- test_factorize(ctx);
+ for (i = 0; i < ARRAY_SIZE(tests); ++i) {
+ printf("%s\n", tests[i].name);
+ if (tests[i].fn(ctx) < 0)
+ goto error;
+ }
test_subset(ctx);
test_lift(ctx);
test_bound(ctx);
test_union(ctx);
test_split_periods(ctx);
- test_parse(ctx);
test_pwqp(ctx);
test_lex(ctx);
- if (test_sv(ctx) < 0)
- goto error;
test_bijective(ctx);
test_dep(ctx);
test_read(ctx);
test_bounded(ctx);
test_construction(ctx);
test_dim(ctx);
- test_div(ctx);
test_application(ctx);
- if (test_affine_hull(ctx) < 0)
- goto error;
test_convex_hull(ctx);
test_gist(ctx);
- if (test_coalesce(ctx) < 0)
- goto error;
test_closure(ctx);
test_lexmin(ctx);
isl_ctx_free(ctx);