Skip to content

Commit 4cceb23

Browse files
authored
[Fortran/gfortran] Initial support to override DejaGNU annotations
The DejaGNU annotations in the gfortran test suite sometimes need to be overridden, for instance in cases where the one of the compilers generates a compile error for some non-standard extension while the other does not. This PR adds support to override the some annotations, such as forcing a test to pass with flang where it would fail in gfortran. For now, only some of the behavior can be overridden, but this could be extended in the future. The documentation was updated to reflect this (some cleanup of the documentation was also carried out). Similarly, the static test configuration generation script was updated and cleaned up. An override file is also provided for two tests that were disabled in 27a6a3a since they are expected to pass in flang. The static test configuration was also updated to reflect this change.
1 parent 87e97b5 commit 4cceb23

File tree

4 files changed

+329
-51
lines changed

4 files changed

+329
-51
lines changed

Fortran/gfortran/README.md

Lines changed: 172 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ behavior of the binary produced by the compiler.
1616
Currently, only the _execute_ tests are supported in `regression`. Both
1717
`compile` and `execute` tests have been enabled in `torture`.
1818

19-
Of the supported tests, a number of tests have been disabled. These are listed
19+
Of the supported tests, a number of tests have been disabled. These are listed
2020
in the `DisabledFiles.cmake` files that can be found in the various
2121
subdirectories of `Fortran/gfortran`. There are four
2222
categories of such tests:
@@ -35,12 +35,12 @@ features.
3535

3636
- *Failing*: These tests fail at test-time.
3737

38-
- For "execute" tests, some crash on execution, others produce
39-
incorrect/unexpected output. This could be a result of a bug in the
40-
compiler/code generator or the runtime.
38+
- For "execute" tests, some crash on execution, others produce
39+
incorrect/unexpected output. This could be a result of a bug in the
40+
compiler/code generator or the runtime.
4141

42-
- For "compile" tests, this could be because the compilation succeeds when it
43-
is expected to fail, or vice versa.
42+
- For "compile" tests, this could be because the compilation succeeds when it
43+
is expected to fail, or vice versa.
4444

4545
Over time, the number of tests in the *unimplemented*, *skipped*, and *failing*
4646
categories should decrease. Eventually, only the *unsupported* category should
@@ -116,7 +116,7 @@ are unrelated to the gfortran tests here.
116116

117117
Additional denylists for a particular feature can be included by creating
118118
`DisabledFiles_FEATURE.cmake` files (in the same format as those for the default
119-
denylists, `DisabledFiles.cmake`), and adding FEATURE to
119+
denylists, `DisabledFiles.cmake`), and adding FEATURE to
120120
`TEST_SUITE_FORTRAN_FEATURES`. Additional compiler flags can be added using
121121
`CMAKE_Fortran_FLAGS`.
122122

@@ -131,8 +131,8 @@ cmake -DTEST_SUITE_FORTRAN_FEATURES=FOO \
131131
`DisabledFiles_FOO.cmake` files can be created in the appropriate subdirectories
132132
if enabling the feature/flag results in the failure of tests that otherwise pass.
133133
Conversely, the feature/flag may cause some disabled tests to pass. These can be
134-
added to an allowlist file, `EnabledFiles_FOO.cmake` in the corresponding
135-
directory. The file must contain a single variable named `ENABLED_FILES` with
134+
added to an allowlist file, `EnabledFiles_FOO.cmake` in the corresponding
135+
directory. The file must contain a single variable named `ENABLED_FILES` with
136136
the file names of the tests that should be enabled (in the case of multi-file
137137
tests, this should be the name of the "main" file). An example of such a list is
138138
below.
@@ -152,8 +152,8 @@ implemented at a steady pace. The relevant tests in this directory should be
152152
enabled. This would involve building the test suite with one of the
153153
`TEST_SUITE_FORTRAN_*` flags described above.
154154

