1 /* Implementation of selftests.
2    Copyright (C) 2015-2020 Free Software Foundation, Inc.
3 
4 This file is part of GCC.
5 
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
8 Software Foundation; either version 3, or (at your option) any later
9 version.
10 
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3.  If not see
18 <http://www.gnu.org/licenses/>.  */
19 
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "selftest.h"
24 #include "tree.h"
25 #include "target.h"
26 #include "langhooks.h"
27 #include "options.h"
28 #include "stringpool.h"
29 #include "attribs.h"
30 #include "analyzer/analyzer-selftests.h"
31 
32 /* This function needed to be split out from selftest.c as it references
33    tests from the whole source tree, and so is within
34    OBJS in Makefile.in, whereas selftest.o is within OBJS-libcommon.
35    This allows us to embed tests within files in OBJS-libcommon without
36    introducing a dependency on objects within OBJS.  */
37 
38 #if CHECKING_P
39 
40 /* Run all tests, aborting if any fail.  */
41 
42 void
run_tests()43 selftest::run_tests ()
44 {
45   /* Makefile.in has -fself-test=$(srcdir)/testsuite/selftests, so that
46      flag_self_test contains the path to the selftest subdirectory of the
47      source tree (without a trailing slash).  Copy it up to
48      path_to_selftest_files, to avoid selftest.c depending on
49      option-handling.  */
50   path_to_selftest_files = flag_self_test;
51 
52   test_runner r ("-fself-test");
53 
54   /* Run all the tests, in hand-coded order of (approximate) dependencies:
55      run the tests for lowest-level code first.  */
56 
57   /* Sanity-check for selftests themselves.  */
58   selftest_c_tests ();
59 
60   /* Low-level data structures.  */
61   bitmap_c_tests ();
62   sbitmap_c_tests ();
63   dumpfile_c_tests ();
64   et_forest_c_tests ();
65   hash_map_tests_c_tests ();
66   hash_set_tests_c_tests ();
67   vec_c_tests ();
68   pretty_print_c_tests ();
69   wide_int_cc_tests ();
70   ggc_tests_c_tests ();
71   sreal_c_tests ();
72   fibonacci_heap_c_tests ();
73   typed_splay_tree_c_tests ();
74   unique_ptr_tests_cc_tests ();
75   opt_proposer_c_tests ();
76   opts_c_tests ();
77   json_cc_tests ();
78   cgraph_c_tests ();
79   optinfo_emit_json_cc_tests ();
80   opt_problem_cc_tests ();
81   ordered_hash_map_tests_cc_tests ();
82 
83   /* Mid-level data structures.  */
84   input_c_tests ();
85   vec_perm_indices_c_tests ();
86   tree_c_tests ();
87   convert_c_tests ();
88   gimple_c_tests ();
89   rtl_tests_c_tests ();
90   read_rtl_function_c_tests ();
91   digraph_cc_tests ();
92   tristate_cc_tests ();
93 
94   /* Higher-level tests, or for components that other selftests don't
95      rely on.  */
96   diagnostic_show_locus_c_tests ();
97   diagnostic_c_tests ();
98   diagnostic_format_json_cc_tests ();
99   edit_context_c_tests ();
100   fold_const_c_tests ();
101   spellcheck_c_tests ();
102   spellcheck_tree_c_tests ();
103   tree_cfg_c_tests ();
104   tree_diagnostic_path_cc_tests ();
105   attribute_c_tests ();
106 
107   /* This one relies on most of the above.  */
108   function_tests_c_tests ();
109 
110   /* Run any target-specific selftests.  */
111   if (targetm.run_target_selftests)
112     targetm.run_target_selftests ();
113 
114   store_merging_c_tests ();
115   predict_c_tests ();
116   simplify_rtx_c_tests ();
117   dbgcnt_c_tests ();
118 
119   /* Run any lang-specific selftests.  */
120   lang_hooks.run_lang_selftests ();
121 
122   /* Run the analyzer selftests (if enabled).  */
123   ana::selftest::run_analyzer_selftests ();
124 
125   /* Force a GC at the end of the selftests, to shake out GC-related
126      issues.  For example, if any GC-managed items have buggy (or missing)
127      finalizers, this last collection will ensure that things that were
128      failed to be finalized can be detected by valgrind.  */
129   forcibly_ggc_collect ();
130 
131   /* Finished running tests; the test_runner dtor will print a summary.  */
132 }
133 
134 #endif /* #if CHECKING_P */
135