isl_aff_alloc: check that all divs are known
[platform/upstream/isl.git] / isl_test.c
index 0558d08..55a50d5 100644 (file)
@@ -2131,6 +2131,57 @@ int test_schedule(isl_ctx *ctx)
        return test_special_schedule(ctx);
 }
 
+int test_plain_injective(isl_ctx *ctx, const char *str, int injective)
+{
+       isl_union_map *umap;
+       int test;
+
+       umap = isl_union_map_read_from_str(ctx, str);
+       test = isl_union_map_plain_is_injective(umap);
+       isl_union_map_free(umap);
+       if (test < 0)
+               return -1;
+       if (test == injective)
+               return 0;
+       if (injective)
+               isl_die(ctx, isl_error_unknown,
+                       "map not detected as injective", return -1);
+       else
+               isl_die(ctx, isl_error_unknown,
+                       "map detected as injective", return -1);
+}
+
+int test_injective(isl_ctx *ctx)
+{
+       const char *str;
+
+       if (test_plain_injective(ctx, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
+               return -1;
+       if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> B[0]}", 1))
+               return -1;
+       if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[1]}", 1))
+               return -1;
+       if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[0]}", 0))
+               return -1;
+       if (test_plain_injective(ctx, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
+               return -1;
+       if (test_plain_injective(ctx, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
+               return -1;
+       if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
+               return -1;
+       if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
+               return -1;
+
+       str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
+       if (test_plain_injective(ctx, str, 1))
+               return -1;
+       str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
+       if (test_plain_injective(ctx, str, 0))
+               return -1;
+
+       return 0;
+}
+
 int main()
 {
        struct isl_ctx *ctx;
@@ -2139,6 +2190,8 @@ int main()
        assert(srcdir);
 
        ctx = isl_ctx_alloc();
+       if (test_injective(ctx) < 0)
+               goto error;
        if (test_schedule(ctx) < 0)
                goto error;
        test_factorize(ctx);