155-
The build system uses static test configuration files named `tests.cmake` to be
156-
found in the various subdirectories of the test suite. These are generated by
155+
The build system uses static test configuration files named `tests.cmake` to be
156+
found in the various subdirectories of the test suite. These are generated by
157157
`utils/update-test-config.py`. The configuration files are the result of parsing
158158
the relevant DejaGNU annotations from the test files and are used by the various
159159
`CMakeLists.txt` files to set up the tests. These configuration files *must not*
@@ -178,29 +178,169 @@ Each field is described in the table below:
178178
| `<disabled-on>`| A space-separated list of targets on which the test is disabled. Each element of the list will be a regular expression that is expected to match an LLVM target triple.
179179

180180
The test `kind`'s generally reflect what is being tested. For instance,
181-
`preprocess` tests only run the preprocessor, `assemble` tests generate assembly
181+
`preprocess` tests only run the preprocessor, `assemble` tests generate assembly
182182
but no object code, the `compile` tests generate object code but do not invoke
183183
the linker while the `link` tests do invoke the linker. The `run` tests are
184184
"end-to-end" in that the code is compiled, linked and executed. These tests
185185
generally examine the output of the execution to ensure that the behavior of the
186186
generated executable is as expected.
187187

188-
The test files should be kept in sync with gfortran. This has to be done
189-
manually. When performing this update, the test configuration files must be
188+
The test files should be kept in sync with gfortran. This has to be done
189+
manually. When performing this update, the test configuration files must be
190190
regenerated. This can be done by running `update-test-config.py` in the root of
191191
the test suite. The `-h` switch can be provided to the script for additional
192192
options.
193193

194194
The test files in `regression` and `torture` *must not* be modified.
195195

