]>
Commit | Line | Data |
---|---|---|
c63539ff ML |
1 | .. |
2 | Copyright 1988-2022 Free Software Foundation, Inc. | |
3 | This is part of the GCC manual. | |
4 | For copying conditions, see the copyright.rst file. | |
5 | ||
6 | .. _final-actions: | |
7 | ||
8 | Commands for use in dg-final | |
9 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
10 | ||
11 | The GCC testsuite defines the following directives to be used within | |
12 | ``dg-final``. | |
13 | ||
14 | Scan a particular file | |
15 | ~~~~~~~~~~~~~~~~~~~~~~ | |
16 | ||
17 | :samp:`scan-file {filename}{regexp} [{ target/xfail {selector} }]` | |
18 | Passes if :samp:`{regexp}` matches text in :samp:`{filename}`. | |
19 | ||
20 | :samp:`scan-file-not {filename}{regexp} [{ target/xfail {selector} }]` | |
21 | Passes if :samp:`{regexp}` does not match text in :samp:`{filename}`. | |
22 | ||
23 | :samp:`scan-module {module}{regexp} [{ target/xfail {selector} }]` | |
24 | Passes if :samp:`{regexp}` matches in Fortran module :samp:`{module}`. | |
25 | ||
26 | :samp:`dg-check-dot {filename}` | |
27 | Passes if :samp:`{filename}` is a valid :samp:`.dot` file (by running | |
28 | ``dot -Tpng`` on it, and verifying the exit code is 0). | |
29 | ||
30 | :samp:`scan-sarif-file {regexp} [{ target/xfail {selector} }]` | |
31 | Passes if :samp:`{regexp}` matches text in the file generated by | |
32 | :option:`-fdiagnostics-format=sarif-file`. | |
33 | ||
34 | :samp:`scan-sarif-file-not {regexp} [{ target/xfail {selector} }]` | |
35 | Passes if :samp:`{regexp}` does not match text in the file generated by | |
36 | :option:`-fdiagnostics-format=sarif-file`. | |
37 | ||
38 | Scan the assembly output | |
39 | ~~~~~~~~~~~~~~~~~~~~~~~~ | |
40 | ||
41 | :samp:`scan-assembler {regex} [{ target/xfail {selector} }]` | |
42 | Passes if :samp:`{regex}` matches text in the test's assembler output. | |
43 | ||
44 | :samp:`scan-assembler-not {regex} [{ target/xfail {selector} }]` | |
45 | Passes if :samp:`{regex}` does not match text in the test's assembler output. | |
46 | ||
47 | :samp:`scan-assembler-times {regex}{num} [{ target/xfail {selector} }]` | |
48 | Passes if :samp:`{regex}` is matched exactly :samp:`{num}` times in the test's | |
49 | assembler output. | |
50 | ||
51 | :samp:`scan-assembler-dem {regex} [{ target/xfail {selector} }]` | |
52 | Passes if :samp:`{regex}` matches text in the test's demangled assembler output. | |
53 | ||
54 | :samp:`scan-assembler-dem-not {regex} [{ target/xfail {selector} }]` | |
55 | Passes if :samp:`{regex}` does not match text in the test's demangled assembler | |
56 | output. | |
57 | ||
58 | :samp:`scan-assembler-symbol-section {functions}{section} [{ target/xfail {selector} }]` | |
59 | Passes if :samp:`{functions}` are all in :samp:`{section}`. The caller needs to | |
60 | allow for ``USER_LABEL_PREFIX`` and different section name conventions. | |
61 | ||
62 | :samp:`scan-symbol-section {filename}{functions}{section} [{ target/xfail {selector} }]` | |
63 | Passes if :samp:`{functions}` are all in :samp:`{section}` in :samp:`{filename}`. | |
64 | The same caveats as for ``scan-assembler-symbol-section`` apply. | |
65 | ||
66 | :samp:`scan-hidden {symbol} [{ target/xfail {selector} }]` | |
67 | Passes if :samp:`{symbol}` is defined as a hidden symbol in the test's | |
68 | assembly output. | |
69 | ||
70 | :samp:`scan-not-hidden {symbol} [{ target/xfail {selector} }]` | |
71 | Passes if :samp:`{symbol}` is not defined as a hidden symbol in the test's | |
72 | assembly output. | |
73 | ||
74 | :samp:`check-function-bodies {prefix}{terminator} [{options} [{ target/xfail {selector} }]]` | |
75 | Looks through the source file for comments that give the expected assembly | |
76 | output for selected functions. Each line of expected output starts with the | |
77 | prefix string :samp:`{prefix}` and the expected output for a function as a whole | |
78 | is followed by a line that starts with the string :samp:`{terminator}`. | |
79 | Specifying an empty terminator is equivalent to specifying :samp:`"*/"`. | |
80 | ||
81 | :samp:`{options}`, if specified, is a list of regular expressions, each of | |
82 | which matches a full command-line option. A non-empty list prevents | |
83 | the test from running unless all of the given options are present on the | |
84 | command line. This can help if a source file is compiled both with | |
85 | and without optimization, since it is rarely useful to check the full | |
86 | function body for unoptimized code. | |
87 | ||
88 | The first line of the expected output for a function :samp:`{fn}` has the form: | |
89 | ||
90 | .. code-block:: c++ | |
91 | ||
92 | prefix fn: [{ target/xfail selector }] | |
93 | ||
94 | Subsequent lines of the expected output also start with :samp:`{prefix}`. | |
95 | In both cases, whitespace after :samp:`{prefix}` is not significant. | |
96 | ||
97 | The test discards assembly directives such as ``.cfi_startproc`` | |
98 | and local label definitions such as ``.LFB0`` from the compiler's | |
99 | assembly output. It then matches the result against the expected | |
100 | output for a function as a single regular expression. This means that | |
101 | later lines can use backslashes to refer back to :samp:`(...)` | |
102 | captures on earlier lines. For example: | |
103 | ||
104 | .. code-block:: c++ | |
105 | ||
106 | /* { dg-final { check-function-bodies "**" "" "-DCHECK_ASM" } } */ | |
107 | ... | |
108 | /* | |
109 | ** add_w0_s8_m: | |
110 | ** mov (z[0-9]+\.b), w0 | |
111 | ** add z0\.b, p0/m, z0\.b, \1 | |
112 | ** ret | |
113 | */ | |
114 | svint8_t add_w0_s8_m (...) { ... } | |
115 | ... | |
116 | /* | |
117 | ** add_b0_s8_m: | |
118 | ** mov (z[0-9]+\.b), b0 | |
119 | ** add z1\.b, p0/m, z1\.b, \1 | |
120 | ** ret | |
121 | */ | |
122 | svint8_t add_b0_s8_m (...) { ... } | |
123 | ||
124 | checks whether the implementations of ``add_w0_s8_m`` and | |
125 | ``add_b0_s8_m`` match the regular expressions given. The test only | |
126 | runs when :samp:`-DCHECK_ASM` is passed on the command line. | |
127 | ||
128 | It is possible to create non-capturing multi-line regular expression | |
129 | groups of the form :samp:`({a}|{b}|...)` by putting the | |
130 | :samp:`(`, :samp:`|` and :samp:`)` on separate lines (each still using | |
131 | :samp:`{prefix}`). For example: | |
132 | ||
133 | .. code-block:: c++ | |
134 | ||
135 | /* | |
136 | ** cmple_f16_tied: | |
137 | ** ( | |
138 | ** fcmge p0\.h, p0/z, z1\.h, z0\.h | |
139 | ** | | |
140 | ** fcmle p0\.h, p0/z, z0\.h, z1\.h | |
141 | ** ) | |
142 | ** ret | |
143 | */ | |
144 | svbool_t cmple_f16_tied (...) { ... } | |
145 | ||
146 | checks whether ``cmple_f16_tied`` is implemented by the | |
147 | ``fcmge`` instruction followed by ``ret`` or by the | |
148 | ``fcmle`` instruction followed by ``ret``. The test is | |
149 | still a single regular rexpression. | |
150 | ||
151 | A line containing just: | |
152 | ||
153 | .. code-block:: c++ | |
154 | ||
155 | prefix ... | |
156 | ||
157 | stands for zero or more unmatched lines; the whitespace after | |
158 | :samp:`{prefix}` is again not significant. | |
159 | ||
160 | Scan optimization dump files | |
161 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
162 | ||
163 | These commands are available for :samp:`{kind}` of ``tree``, ``ltrans-tree``, | |
164 | ``offload-tree``, ``rtl``, ``offload-rtl``, ``ipa``, and | |
165 | ``wpa-ipa``. | |
166 | ||
167 | :samp:`scan-{kind}-dump {regex}{suffix} [{ target/xfail {selector} }]` | |
168 | Passes if :samp:`{regex}` matches text in the dump file with suffix :samp:`{suffix}`. | |
169 | ||
170 | :samp:`scan-{kind}-dump-not {regex}{suffix} [{ target/xfail {selector} }]` | |
171 | Passes if :samp:`{regex}` does not match text in the dump file with suffix | |
172 | :samp:`{suffix}`. | |
173 | ||
174 | :samp:`scan-{kind}-dump-times {regex}{num}{suffix} [{ target/xfail {selector} }]` | |
175 | Passes if :samp:`{regex}` is found exactly :samp:`{num}` times in the dump file | |
176 | with suffix :samp:`{suffix}`. | |
177 | ||
178 | :samp:`scan-{kind}-dump-dem {regex}{suffix} [{ target/xfail {selector} }]` | |
179 | Passes if :samp:`{regex}` matches demangled text in the dump file with | |
180 | suffix :samp:`{suffix}`. | |
181 | ||
182 | :samp:`scan-{kind}-dump-dem-not {regex}{suffix} [{ target/xfail {selector} }]` | |
183 | Passes if :samp:`{regex}` does not match demangled text in the dump file with | |
184 | suffix :samp:`{suffix}`. | |
185 | ||
186 | The :samp:`{suffix}` argument which describes the dump file to be scanned | |
187 | may contain a glob pattern that must expand to exactly one file | |
188 | name. This is useful if, e.g., different pass instances are executed | |
189 | depending on torture testing command-line flags, producing dump files | |
190 | whose names differ only in their pass instance number suffix. For | |
191 | example, to scan instances 1, 2, 3 of a tree pass 'mypass' for | |
192 | occurrences of the string 'code has been optimized', use: | |
193 | ||
194 | .. code-block:: c++ | |
195 | ||
196 | /* { dg-options "-fdump-tree-mypass" } */ | |
197 | /* { dg-final { scan-tree-dump "code has been optimized" "mypass\[1-3\]" } } */ | |
198 | ||
199 | Check for output files | |
200 | ~~~~~~~~~~~~~~~~~~~~~~ | |
201 | ||
202 | :samp:`output-exists [{ target/xfail {selector} }]` | |
203 | Passes if compiler output file exists. | |
204 | ||
205 | :samp:`output-exists-not [{ target/xfail {selector} }]` | |
206 | Passes if compiler output file does not exist. | |
207 | ||
208 | :samp:`scan-symbol {regexp} [{ target/xfail {selector} }]` | |
209 | Passes if the pattern is present in the final executable. | |
210 | ||
211 | :samp:`scan-symbol-not {regexp} [{ target/xfail {selector} }]` | |
212 | Passes if the pattern is absent from the final executable. | |
213 | ||
214 | Checks for gcov tests | |
215 | ~~~~~~~~~~~~~~~~~~~~~ | |
216 | ||
217 | :samp:`run-gcov {sourcefile}` | |
218 | Check line counts in :command:`gcov` tests. | |
219 | ||
220 | :samp:`run-gcov [branches] [calls] { {opts}{sourcefile} }` | |
221 | Check branch and/or call counts, in addition to line counts, in | |
222 | :command:`gcov` tests. | |
223 | ||
224 | :samp:`run-gcov-pytest { {sourcefile}{pytest_file} }` | |
225 | Check output of :command:`gcov` intermediate format with a pytest | |
226 | script. | |
227 | ||
228 | Clean up generated test files | |
229 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
230 | ||
231 | Usually the test-framework removes files that were generated during | |
232 | testing. If a testcase, for example, uses any dumping mechanism to | |
233 | inspect a passes dump file, the testsuite recognized the dump option | |
234 | passed to the tool and schedules a final cleanup to remove these files. | |
235 | ||
236 | There are, however, following additional cleanup directives that can be | |
237 | used to annotate a testcase "manually". | |
238 | ||
239 | ``cleanup-coverage-files`` | |
240 | Removes coverage data files generated for this test. | |
241 | ||
242 | :samp:`cleanup-modules "{list-of-extra-modules}"` | |
243 | Removes Fortran module files generated for this test, excluding the | |
244 | module names listed in keep-modules. | |
245 | Cleaning up module files is usually done automatically by the testsuite | |
246 | by looking at the source files and removing the modules after the test | |
247 | has been executed. | |
248 | ||
249 | .. code-block:: c++ | |
250 | ||
251 | module MoD1 | |
252 | end module MoD1 | |
253 | module Mod2 | |
254 | end module Mod2 | |
255 | module moD3 | |
256 | end module moD3 | |
257 | module mod4 | |
258 | end module mod4 | |
259 | ! { dg-final { cleanup-modules "mod1 mod2" } } ! redundant | |
260 | ! { dg-final { keep-modules "mod3 mod4" } } | |
261 | ||
262 | :samp:`keep-modules "{list-of-modules-not-to-delete}"` | |
263 | Whitespace separated list of module names that should not be deleted by | |
264 | cleanup-modules. | |
265 | If the list of modules is empty, all modules defined in this file are kept. | |
266 | ||
267 | .. code-block:: c++ | |
268 | ||
269 | module maybe_unneeded | |
270 | end module maybe_unneeded | |
271 | module keep1 | |
272 | end module keep1 | |
273 | module keep2 | |
274 | end module keep2 | |
275 | ! { dg-final { keep-modules "keep1 keep2" } } ! just keep these two | |
276 | ! { dg-final { keep-modules "" } } ! keep all | |
277 | ||
278 | :samp:`dg-keep-saved-temps "{list-of-suffixes-not-to-delete}"` | |
279 | Whitespace separated list of suffixes that should not be deleted | |
280 | automatically in a testcase that uses :option:`-save-temps`. | |
281 | ||
282 | .. code-block:: c++ | |
283 | ||
284 | // { dg-options "-save-temps -fpch-preprocess -I." } | |
285 | int main() { return 0; } | |
286 | // { dg-keep-saved-temps ".s" } ! just keep assembler file | |
287 | // { dg-keep-saved-temps ".s" ".i" } ! ... and .i | |
288 | // { dg-keep-saved-temps ".ii" ".o" } ! or just .ii and .o | |
289 | ||
290 | ``cleanup-profile-file`` | |
3ed1b4ce | 291 | Removes profiling files generated for this test. |