From 764a8c5b795fc896b7ffdf7c3da4513001efa95b Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 5 Oct 2021 16:07:44 +0200 Subject: [PATCH] add basic isl_ast_node_foreach_descendant_top_down test An upcoming commit will change the implementation of isl_ast_node_foreach_descendant_top_down. Add a basic test to reduce the risk that these changes break the functionality. Signed-off-by: Sven Verdoolaege --- isl_test.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/isl_test.c b/isl_test.c index ddcbfb47..ac83b03c 100644 --- a/isl_test.c +++ b/isl_test.c @@ -9707,14 +9707,35 @@ static __isl_give isl_ast_node *after_for(__isl_take isl_ast_node *node, return node; } +/* This function is called after node in the AST generated + * from test_ast_gen1. + * + * Increment the count in "user" if this is a for node and + * return true to indicate that descendant should also be visited. + */ +static isl_bool count_for(__isl_keep isl_ast_node *node, void *user) +{ + int *count = user; + + if (isl_ast_node_get_type(node) == isl_ast_node_for) + ++*count; + + return isl_bool_true; +} + /* Check that the before_each_for and after_each_for callbacks * are called for each for loop in the generated code, * that they are called in the right order and that the isl_id * returned from the before_each_for callback is attached to * the isl_ast_node passed to the corresponding after_each_for call. + * + * Additionally, check the basic functionality of + * isl_ast_node_foreach_descendant_top_down by counting the number + * of for loops in the resulting AST. */ static isl_stat test_ast_gen1(isl_ctx *ctx) { + int count = 0; const char *str; isl_set *set; isl_union_map *schedule; @@ -9738,12 +9759,17 @@ static isl_stat test_ast_gen1(isl_ctx *ctx) &after_for, &data); tree = isl_ast_build_node_from_schedule_map(build, schedule); isl_ast_build_free(build); + + if (isl_ast_node_foreach_descendant_top_down(tree, + &count_for, &count) < 0) + tree = isl_ast_node_free(tree); + if (!tree) return isl_stat_error; isl_ast_node_free(tree); - if (data.before != 3 || data.after != 3) + if (data.before != 3 || data.after != 3 || count != 3) isl_die(ctx, isl_error_unknown, "unexpected number of for nodes", return isl_stat_error); -- 2.11.4.GIT