196+
### Overriding DejaGNU annotations ###
197+
198+
In some cases, it may be necessary to override the DejaGNU annotations. Some of
199+
these include:
200+
201+
- To invert the xfail status of a test (which is usually needed when there is
202+
a difference in behavior between gfortran and flang)
203+
204+
- To selectively enable/disable a test on a particular platform.
205+
206+
- In cases where a warning is expected, to override the gfortran-specific
207+
warning message with a flang-specific one.
208+
209+
For now, only limited forms of overriding are supported. In particular, we
210+
do not support overriding warning messages, but that might be supported in the
211+
future.
212+
213+
In order to override annotations for tests in a given directory, create a
214+
file named `override.yaml` in that directory. The format of the file is
215+
described below. After the file has been populated, the static test
216+
configuration files must be updated by running `update-test-config.py` as shown
217+
below. This will update all the `tests.cmake` files in the test suite.
218+
219+
```
220+
$ cd /path/to/llvm-test-suite/Fortran/gfortran
221+
$ ./utils/update-test-config.py
222+
```
223+
224+
#### override.yaml ####
225+
226+
The `override.yaml` file can only be used to override attributes of tests
227+
contained within the directory containing `override.yaml`. In order to override
228+
attributes of tests in subdirectories, an `override.yaml` file must be created
229+
in the subdirectory. This file only needs to be created if necessary. Unlike
230+
the `DisabledFiles.cmake` files, it does not need to be present if test
231+
attributes do not need to be overridden. At a high level, the format of the
232+
file is as follows:
233+
234+
```
235+
---
236+
"file1":
237+
attr-name-1: attr-val-1
238+
attr-name-2: attr-val-2
239+
...
240+
241+
"file2":
242+
attr-name-1: attr-val-2
243+
...
244+
245+
...
246+
247+
```
248+
249+
Here each "fileN" is the full file name (including the extension) of the test.
250+
In the case of multi-file tests, this must be the name of the main test file.
251+
This must not contain paths (relative or absolute).
252+
253+
The following attributes are currently supported.
254+
255+
#### `disabled_on` ###
256+
257+
The value must be a list of strings. Each string describes a platform on which
258+
the test must be disabled. This will usually be a target triple, and may be a
259+
regex.
260+
261+
This can be used to disable tests on platforms on which they have been
262+
explicitly enabled (this usually occurs when tests are restricted to run only
263+
on certain platforms). In such cases, the string that is used to specify the
264+
platform must exactly match the string that was used in a DejaGNU annotation.
265+
For instance, the test `regression/simd-builtins-1.f90` is explicitly enabled
266+
on certain Linux platforms only. This is done in the following annotation:
267+
268+
```
269+
! { dg-do compile { target i?86-*-linux* x86_64-*-linux* aarch64*-*-linux* } }
270+
```
271+
272+
In order to disable this test on AArch64-based Linux systems, the following
273+
should be added to `regression/override.yaml`:
274+
275+
```
276+
"simd_builtins-1.f90":
277+
disabled_on: ["aarch64*-*-linux*"]
278+
```
279+
280+
Note that the string in the `disabled_on` list exactly matches that in the
281+
DejaGNU annotation. If you are not sure which string to use, check the
282+
`enabled_on` column in the entry for the test in the static test configuration
283+
file, `tests.cmake`, which will be present in the directory containing the test.
284+
285+
If the `enabled_on` column for the test in `tests.cmake` is empty, the test is
286+
run on all platforms. In this case, overriding the `disabled_on` attribute is
287+
perfectly safe and will result in the test being executed on all platforms
288+
_except_ those in the `disabled_on list`.
289+
290+
*WARNING*: However, if any of the strings in the `disabled_on` list is the sole
291+
entry in the `enabled_on` column for the test in `tests.cmake`, the test will
292+
end up being enabled on _all_ platforms _except_ those in `disabled_on` list.
293+
This is a known issue. There is no timeline for a fix for this.
294+
295+
#### `enabled_on` ####
296+
297+
The value must be a list of strings. Each string describes a platform on which
298+
the test must be enabled. This will usually be a target triple, and may be a
299+
regex.
300+
301+
This attribute will nearly always be used to override DejaGNU annotations that
302+
disable the test on certain platforms. In such cases, the string *must* exactly
303+
match the string that is present in the test file. For instance, the test
304+
`regression/chmod_1.f90` is disabled on cygwin using the following annotation:
305+
306+
```
307+
! { dg-do run { target { ! { *-*-mingw* *-*-cygwin* } } } }
308+
```
309+
310+
In order to enable this test on cygwin, the following must be added to
311+
`regression/override.yaml`:
312+
313+
```
314+
"chmod_1.f90":
315+
enable_on: ["*-*-cygwin*"]
316+
```
317+
318+
Note that the string in the value of `enabled_on` exactly matches the string
319+
in the `regression/chmod_1.f90`. If you are not sure which string to add to
320+
the `override.yaml` file, check the `disabled_on` column in the entry for the
321+
test in the static test configuration file, `tests.cmake`, which will be
322+
present in the directory containing the test.
323+
324+
*WARNING*: If this is used on a test that is not disabled on any platform, it
325+
will result in the test being enabled _only_ on the platforms specified in the
326+
`enabled_on` list.
327+
328+
#### `xfail` ####
329+
330+
The value must be a boolean, i.e. `true` or `false`. If `true`, the test will
331+
be expected to fail, and if `false`, the test will be expected to pass. If
332+
the `xfail` column in the entry for the test in `tests.cmake` is the same as
333+
the overridden value provided here, there will be no change in the behavior
334+
of the test.
335+
196336

197337
### TODO's ###
198338

199339
If some of the items listed here are implemented, even in part, it should
200340
allows us to make better use of the test-suite.
201341

202342
Several DejaGNU directives from the test files are either ignored or only
203-
partially supported - i.e. only a subset of the options specified by the
343+
partially supported - i.e. only a subset of the options specified by the
204344
directive are handled correctly. In some
205345
cases, those directives check that the language feature/optimization being
206346
exercised by the tests is actually handled correctly. By ignoring them, we are
@@ -231,8 +371,8 @@ thereby causing the test to pass.
231371

232372
#### `dg-warning` directive ####
233373

234-
Currently, the `dg-warning` directive is ignored. It ought to be possible to
235-
treat in a manner similar to `dg-error`.
374+
Currently, the `dg-warning` directive is ignored. It ought to be possible to
375+
treat this in a manner similar to `dg-error`.
236376

237377
#### `scan-tree-dump` directive ####
238378

@@ -249,24 +389,25 @@ of GCC to an equivalent representation in LLVM IR.
249389
#### `target` directive ####
250390

