comparison gcc/selftest.h @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* A self-testing framework, for use by -fself-test. 1 /* A self-testing framework, for use by -fself-test.
2 Copyright (C) 2015-2018 Free Software Foundation, Inc. 2 Copyright (C) 2015-2020 Free Software Foundation, Inc.
3 3
4 This file is part of GCC. 4 This file is part of GCC.
5 5
6 GCC is free software; you can redistribute it and/or modify it under 6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free 7 the terms of the GNU General Public License as published by the Free
28 namespace selftest { 28 namespace selftest {
29 29
30 /* A struct describing the source-location of a selftest, to make it 30 /* A struct describing the source-location of a selftest, to make it
31 easier to track down failing tests. */ 31 easier to track down failing tests. */
32 32
33 struct location 33 class location
34 { 34 {
35 public:
35 location (const char *file, int line, const char *function) 36 location (const char *file, int line, const char *function)
36 : m_file (file), m_line (line), m_function (function) {} 37 : m_file (file), m_line (line), m_function (function) {}
37 38
38 const char *m_file; 39 const char *m_file;
39 int m_line; 40 int m_line;
139 For maximum test coverage we want to run these tests with a variety 140 For maximum test coverage we want to run these tests with a variety
140 of situations: 141 of situations:
141 - line_table->default_range_bits: some frontends use a non-zero value 142 - line_table->default_range_bits: some frontends use a non-zero value
142 and others use zero 143 and others use zero
143 - the fallback modes within line-map.c: there are various threshold 144 - the fallback modes within line-map.c: there are various threshold
144 values for source_location/location_t beyond line-map.c changes 145 values for location_t beyond line-map.c changes
145 behavior (disabling of the range-packing optimization, disabling 146 behavior (disabling of the range-packing optimization, disabling
146 of column-tracking). We can exercise these by starting the line_table 147 of column-tracking). We can exercise these by starting the line_table
147 at interesting values at or near these thresholds. 148 at interesting values at or near these thresholds.
148 149
149 The following struct describes a particular case within our test 150 The following struct describes a particular case within our test
150 matrix. */ 151 matrix. */
151 152
152 struct line_table_case; 153 class line_table_case;
153 154
154 /* A class for overriding the global "line_table" within a selftest, 155 /* A class for overriding the global "line_table" within a selftest,
155 restoring its value afterwards. At most one instance of this 156 restoring its value afterwards. At most one instance of this
156 class can exist at once, due to the need to keep the old value 157 class can exist at once, due to the need to keep the old value
157 of line_table as a GC root. */ 158 of line_table as a GC root. */
168 169
169 /* Destructor. Restore the saved line_table. */ 170 /* Destructor. Restore the saved line_table. */
170 ~line_table_test (); 171 ~line_table_test ();
171 }; 172 };
172 173
174 /* Helper function for selftests that need a function decl. */
175
176 extern tree make_fndecl (tree return_type,
177 const char *name,
178 vec <tree> &param_types,
179 bool is_variadic = false);
180
173 /* Run TESTCASE multiple times, once for each case in our test matrix. */ 181 /* Run TESTCASE multiple times, once for each case in our test matrix. */
174 182
175 extern void 183 extern void
176 for_each_line_table_case (void (*testcase) (const line_table_case &)); 184 for_each_line_table_case (void (*testcase) (const line_table_case &));
177 185
213 221
214 /* Declarations for specific families of tests (by source file), in 222 /* Declarations for specific families of tests (by source file), in
215 alphabetical order. */ 223 alphabetical order. */
216 extern void attribute_c_tests (); 224 extern void attribute_c_tests ();
217 extern void bitmap_c_tests (); 225 extern void bitmap_c_tests ();
226 extern void cgraph_c_tests ();
227 extern void convert_c_tests ();
218 extern void diagnostic_c_tests (); 228 extern void diagnostic_c_tests ();
229 extern void diagnostic_format_json_cc_tests ();
219 extern void diagnostic_show_locus_c_tests (); 230 extern void diagnostic_show_locus_c_tests ();
231 extern void digraph_cc_tests ();
220 extern void dumpfile_c_tests (); 232 extern void dumpfile_c_tests ();
221 extern void edit_context_c_tests (); 233 extern void edit_context_c_tests ();
222 extern void et_forest_c_tests (); 234 extern void et_forest_c_tests ();
223 extern void fibonacci_heap_c_tests (); 235 extern void fibonacci_heap_c_tests ();
224 extern void fold_const_c_tests (); 236 extern void fold_const_c_tests ();
229 extern void hash_set_tests_c_tests (); 241 extern void hash_set_tests_c_tests ();
230 extern void input_c_tests (); 242 extern void input_c_tests ();
231 extern void json_cc_tests (); 243 extern void json_cc_tests ();
232 extern void opt_problem_cc_tests (); 244 extern void opt_problem_cc_tests ();
233 extern void optinfo_emit_json_cc_tests (); 245 extern void optinfo_emit_json_cc_tests ();
246 extern void ordered_hash_map_tests_cc_tests ();
234 extern void predict_c_tests (); 247 extern void predict_c_tests ();
235 extern void pretty_print_c_tests (); 248 extern void pretty_print_c_tests ();
249 extern void range_tests ();
236 extern void read_rtl_function_c_tests (); 250 extern void read_rtl_function_c_tests ();
237 extern void rtl_tests_c_tests (); 251 extern void rtl_tests_c_tests ();
238 extern void sbitmap_c_tests (); 252 extern void sbitmap_c_tests ();
239 extern void selftest_c_tests (); 253 extern void selftest_c_tests ();
240 extern void simplify_rtx_c_tests (); 254 extern void simplify_rtx_c_tests ();
242 extern void spellcheck_tree_c_tests (); 256 extern void spellcheck_tree_c_tests ();
243 extern void sreal_c_tests (); 257 extern void sreal_c_tests ();
244 extern void store_merging_c_tests (); 258 extern void store_merging_c_tests ();
245 extern void tree_c_tests (); 259 extern void tree_c_tests ();
246 extern void tree_cfg_c_tests (); 260 extern void tree_cfg_c_tests ();
261 extern void tree_diagnostic_path_cc_tests ();
262 extern void tristate_cc_tests ();
247 extern void typed_splay_tree_c_tests (); 263 extern void typed_splay_tree_c_tests ();
248 extern void unique_ptr_tests_cc_tests (); 264 extern void unique_ptr_tests_cc_tests ();
249 extern void vec_c_tests (); 265 extern void vec_c_tests ();
250 extern void vec_perm_indices_c_tests (); 266 extern void vec_perm_indices_c_tests ();
251 extern void wide_int_cc_tests (); 267 extern void wide_int_cc_tests ();
252 extern void opt_proposer_c_tests (); 268 extern void opt_proposer_c_tests ();
269 extern void dbgcnt_c_tests ();
253 270
254 extern int num_passes; 271 extern int num_passes;
255 272
256 } /* end of namespace selftest. */ 273 } /* end of namespace selftest. */
257 274
433 SELFTEST_BEGIN_STMT \ 450 SELFTEST_BEGIN_STMT \
434 ::selftest::assert_str_contains (SELFTEST_LOCATION, #HAYSTACK, #NEEDLE, \ 451 ::selftest::assert_str_contains (SELFTEST_LOCATION, #HAYSTACK, #NEEDLE, \
435 (HAYSTACK), (NEEDLE)); \ 452 (HAYSTACK), (NEEDLE)); \
436 SELFTEST_END_STMT 453 SELFTEST_END_STMT
437 454
455 /* Like ASSERT_STR_CONTAINS, but treat LOC as the effective location of the
456 selftest. */
457
458 #define ASSERT_STR_CONTAINS_AT(LOC, HAYSTACK, NEEDLE) \
459 SELFTEST_BEGIN_STMT \
460 ::selftest::assert_str_contains (LOC, #HAYSTACK, #NEEDLE, \
461 (HAYSTACK), (NEEDLE)); \
462 SELFTEST_END_STMT
463
438 /* Evaluate STR and PREFIX and determine if STR starts with PREFIX. 464 /* Evaluate STR and PREFIX and determine if STR starts with PREFIX.
439 ::selftest::pass if STR does start with PREFIX. 465 ::selftest::pass if STR does start with PREFIX.
440 ::selftest::fail if does not, or either is NULL. */ 466 ::selftest::fail if does not, or either is NULL. */
441 467
442 #define ASSERT_STR_STARTSWITH(STR, PREFIX) \ 468 #define ASSERT_STR_STARTSWITH(STR, PREFIX) \