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)
34 #define assert(exp) assert_impl(exp, __FILE__, __LINE__, #exp)
36 #include "isl_test_cpp-generic.cc"
38 /* Test that isl_bool values are returned correctly.
40 * In particular, check the conversion to bool in case of true and false, and
41 * exception throwing in case of error.
43 static void test_return_bool(isl::ctx ctx
)
45 isl::set
empty(ctx
, "{ : false }");
46 isl::set
univ(ctx
, "{ : }");
49 bool b_true
= empty
.is_empty();
50 bool b_false
= univ
.is_empty();
54 die("no exception raised");
55 } catch (const isl::exception_invalid
&e
) {
64 /* Test that return values are handled correctly.
66 * Test that isl C++ objects, integers, boolean values, and strings are
69 static void test_return(isl::ctx ctx
)
73 test_return_bool(ctx
);
74 test_return_string(ctx
);
77 /* Test that foreach functions are modeled correctly.
79 * Verify that lambdas are correctly called as callback of a 'foreach'
80 * function and that variables captured by the lambda work correctly. Also
81 * check that the foreach function handles exceptions thrown from
82 * the lambda and that it propagates the exception.
84 static void test_foreach(isl::ctx ctx
)
86 isl::set
s(ctx
, "{ [0]; [1]; [2] }");
88 std::vector
<isl::basic_set
> basic_sets
;
90 auto add_to_vector
= [&] (isl::basic_set bs
) {
91 basic_sets
.push_back(bs
);
94 s
.foreach_basic_set(add_to_vector
);
96 assert(basic_sets
.size() == 3);
97 assert(isl::set(basic_sets
[0]).is_subset(s
));
98 assert(isl::set(basic_sets
[1]).is_subset(s
));
99 assert(isl::set(basic_sets
[2]).is_subset(s
));
100 assert(!basic_sets
[0].is_equal(basic_sets
[1]));
102 auto fail
= [&] (isl::basic_set bs
) {
108 s
.foreach_basic_set(fail
);
109 die("no exception raised");
110 } catch (char const *s
) {
116 /* Test the functionality of "every" functions.
118 * In particular, test the generic functionality and
119 * test that exceptions are properly propagated.
121 static void test_every(isl::ctx ctx
)
123 isl::union_set
us(ctx
, "{ A[i]; B[j] }");
125 test_every_generic(ctx
);
127 auto fail
= [] (isl::set s
) -> bool {
133 die("no exception raised");
134 } catch (char const *s
) {
140 /* Test that an exception is generated for an isl error and
141 * that the error message is captured by the exception.
142 * Also check that the exception can be copied and that copying
143 * does not throw any exceptions.
145 static void test_exception(isl::ctx ctx
)
147 isl::multi_union_pw_aff
mupa(ctx
, "[]");
150 static_assert(std::is_nothrow_copy_constructible
<isl::exception
>::value
,
151 "exceptions must be nothrow-copy-constructible");
152 static_assert(std::is_nothrow_assignable
<isl::exception
,
153 isl::exception
>::value
,
154 "exceptions must be nothrow-assignable");
157 auto umap
= isl::union_map::from(mupa
);
158 } catch (const isl::exception_unsupported
&error
) {
159 die("caught wrong exception");
160 } catch (const isl::exception
&error
) {
161 assert(strstr(error
.what(), "without explicit domain"));
164 assert(strstr(copy
.what(), "without explicit domain"));
167 /* Test basic schedule tree functionality.
169 * In particular, create a simple schedule tree and
170 * - perform some generic tests
171 * - test map_descendant_bottom_up in the failing case
172 * - test foreach_descendant_top_down
173 * - test every_descendant
175 static void test_schedule_tree(isl::ctx ctx
)
177 auto root
= test_schedule_tree_generic(ctx
);
179 auto fail_map
= [](isl::schedule_node node
) {
185 root
.map_descendant_bottom_up(fail_map
);
186 die("no exception raised");
187 } catch (char const *s
) {
193 auto inc_count
= [&count
](isl::schedule_node node
) {
197 root
.foreach_descendant_top_down(inc_count
);
201 auto inc_count_once
= [&count
](isl::schedule_node node
) {
205 root
.foreach_descendant_top_down(inc_count_once
);
208 auto is_not_domain
= [](isl::schedule_node node
) {
209 return !node
.isa
<isl::schedule_node_domain
>();
211 assert(root
.child(0).every_descendant(is_not_domain
));
212 assert(!root
.every_descendant(is_not_domain
));
214 auto fail
= [](isl::schedule_node node
) {
220 root
.every_descendant(fail
);
221 die("no exception raised");
222 } catch (char const *s
) {
227 auto domain
= root
.as
<isl::schedule_node_domain
>().domain();
228 auto filters
= isl::union_set(ctx
, "{}");
229 auto collect_filters
= [&filters
](isl::schedule_node node
) {
230 if (node
.isa
<isl::schedule_node_filter
>()) {
231 auto filter
= node
.as
<isl::schedule_node_filter
>();
232 filters
= filters
.unite(filter
.filter());
236 root
.every_descendant(collect_filters
);
237 assert(domain
.is_equal(filters
));
240 /* Test basic AST generation from a schedule tree.
242 * In particular, create a simple schedule tree and
243 * - perform some generic tests
244 * - test at_each_domain in the failing case
246 static void test_ast_build(isl::ctx ctx
)
248 auto schedule
= test_ast_build_generic(ctx
);
251 int count_ast_fail
= 0;
252 auto fail_inc_count_ast
=
253 [&count_ast_fail
, &do_fail
](isl::ast_node node
,
254 isl::ast_build build
) {
260 auto build
= isl::ast_build(ctx
);
261 build
= build
.set_at_each_domain(fail_inc_count_ast
);
264 auto ast
= build
.node_from(schedule
);
265 } catch (char const *s
) {
269 assert(count_ast_fail
> 0);
270 auto build_copy
= build
;
273 [&count_ast
](isl::ast_node node
, isl::ast_build build
) {
277 build_copy
= build_copy
.set_at_each_domain(inc_count_ast
);
278 auto ast
= build_copy
.node_from(schedule
);
279 assert(count_ast
== 2);
282 ast
= build
.node_from(schedule
);
283 assert(count_ast_fail
== 2);
286 /* Test the (unchecked) isl C++ interface
289 * - The isl C <-> C++ pointer interface
290 * - Object construction
291 * - Different parameter types
292 * - Different return types
293 * - Foreach functions
298 * - AST expression generation
302 isl_ctx
*ctx
= isl_ctx_alloc();
304 isl_options_set_on_error(ctx
, ISL_ON_ERROR_ABORT
);
307 test_constructors(ctx
);
308 test_parameters(ctx
);
314 test_schedule_tree(ctx
);
316 test_ast_build_expr(ctx
);