251391
The `target` directive is used to restrict tests to run on certain platforms
252-
and/or systems. The directive can be fairly complex. While in most cases the
253-
directive simply consists of a triple specifying the platform on which the
254-
test is enabled (or disabled), negations, logical `and` and `or` operations are
255-
also permitted. The directives can appear in several places within
256-
a test file. In addition to "top-level" directives which control whether or
257-
not the entire test is enabled, a `target` directive can also be used to
258-
conditionally emit or suppress an error or a warning on certain platforms.
392+
and/or systems. The directive can be fairly complex. While in most cases the
393+
directive simply consists of a triple specifying the platform on which the
394+
test is enabled (or disabled), negations, logical `and` and `or` operations are
395+
also permitted. The directives can appear in several places within
396+
a test file. In addition to "top-level" directives which control whether or
397+
not the entire test is enabled, a `target` directive can also be used to
398+
conditionally emit or suppress an error or a warning on certain platforms.
259399
Currently, there is limited support for these directives.
260400

261-
- Logical operators on `target` directives are not supported. Directives
401+
- Logical operators on `target` directives are not supported. Directives
262402
containing these operators are ignored entirely.
263403

264-
- Only "top-level" directives are handled. `target` directives that appear
265-
inside other directives such as `dg-error` or `dg-warning` are ignored.
404+
- Only "top-level" directives are handled. `target` directives that appear
405+
inside other directives such as `dg-error` or `dg-warning` are ignored.
266406

267407
#### Platform-specific disabling of tests ####
268408

269-
Some tests fail on certain platforms but not on others. There is, currently, no
270-
way to disable these tests on a specific platform and these are disabled
271-
everywhere. This is obviously not ideal since the extra coverage that the tests
272-
provide &mdash; even if on a limited set of platforms &mdash; is desirable.
409+
Some tests fail on certain platforms but not on others. It is possible to
410+
disable such tests on the failing platforms and/or enable them selectively
411+
only on certain platforms. See the [Overriding
412+
DejaGNU annotations](#Overriding-DejaGNU-Annotations) section for details on
413+
how this can be done.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
# Overrides for DejaGNU annotations for tests in the directory in which this
3+
# file is present. To override tests in subdirectories, create/edit an
4+
# override.yaml file in that subdirectory.
5+
#
6+
# Please see gfortran/README.md for instructions on editing this file.
7+
#
8+
# When adding a test to this file, please leave a comment describing why the
9+
# behavior of the test is being overridden.
10+
11+
# The following two tests use ```print <namelist name>```. This is a
12+
# non-standard extension that is not supported in certain cases in gfortran,
13+
# but, for now, is always supported in flang,
14+
"namelist_print_2.f":
15+
xfail: false
16+
17+
"print_fmt_2.f90":
18+
xfail: false

Fortran/gfortran/regression/tests.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,7 +1946,7 @@ compile;namelist_args.f90;xfail;-std=gnu;;
19461946
compile;namelist_assumed_char.f90;xfail;-std=f95;;
19471947
compile;namelist_blockdata.f;xfail;;;
19481948
compile;namelist_empty.f90;;-std=legacy;;
1949-
compile;namelist_print_2.f;xfail;-std=f95;;
1949+
compile;namelist_print_2.f;;-std=f95;;
19501950
compile;namelist_utf8.f90;;;;
19511951
compile;nan_4.f90;;-std=gnu -fallow-invalid-boz;;
19521952
compile;nan_5.f90;;-fno-range-check;;
@@ -2852,7 +2852,7 @@ compile;predict-3.f90;;-fno-tree-fre -fno-tree-ccp -Og;;
28522852
compile;present_1.f90;xfail;;;
28532853
compile;print_1.f90;xfail;;;
28542854
compile;print_2.f90;xfail;;;
2855-
compile;print_fmt_2.f90;xfail;;;
2855+
compile;print_fmt_2.f90;;;;
28562856
compile;print_fmt_3.f;;;;
28572857
compile;print_fmt_4.f;xfail;;;
28582858
compile;print_fmt_5.f90;xfail;;;

0 commit comments

Comments
 (0)