1 /* Copyright 2016-2017 Tobias Grosser
3 * Use of this software is governed by the MIT license
5 * Written by Tobias Grosser, Weststrasse 47, CH-8003, Zurich
15 #include <isl/options.h>
18 static void die_impl(const char *file
, int line
, const char *message
)
20 fprintf(stderr
, "Assertion failed in %s:%d %s\n", file
, line
, message
);
24 static void assert_impl(bool condition
, const char *file
, int line
,
30 return die_impl(file
, line
, message
);
33 #define die(msg) die_impl(__FILE__, __LINE__, msg)
35 #define assert(exp) assert_impl(exp, __FILE__, __LINE__, #exp)
37 #include "isl_test_cpp-generic.cc"
39 /* Test that isl_bool values are returned correctly.
41 * In particular, check the conversion to bool in case of true and false, and
42 * exception throwing in case of error.
44 static void test_return_bool(isl::ctx ctx
)
46 isl::set
empty(ctx
, "{ : false }");
47 isl::set
univ(ctx
, "{ : }");
50 bool b_true
= empty
.is_empty();
51 bool b_false
= univ
.is_empty();
55 die("no exception raised");
56 } catch (const isl::exception_invalid
&e
) {
65 /* Test that return values are handled correctly.
67 * Test that isl C++ objects, integers, boolean values, and strings are
70 static void test_return(isl::ctx ctx
)
74 test_return_bool(ctx
);
75 test_return_string(ctx
);
78 /* Test that foreach functions are modeled correctly.
80 * Verify that lambdas are correctly called as callback of a 'foreach'
81 * function and that variables captured by the lambda work correctly. Also
82 * check that the foreach function handles exceptions thrown from
83 * the lambda and that it propagates the exception.
85 static void test_foreach(isl::ctx ctx
)
87 isl::set
s(ctx
, "{ [0]; [1]; [2] }");
89 std::vector
<isl::basic_set
> basic_sets
;
91 auto add_to_vector
= [&] (isl::basic_set bs
) {
92 basic_sets
.push_back(bs
);
95 s
.foreach_basic_set(add_to_vector
);
97 assert(basic_sets
.size() == 3);
98 assert(isl::set(basic_sets
[0]).is_subset(s
));
99 assert(isl::set(basic_sets
[1]).is_subset(s
));
100 assert(isl::set(basic_sets
[2]).is_subset(s
));
101 assert(!basic_sets
[0].is_equal(basic_sets
[1]));
103 auto fail
= [&] (isl::basic_set bs
) {
109 s
.foreach_basic_set(fail
);
110 die("no exception raised");
111 } catch (char const *s
) {
117 /* Test the functionality of "every" functions.
119 * In particular, test the generic functionality and
120 * test that exceptions are properly propagated.
122 static void test_every(isl::ctx ctx
)
124 isl::union_set
us(ctx
, "{ A[i]; B[j] }");
126 test_every_generic(ctx
);
128 auto fail
= [] (isl::set s
) -> bool {
134 die("no exception raised");
135 } catch (char const *s
) {
141 /* Test that an exception is generated for an isl error and
142 * that the error message is captured by the exception.
143 * Also check that the exception can be copied and that copying
144 * does not throw any exceptions.
146 static void test_exception(isl::ctx ctx
)
148 isl::multi_union_pw_aff
mupa(ctx
, "[]");
151 static_assert(std::is_nothrow_copy_constructible
<isl::exception
>::value
,
152 "exceptions must be nothrow-copy-constructible");
153 static_assert(std::is_nothrow_assignable
<isl::exception
,
154 isl::exception
>::value
,
155 "exceptions must be nothrow-assignable");
158 auto umap
= isl::union_map::from(mupa
);
159 } catch (const isl::exception_unsupported
&error
) {
160 die("caught wrong exception");
161 } catch (const isl::exception
&error
) {
162 assert(strstr(error
.what(), "without explicit domain"));
165 assert(strstr(copy
.what(), "without explicit domain"));
168 /* Test basic schedule tree functionality.
170 * In particular, create a simple schedule tree and
171 * - perform some generic tests
172 * - test map_descendant_bottom_up in the failing case
173 * - test foreach_descendant_top_down
174 * - test every_descendant
176 static void test_schedule_tree(isl::ctx ctx
)
178 auto root
= test_schedule_tree_generic(ctx
);
180 auto fail_map
= [](isl::schedule_node node
) {
186 root
.map_descendant_bottom_up(fail_map
);
187 die("no exception raised");
188 } catch (char const *s
) {
194 auto inc_count
= [&count
](isl::schedule_node node
) {
198 root
.foreach_descendant_top_down(inc_count
);
202 auto inc_count_once
= [&count
](isl::schedule_node node
) {
206 root
.foreach_descendant_top_down(inc_count_once
);
209 auto is_not_domain
= [](isl::schedule_node node
) {
210 return !node
.isa
<isl::schedule_node_domain
>();
212 assert(root
.child(0).every_descendant(is_not_domain
));
213 assert(!root
.every_descendant(is_not_domain
));
215 auto fail
= [](isl::schedule_node node
) {
221 root
.every_descendant(fail
);
222 die("no exception raised");
223 } catch (char const *s
) {
228 auto domain
= root
.as
<isl::schedule_node_domain
>().domain();
229 auto filters
= isl::union_set(ctx
, "{}");
230 auto collect_filters
= [&filters
](isl::schedule_node node
) {
231 if (node
.isa
<isl::schedule_node_filter
>()) {
232 auto filter
= node
.as
<isl::schedule_node_filter
>();
233 filters
= filters
.unite(filter
.filter());
237 root
.every_descendant(collect_filters
);
238 assert(domain
.is_equal(filters
));
241 /* Test basic AST generation from a schedule tree.
243 * In particular, create a simple schedule tree and
244 * - perform some generic tests
245 * - test at_each_domain in the failing case
247 static void test_ast_build(isl::ctx ctx
)
249 auto schedule
= test_ast_build_generic(ctx
);
252 int count_ast_fail
= 0;
253 auto fail_inc_count_ast
=
254 [&count_ast_fail
, &do_fail
](isl::ast_node node
,
255 isl::ast_build build
) {
261 auto build
= isl::ast_build(ctx
);
262 build
= build
.set_at_each_domain(fail_inc_count_ast
);
265 auto ast
= build
.node_from(schedule
);
266 } catch (char const *s
) {
270 assert(count_ast_fail
> 0);
271 auto build_copy
= build
;
274 [&count_ast
](isl::ast_node node
, isl::ast_build build
) {
278 build_copy
= build_copy
.set_at_each_domain(inc_count_ast
);
279 auto ast
= build_copy
.node_from(schedule
);
280 assert(count_ast
== 2);
283 ast
= build
.node_from(schedule
);
284 assert(count_ast_fail
== 2);
287 /* Test the (unchecked) isl C++ interface
290 * - The isl C <-> C++ pointer interface
291 * - Object construction
292 * - Different parameter types
293 * - Different return types
294 * - Foreach functions
299 * - AST expression generation
303 isl_ctx
*ctx
= isl_ctx_alloc();
305 isl_options_set_on_error(ctx
, ISL_ON_ERROR_ABORT
);
308 test_constructors(ctx
);
309 test_parameters(ctx
);
315 test_schedule_tree(ctx
);
317 test_ast_build_expr(ctx
);