Mercurial > hg > CbC > CbC_gcc
comparison gcc/selftest.h @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 /* A self-testing framework, for use by -fself-test. | 1 /* A self-testing framework, for use by -fself-test. |
2 Copyright (C) 2015-2017 Free Software Foundation, Inc. | 2 Copyright (C) 2015-2018 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 |
65 ATTRIBUTE_PRINTF_2 ATTRIBUTE_NORETURN; | 65 ATTRIBUTE_PRINTF_2 ATTRIBUTE_NORETURN; |
66 | 66 |
67 /* Implementation detail of ASSERT_STREQ. */ | 67 /* Implementation detail of ASSERT_STREQ. */ |
68 | 68 |
69 extern void assert_streq (const location &loc, | 69 extern void assert_streq (const location &loc, |
70 const char *desc_expected, const char *desc_actual, | 70 const char *desc_val1, const char *desc_val2, |
71 const char *val_expected, const char *val_actual); | 71 const char *val1, const char *val2); |
72 | 72 |
73 /* Implementation detail of ASSERT_STR_CONTAINS. */ | 73 /* Implementation detail of ASSERT_STR_CONTAINS. */ |
74 | 74 |
75 extern void assert_str_contains (const location &loc, | 75 extern void assert_str_contains (const location &loc, |
76 const char *desc_haystack, | 76 const char *desc_haystack, |
77 const char *desc_needle, | 77 const char *desc_needle, |
78 const char *val_haystack, | 78 const char *val_haystack, |
79 const char *val_needle); | 79 const char *val_needle); |
80 | 80 |
81 /* Implementation detail of ASSERT_STR_STARTSWITH. */ | |
82 | |
83 extern void assert_str_startswith (const location &loc, | |
84 const char *desc_str, | |
85 const char *desc_prefix, | |
86 const char *val_str, | |
87 const char *val_prefix); | |
88 | |
89 | |
81 /* A named temporary file for use in selftests. | 90 /* A named temporary file for use in selftests. |
82 Usable for writing out files, and as the base class for | 91 Usable for writing out files, and as the base class for |
83 temp_source_file. | 92 temp_source_file. |
84 The file is unlinked in the destructor. */ | 93 The file is unlinked in the destructor. */ |
85 | 94 |
100 class temp_source_file : public named_temp_file | 109 class temp_source_file : public named_temp_file |
101 { | 110 { |
102 public: | 111 public: |
103 temp_source_file (const location &loc, const char *suffix, | 112 temp_source_file (const location &loc, const char *suffix, |
104 const char *content); | 113 const char *content); |
114 }; | |
115 | |
116 /* RAII-style class for avoiding introducing locale-specific differences | |
117 in strings containing localized quote marks, by temporarily overriding | |
118 the "open_quote" and "close_quote" globals to something hardcoded. | |
119 | |
120 Specifically, the C locale's values are used: | |
121 - open_quote becomes "`" | |
122 - close_quote becomes "'" | |
123 for the lifetime of the object. */ | |
124 | |
125 class auto_fix_quotes | |
126 { | |
127 public: | |
128 auto_fix_quotes (); | |
129 ~auto_fix_quotes (); | |
130 | |
131 private: | |
132 const char *m_saved_open_quote; | |
133 const char *m_saved_close_quote; | |
105 }; | 134 }; |
106 | 135 |
107 /* Various selftests involving location-handling require constructing a | 136 /* Various selftests involving location-handling require constructing a |
108 line table and one or more line maps within it. | 137 line table and one or more line maps within it. |
109 | 138 |
166 | 195 |
167 /* The path of SRCDIR/testsuite/selftests. */ | 196 /* The path of SRCDIR/testsuite/selftests. */ |
168 | 197 |
169 extern const char *path_to_selftest_files; | 198 extern const char *path_to_selftest_files; |
170 | 199 |
200 /* selftest::test_runner is an implementation detail of selftest::run_tests, | |
201 exposed here to allow plugins to run their own suites of tests. */ | |
202 | |
203 class test_runner | |
204 { | |
205 public: | |
206 test_runner (const char *name); | |
207 ~test_runner (); | |
208 | |
209 private: | |
210 const char *m_name; | |
211 long m_start_time; | |
212 }; | |
213 | |
171 /* Declarations for specific families of tests (by source file), in | 214 /* Declarations for specific families of tests (by source file), in |
172 alphabetical order. */ | 215 alphabetical order. */ |
216 extern void attribute_c_tests (); | |
173 extern void bitmap_c_tests (); | 217 extern void bitmap_c_tests (); |
174 extern void sbitmap_c_tests (); | |
175 extern void diagnostic_c_tests (); | 218 extern void diagnostic_c_tests (); |
176 extern void diagnostic_show_locus_c_tests (); | 219 extern void diagnostic_show_locus_c_tests (); |
220 extern void dumpfile_c_tests (); | |
177 extern void edit_context_c_tests (); | 221 extern void edit_context_c_tests (); |
178 extern void et_forest_c_tests (); | 222 extern void et_forest_c_tests (); |
223 extern void fibonacci_heap_c_tests (); | |
179 extern void fold_const_c_tests (); | 224 extern void fold_const_c_tests (); |
180 extern void fibonacci_heap_c_tests (); | |
181 extern void function_tests_c_tests (); | 225 extern void function_tests_c_tests (); |
226 extern void ggc_tests_c_tests (); | |
182 extern void gimple_c_tests (); | 227 extern void gimple_c_tests (); |
183 extern void ggc_tests_c_tests (); | |
184 extern void hash_map_tests_c_tests (); | 228 extern void hash_map_tests_c_tests (); |
185 extern void hash_set_tests_c_tests (); | 229 extern void hash_set_tests_c_tests (); |
186 extern void input_c_tests (); | 230 extern void input_c_tests (); |
231 extern void json_cc_tests (); | |
232 extern void opt_problem_cc_tests (); | |
233 extern void optinfo_emit_json_cc_tests (); | |
234 extern void predict_c_tests (); | |
187 extern void pretty_print_c_tests (); | 235 extern void pretty_print_c_tests (); |
188 extern void read_rtl_function_c_tests (); | 236 extern void read_rtl_function_c_tests (); |
189 extern void rtl_tests_c_tests (); | 237 extern void rtl_tests_c_tests (); |
238 extern void sbitmap_c_tests (); | |
190 extern void selftest_c_tests (); | 239 extern void selftest_c_tests (); |
240 extern void simplify_rtx_c_tests (); | |
191 extern void spellcheck_c_tests (); | 241 extern void spellcheck_c_tests (); |
192 extern void spellcheck_tree_c_tests (); | 242 extern void spellcheck_tree_c_tests (); |
193 extern void sreal_c_tests (); | 243 extern void sreal_c_tests (); |
194 extern void store_merging_c_tests (); | 244 extern void store_merging_c_tests (); |
195 extern void typed_splay_tree_c_tests (); | |
196 extern void tree_c_tests (); | 245 extern void tree_c_tests (); |
197 extern void tree_cfg_c_tests (); | 246 extern void tree_cfg_c_tests (); |
247 extern void typed_splay_tree_c_tests (); | |
198 extern void unique_ptr_tests_cc_tests (); | 248 extern void unique_ptr_tests_cc_tests (); |
199 extern void vec_c_tests (); | 249 extern void vec_c_tests (); |
250 extern void vec_perm_indices_c_tests (); | |
200 extern void wide_int_cc_tests (); | 251 extern void wide_int_cc_tests (); |
201 extern void predict_c_tests (); | 252 extern void opt_proposer_c_tests (); |
202 | 253 |
203 extern int num_passes; | 254 extern int num_passes; |
204 | 255 |
205 } /* end of namespace selftest. */ | 256 } /* end of namespace selftest. */ |
206 | 257 |
216 /* Like ASSERT_TRUE, but treat LOC as the effective location of the | 267 /* Like ASSERT_TRUE, but treat LOC as the effective location of the |
217 selftest. */ | 268 selftest. */ |
218 | 269 |
219 #define ASSERT_TRUE_AT(LOC, EXPR) \ | 270 #define ASSERT_TRUE_AT(LOC, EXPR) \ |
220 SELFTEST_BEGIN_STMT \ | 271 SELFTEST_BEGIN_STMT \ |
221 const char *desc = "ASSERT_TRUE (" #EXPR ")"; \ | 272 const char *desc_ = "ASSERT_TRUE (" #EXPR ")"; \ |
222 bool actual = (EXPR); \ | 273 bool actual_ = (EXPR); \ |
223 if (actual) \ | 274 if (actual_) \ |
224 ::selftest::pass ((LOC), desc); \ | 275 ::selftest::pass ((LOC), desc_); \ |
225 else \ | 276 else \ |
226 ::selftest::fail ((LOC), desc); \ | 277 ::selftest::fail ((LOC), desc_); \ |
227 SELFTEST_END_STMT | 278 SELFTEST_END_STMT |
228 | 279 |
229 /* Evaluate EXPR and coerce to bool, calling | 280 /* Evaluate EXPR and coerce to bool, calling |
230 ::selftest::pass if it is false, | 281 ::selftest::pass if it is false, |
231 ::selftest::fail if it true. */ | 282 ::selftest::fail if it true. */ |
236 /* Like ASSERT_FALSE, but treat LOC as the effective location of the | 287 /* Like ASSERT_FALSE, but treat LOC as the effective location of the |
237 selftest. */ | 288 selftest. */ |
238 | 289 |
239 #define ASSERT_FALSE_AT(LOC, EXPR) \ | 290 #define ASSERT_FALSE_AT(LOC, EXPR) \ |
240 SELFTEST_BEGIN_STMT \ | 291 SELFTEST_BEGIN_STMT \ |
241 const char *desc = "ASSERT_FALSE (" #EXPR ")"; \ | 292 const char *desc_ = "ASSERT_FALSE (" #EXPR ")"; \ |
242 bool actual = (EXPR); \ | 293 bool actual_ = (EXPR); \ |
243 if (actual) \ | 294 if (actual_) \ |
244 ::selftest::fail ((LOC), desc); \ | 295 ::selftest::fail ((LOC), desc_); \ |
245 else \ | 296 else \ |
246 ::selftest::pass ((LOC), desc); \ | 297 ::selftest::pass ((LOC), desc_); \ |
247 SELFTEST_END_STMT | 298 SELFTEST_END_STMT |
248 | 299 |
249 /* Evaluate EXPECTED and ACTUAL and compare them with ==, calling | 300 /* Evaluate VAL1 and VAL2 and compare them with ==, calling |
250 ::selftest::pass if they are equal, | 301 ::selftest::pass if they are equal, |
251 ::selftest::fail if they are non-equal. */ | 302 ::selftest::fail if they are non-equal. */ |
252 | 303 |
253 #define ASSERT_EQ(EXPECTED, ACTUAL) \ | 304 #define ASSERT_EQ(VAL1, VAL2) \ |
254 ASSERT_EQ_AT ((SELFTEST_LOCATION), (EXPECTED), (ACTUAL)) | 305 ASSERT_EQ_AT ((SELFTEST_LOCATION), (VAL1), (VAL2)) |
255 | 306 |
256 /* Like ASSERT_EQ, but treat LOC as the effective location of the | 307 /* Like ASSERT_EQ, but treat LOC as the effective location of the |
257 selftest. */ | 308 selftest. */ |
258 | 309 |
259 #define ASSERT_EQ_AT(LOC, EXPECTED, ACTUAL) \ | 310 #define ASSERT_EQ_AT(LOC, VAL1, VAL2) \ |
260 SELFTEST_BEGIN_STMT \ | 311 SELFTEST_BEGIN_STMT \ |
261 const char *desc = "ASSERT_EQ (" #EXPECTED ", " #ACTUAL ")"; \ | 312 const char *desc_ = "ASSERT_EQ (" #VAL1 ", " #VAL2 ")"; \ |
262 if ((EXPECTED) == (ACTUAL)) \ | 313 if ((VAL1) == (VAL2)) \ |
263 ::selftest::pass ((LOC), desc); \ | 314 ::selftest::pass ((LOC), desc_); \ |
264 else \ | 315 else \ |
265 ::selftest::fail ((LOC), desc); \ | 316 ::selftest::fail ((LOC), desc_); \ |
266 SELFTEST_END_STMT | 317 SELFTEST_END_STMT |
267 | 318 |
268 /* Evaluate EXPECTED and ACTUAL and compare them with !=, calling | 319 /* Evaluate VAL1 and VAL2 and compare them with known_eq, calling |
320 ::selftest::pass if they are always equal, | |
321 ::selftest::fail if they might be non-equal. */ | |
322 | |
323 #define ASSERT_KNOWN_EQ(VAL1, VAL2) \ | |
324 ASSERT_KNOWN_EQ_AT ((SELFTEST_LOCATION), (VAL1), (VAL2)) | |
325 | |
326 /* Like ASSERT_KNOWN_EQ, but treat LOC as the effective location of the | |
327 selftest. */ | |
328 | |
329 #define ASSERT_KNOWN_EQ_AT(LOC, VAL1, VAL2) \ | |
330 SELFTEST_BEGIN_STMT \ | |
331 const char *desc = "ASSERT_KNOWN_EQ (" #VAL1 ", " #VAL2 ")"; \ | |
332 if (known_eq (VAL1, VAL2)) \ | |
333 ::selftest::pass ((LOC), desc); \ | |
334 else \ | |
335 ::selftest::fail ((LOC), desc); \ | |
336 SELFTEST_END_STMT | |
337 | |
338 /* Evaluate VAL1 and VAL2 and compare them with !=, calling | |
269 ::selftest::pass if they are non-equal, | 339 ::selftest::pass if they are non-equal, |
270 ::selftest::fail if they are equal. */ | 340 ::selftest::fail if they are equal. */ |
271 | 341 |
272 #define ASSERT_NE(EXPECTED, ACTUAL) \ | 342 #define ASSERT_NE(VAL1, VAL2) \ |
273 SELFTEST_BEGIN_STMT \ | 343 SELFTEST_BEGIN_STMT \ |
274 const char *desc = "ASSERT_NE (" #EXPECTED ", " #ACTUAL ")"; \ | 344 const char *desc_ = "ASSERT_NE (" #VAL1 ", " #VAL2 ")"; \ |
275 if ((EXPECTED) != (ACTUAL)) \ | 345 if ((VAL1) != (VAL2)) \ |
276 ::selftest::pass (SELFTEST_LOCATION, desc); \ | 346 ::selftest::pass (SELFTEST_LOCATION, desc_); \ |
277 else \ | 347 else \ |
278 ::selftest::fail (SELFTEST_LOCATION, desc); \ | 348 ::selftest::fail (SELFTEST_LOCATION, desc_); \ |
279 SELFTEST_END_STMT | 349 SELFTEST_END_STMT |
280 | 350 |
281 /* Evaluate EXPECTED and ACTUAL and compare them with strcmp, calling | 351 /* Evaluate VAL1 and VAL2 and compare them with maybe_ne, calling |
282 ::selftest::pass if they are equal, | 352 ::selftest::pass if they might be non-equal, |
283 ::selftest::fail if they are non-equal. */ | 353 ::selftest::fail if they are known to be equal. */ |
284 | 354 |
285 #define ASSERT_STREQ(EXPECTED, ACTUAL) \ | 355 #define ASSERT_MAYBE_NE(VAL1, VAL2) \ |
356 ASSERT_MAYBE_NE_AT ((SELFTEST_LOCATION), (VAL1), (VAL2)) | |
357 | |
358 /* Like ASSERT_MAYBE_NE, but treat LOC as the effective location of the | |
359 selftest. */ | |
360 | |
361 #define ASSERT_MAYBE_NE_AT(LOC, VAL1, VAL2) \ | |
362 SELFTEST_BEGIN_STMT \ | |
363 const char *desc = "ASSERT_MAYBE_NE (" #VAL1 ", " #VAL2 ")"; \ | |
364 if (maybe_ne (VAL1, VAL2)) \ | |
365 ::selftest::pass ((LOC), desc); \ | |
366 else \ | |
367 ::selftest::fail ((LOC), desc); \ | |
368 SELFTEST_END_STMT | |
369 | |
370 /* Evaluate LHS and RHS and compare them with >, calling | |
371 ::selftest::pass if LHS > RHS, | |
372 ::selftest::fail otherwise. */ | |
373 | |
374 #define ASSERT_GT(LHS, RHS) \ | |
375 ASSERT_GT_AT ((SELFTEST_LOCATION), (LHS), (RHS)) | |
376 | |
377 /* Like ASSERT_GT, but treat LOC as the effective location of the | |
378 selftest. */ | |
379 | |
380 #define ASSERT_GT_AT(LOC, LHS, RHS) \ | |
381 SELFTEST_BEGIN_STMT \ | |
382 const char *desc_ = "ASSERT_GT (" #LHS ", " #RHS ")"; \ | |
383 if ((LHS) > (RHS)) \ | |
384 ::selftest::pass ((LOC), desc_); \ | |
385 else \ | |
386 ::selftest::fail ((LOC), desc_); \ | |
387 SELFTEST_END_STMT | |
388 | |
389 /* Evaluate LHS and RHS and compare them with <, calling | |
390 ::selftest::pass if LHS < RHS, | |
391 ::selftest::fail otherwise. */ | |
392 | |
393 #define ASSERT_LT(LHS, RHS) \ | |
394 ASSERT_LT_AT ((SELFTEST_LOCATION), (LHS), (RHS)) | |
395 | |
396 /* Like ASSERT_LT, but treat LOC as the effective location of the | |
397 selftest. */ | |
398 | |
399 #define ASSERT_LT_AT(LOC, LHS, RHS) \ | |
400 SELFTEST_BEGIN_STMT \ | |
401 const char *desc_ = "ASSERT_LT (" #LHS ", " #RHS ")"; \ | |
402 if ((LHS) < (RHS)) \ | |
403 ::selftest::pass ((LOC), desc_); \ | |
404 else \ | |
405 ::selftest::fail ((LOC), desc_); \ | |
406 SELFTEST_END_STMT | |
407 | |
408 /* Evaluate VAL1 and VAL2 and compare them with strcmp, calling | |
409 ::selftest::pass if they are equal (and both are non-NULL), | |
410 ::selftest::fail if they are non-equal, or are both NULL. */ | |
411 | |
412 #define ASSERT_STREQ(VAL1, VAL2) \ | |
286 SELFTEST_BEGIN_STMT \ | 413 SELFTEST_BEGIN_STMT \ |
287 ::selftest::assert_streq (SELFTEST_LOCATION, #EXPECTED, #ACTUAL, \ | 414 ::selftest::assert_streq (SELFTEST_LOCATION, #VAL1, #VAL2, \ |
288 (EXPECTED), (ACTUAL)); \ | 415 (VAL1), (VAL2)); \ |
289 SELFTEST_END_STMT | 416 SELFTEST_END_STMT |
290 | 417 |
291 /* Like ASSERT_STREQ, but treat LOC as the effective location of the | 418 /* Like ASSERT_STREQ, but treat LOC as the effective location of the |
292 selftest. */ | 419 selftest. */ |
293 | 420 |
294 #define ASSERT_STREQ_AT(LOC, EXPECTED, ACTUAL) \ | 421 #define ASSERT_STREQ_AT(LOC, VAL1, VAL2) \ |
295 SELFTEST_BEGIN_STMT \ | 422 SELFTEST_BEGIN_STMT \ |
296 ::selftest::assert_streq ((LOC), #EXPECTED, #ACTUAL, \ | 423 ::selftest::assert_streq ((LOC), #VAL1, #VAL2, \ |
297 (EXPECTED), (ACTUAL)); \ | 424 (VAL1), (VAL2)); \ |
298 SELFTEST_END_STMT | 425 SELFTEST_END_STMT |
299 | 426 |
300 /* Evaluate HAYSTACK and NEEDLE and use strstr to determine if NEEDLE | 427 /* Evaluate HAYSTACK and NEEDLE and use strstr to determine if NEEDLE |
301 is within HAYSTACK. | 428 is within HAYSTACK. |
302 ::selftest::pass if NEEDLE is found. | 429 ::selftest::pass if NEEDLE is found. |
306 SELFTEST_BEGIN_STMT \ | 433 SELFTEST_BEGIN_STMT \ |
307 ::selftest::assert_str_contains (SELFTEST_LOCATION, #HAYSTACK, #NEEDLE, \ | 434 ::selftest::assert_str_contains (SELFTEST_LOCATION, #HAYSTACK, #NEEDLE, \ |
308 (HAYSTACK), (NEEDLE)); \ | 435 (HAYSTACK), (NEEDLE)); \ |
309 SELFTEST_END_STMT | 436 SELFTEST_END_STMT |
310 | 437 |
438 /* Evaluate STR and PREFIX and determine if STR starts with PREFIX. | |
439 ::selftest::pass if STR does start with PREFIX. | |
440 ::selftest::fail if does not, or either is NULL. */ | |
441 | |
442 #define ASSERT_STR_STARTSWITH(STR, PREFIX) \ | |
443 SELFTEST_BEGIN_STMT \ | |
444 ::selftest::assert_str_startswith (SELFTEST_LOCATION, #STR, #PREFIX, \ | |
445 (STR), (PREFIX)); \ | |
446 SELFTEST_END_STMT | |
447 | |
311 /* Evaluate PRED1 (VAL1), calling ::selftest::pass if it is true, | 448 /* Evaluate PRED1 (VAL1), calling ::selftest::pass if it is true, |
312 ::selftest::fail if it is false. */ | 449 ::selftest::fail if it is false. */ |
313 | 450 |
314 #define ASSERT_PRED1(PRED1, VAL1) \ | 451 #define ASSERT_PRED1(PRED1, VAL1) \ |
315 SELFTEST_BEGIN_STMT \ | 452 SELFTEST_BEGIN_STMT \ |
316 const char *desc = "ASSERT_PRED1 (" #PRED1 ", " #VAL1 ")"; \ | 453 const char *desc_ = "ASSERT_PRED1 (" #PRED1 ", " #VAL1 ")"; \ |
317 bool actual = (PRED1) (VAL1); \ | 454 bool actual_ = (PRED1) (VAL1); \ |
318 if (actual) \ | 455 if (actual_) \ |
319 ::selftest::pass (SELFTEST_LOCATION, desc); \ | 456 ::selftest::pass (SELFTEST_LOCATION, desc_); \ |
320 else \ | 457 else \ |
321 ::selftest::fail (SELFTEST_LOCATION, desc); \ | 458 ::selftest::fail (SELFTEST_LOCATION, desc_); \ |
322 SELFTEST_END_STMT | 459 SELFTEST_END_STMT |
323 | 460 |
324 #define SELFTEST_BEGIN_STMT do { | 461 #define SELFTEST_BEGIN_STMT do { |
325 #define SELFTEST_END_STMT } while (0) | 462 #define SELFTEST_END_STMT } while (0) |
326 | 463 |