xref: /netbsd-src/external/mit/isl/dist/check_parse_fail_test_templ.c (revision 5971e316fdea024efff6be8f03536623db06833e)
1 /*
2  * Copyright 2021      Cerebras Systems
3  *
4  * Use of this software is governed by the MIT license
5  *
6  * Written by Sven Verdoolaege,
7  * Cerebras Systems, 1237 E Arques Ave, Sunnyvale, CA, USA
8  */
9 
10 #define xCAT(A,B) A ## B
11 #define CAT(A,B) xCAT(A,B)
12 #undef TYPE
13 #define TYPE CAT(isl_,BASE)
14 #define xFN(TYPE,NAME) TYPE ## _ ## NAME
15 #define FN(TYPE,NAME) xFN(TYPE,NAME)
16 
17 #undef TESTS
18 #define TESTS CAT(parse_,CAT(BASE,_fail_tests))
19 
20 /* Test parsing of objects of type TYPE
21  * that are expected to fail.
22  */
FN(check,TESTS)23 static isl_stat FN(check,TESTS)(isl_ctx *ctx)
24 {
25 	int i, n;
26 	int on_error;
27 
28 	on_error = isl_options_get_on_error(ctx);
29 	isl_options_set_on_error(ctx, ISL_ON_ERROR_CONTINUE);
30 	n = ARRAY_SIZE(TESTS);
31 	for (i = 0; i < n; ++i) {
32 		TYPE *obj;
33 
34 		obj = FN(TYPE,read_from_str)(ctx, TESTS[i]);
35 		FN(TYPE,free)(obj);
36 		if (obj)
37 			break;
38 	}
39 	isl_options_set_on_error(ctx, on_error);
40 	if (i < n)
41 		isl_die(ctx, isl_error_unknown,
42 			"parsing not expected to succeed",
43 			return isl_stat_error);
44 
45 	return isl_stat_ok;
46 }
47