Skip to content

Commit 8d5b81a

Browse files
authored
[libc++] Make it possible to mark a gen-test as UNSUPPORTED (#156737)
Previously, only the tests that are generated by the gen-test could be marked as UNSUPPORTED. After this patch, the gen-test itself can be marked as UNSUPPORTED, which makes it possible to add RUN lines that would be an error when unsupported to the gen-test itself.
1 parent 7bd958f commit 8d5b81a

File tree

10 files changed

+97
-103
lines changed

10 files changed

+97
-103
lines changed

libcxx/test/extensions/clang/clang_modules_include.gen.py

Lines changed: 25 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,32 @@
1010
# This is important notably because the LLDB data formatters use
1111
# libc++ headers with modules enabled.
1212

13-
# RUN: %{python} %s %{libcxx-dir}/utils
13+
# Older macOS SDKs were not properly modularized, which causes issues with localization.
14+
# This feature should instead be based on the SDK version.
15+
# UNSUPPORTED: stdlib=system && target={{.+}}-apple-macosx13{{.*}}
16+
17+
# GCC doesn't support -fcxx-modules
18+
# UNSUPPORTED: gcc
19+
20+
# The Windows headers don't appear to be compatible with modules
21+
# UNSUPPORTED: windows
22+
# UNSUPPORTED: buildhost=windows
23+
24+
# The Android headers don't appear to be compatible with modules yet
25+
# UNSUPPORTED: LIBCXX-ANDROID-FIXME
26+
27+
# TODO: Investigate this failure
28+
# UNSUPPORTED: LIBCXX-FREEBSD-FIXME
29+
30+
# TODO: Investigate why this doesn't work on Picolibc once the locale base API is refactored
31+
# UNSUPPORTED: LIBCXX-PICOLIBC-FIXME
32+
33+
# TODO: Fix seemingly circular inclusion or <wchar.h> on AIX
34+
# UNSUPPORTED: LIBCXX-AIX-FIXME
1435

15-
# block Lit from interpreting a RUN/XFAIL/etc inside the generation script
36+
# UNSUPPORTED: FROZEN-CXX03-HEADERS-FIXME
37+
38+
# RUN: %{python} %s %{libcxx-dir}/utils
1639
# END.
1740

1841
import sys
@@ -29,31 +52,6 @@
2952
//--- {header}.compile.pass.cpp
3053
// RUN: %{{cxx}} %s %{{flags}} %{{compile_flags}} -fmodules -fcxx-modules -fmodules-cache-path=%t -fsyntax-only
3154
32-
// Older macOS SDKs were not properly modularized, which causes issues with localization.
33-
// This feature should instead be based on the SDK version.
34-
// UNSUPPORTED: stdlib=system && target={{{{.+}}}}-apple-macosx13{{{{.*}}}}
35-
36-
// GCC doesn't support -fcxx-modules
37-
// UNSUPPORTED: gcc
38-
39-
// The Windows headers don't appear to be compatible with modules
40-
// UNSUPPORTED: windows
41-
// UNSUPPORTED: buildhost=windows
42-
43-
// The Android headers don't appear to be compatible with modules yet
44-
// UNSUPPORTED: LIBCXX-ANDROID-FIXME
45-
46-
// TODO: Investigate this failure
47-
// UNSUPPORTED: LIBCXX-FREEBSD-FIXME
48-
49-
// TODO: Investigate why this doesn't work on Picolibc once the locale base API is refactored
50-
// UNSUPPORTED: LIBCXX-PICOLIBC-FIXME
51-
52-
// TODO: Fix seemingly circular inclusion or <wchar.h> on AIX
53-
// UNSUPPORTED: LIBCXX-AIX-FIXME
54-
55-
// UNSUPPORTED: FROZEN-CXX03-HEADERS-FIXME
56-
5755
{lit_header_restrictions.get(header, '')}
5856
{lit_header_undeprecations.get(header, '')}
5957
@@ -68,30 +66,6 @@
6866
6967
// REQUIRES: clang-modules-build
7068
71-
// Older macOS SDKs were not properly modularized, which causes issues with localization.
72-
// This feature should instead be based on the SDK version.
73-
// UNSUPPORTED: stdlib=system && target={{{{.+}}}}-apple-macosx13{{{{.*}}}}
74-
75-
// GCC doesn't support -fcxx-modules
76-
// UNSUPPORTED: gcc
77-
78-
// The Windows headers don't appear to be compatible with modules
79-
// UNSUPPORTED: windows
80-
// UNSUPPORTED: buildhost=windows
81-
82-
// The Android headers don't appear to be compatible with modules yet
83-
// UNSUPPORTED: LIBCXX-ANDROID-FIXME
84-
85-
// TODO: Investigate this failure
86-
// UNSUPPORTED: LIBCXX-FREEBSD-FIXME
87-
88-
// TODO: Investigate why this doesn't work on Picolibc once the locale base API is refactored
89-
// UNSUPPORTED: LIBCXX-PICOLIBC-FIXME
90-
91-
// TODO: Fix seemingly circular inclusion or <wchar.h> on AIX
92-
// UNSUPPORTED: LIBCXX-AIX-FIXME
93-
9469
@import std;
95-
9670
"""
9771
)

libcxx/test/extensions/posix/xopen_source.gen.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
#
1313
# https://llvm.org/PR117630
1414

15+
# Some parts of the code like <fstream> use non-standard functions in their implementation,
16+
# and these functions are not provided when _XOPEN_SOURCE is set to older values. This
17+
# breaks when building with modules even when we don't use the offending headers directly.
18+
# UNSUPPORTED: clang-modules-build
19+
20+
# The AIX localization support uses some functions as part of their headers that require a
21+
# recent value of _XOPEN_SOURCE.
22+
# UNSUPPORTED: LIBCXX-AIX-FIXME
23+
24+
# This test fails on FreeBSD for an unknown reason.
25+
# UNSUPPORTED: LIBCXX-FREEBSD-FIXME
26+
1527
# RUN: %{python} %s %{libcxx-dir}/utils
1628
# END.
1729

@@ -33,19 +45,6 @@
3345
print(
3446
f"""\
3547
//--- {header}.xopen_source_{version}.compile.pass.cpp
36-
37-
// Some parts of the code like <fstream> use non-standard functions in their implementation,
38-
// and these functions are not provided when _XOPEN_SOURCE is set to older values. This
39-
// breaks when building with modules even when we don't use the offending headers directly.
40-
// UNSUPPORTED: clang-modules-build
41-
42-
// The AIX localization support uses some functions as part of their headers that require a
43-
// recent value of _XOPEN_SOURCE.
44-
// UNSUPPORTED: LIBCXX-AIX-FIXME
45-
46-
// This test fails on FreeBSD for an unknown reason.
47-
// UNSUPPORTED: LIBCXX-FREEBSD-FIXME
48-
4948
{lit_header_restrictions.get(header, '')}
5049
{lit_header_undeprecations.get(header, '')}
5150

libcxx/test/libcxx-03/clang_tidy.gen.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66
#
77
# ===----------------------------------------------------------------------===##
88

9-
109
# Run our custom libc++ clang-tidy checks on all public headers.
1110

12-
# RUN: %{python} %s %{libcxx-dir}/utils
11+
# REQUIRES: has-clang-tidy
12+
13+
# The frozen headers should not be updated to the latest libc++ style, so don't test.
14+
# UNSUPPORTED: FROZEN-CXX03-HEADERS-FIXME
1315

14-
# block Lit from interpreting a RUN/XFAIL/etc inside the generation script
16+
# The GCC compiler flags are not always compatible with clang-tidy.
17+
# UNSUPPORTED: gcc
18+
19+
# RUN: %{python} %s %{libcxx-dir}/utils
1520
# END.
1621

1722
import sys
@@ -21,15 +26,6 @@
2126
for header in public_headers:
2227
print(f"""\
2328
//--- {header}.sh.cpp
24-
25-
// REQUIRES: has-clang-tidy
26-
27-
// The frozen headers should not be updated to the latest libc++ style, so don't test.
28-
// UNSUPPORTED: FROZEN-CXX03-HEADERS-FIXME
29-
30-
// The GCC compiler flags are not always compatible with clang-tidy.
31-
// UNSUPPORTED: gcc
32-
3329
{lit_header_restrictions.get(header, '')}
3430
{lit_header_undeprecations.get(header, '')}
3531

libcxx/test/libcxx/clang_tidy.gen.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
#
77
# ===----------------------------------------------------------------------===##
88

9-
109
# Run our custom libc++ clang-tidy checks on all public headers.
1110

12-
# RUN: %{python} %s %{libcxx-dir}/utils
11+
# REQUIRES: has-clang-tidy
1312

14-
# block Lit from interpreting a RUN/XFAIL/etc inside the generation script
13+
# The GCC compiler flags are not always compatible with clang-tidy.
14+
# UNSUPPORTED: gcc
15+
16+
# RUN: %{python} %s %{libcxx-dir}/utils
1517
# END.
1618

1719
import sys
@@ -21,12 +23,6 @@
2123
for header in public_headers:
2224
print(f"""\
2325
//--- {header}.sh.cpp
24-
25-
// REQUIRES: has-clang-tidy
26-
27-
// The GCC compiler flags are not always compatible with clang-tidy.
28-
// UNSUPPORTED: gcc
29-
3026
{lit_header_restrictions.get(header, '')}
3127
{lit_header_undeprecations.get(header, '')}
3228

libcxx/test/libcxx/transitive_includes.gen.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
# to avoid breaking users at every release.
1818

1919
# RUN: %{python} %s %{libcxx-dir}/utils
20-
21-
# block Lit from interpreting a RUN/XFAIL/etc inside the generation script
2220
# END.
2321

2422
import sys
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// Make sure we can mark a gen-test as UNSUPPORTED
10+
11+
// We use C++03 as a random feature that we know exists. The goal is to make
12+
// this test always unsupported.
13+
// UNSUPPORTED: c++03
14+
// REQUIRES: c++03
15+
16+
// Note that an unsupported gen-test should still contain some commands, otherwise
17+
// what are we generating? They are never executed, though.
18+
// RUN: something-definitely-invalid

libcxx/test/std/double_include.gen.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
# Test that we can include each header in two TU's and link them together.
1010

11-
# RUN: %{python} %s %{libcxx-dir}/utils
11+
# We're using compiler-specific flags in this test
12+
# REQUIRES: (gcc || clang)
1213

13-
# Block Lit from interpreting a RUN/XFAIL/etc inside the generation script.
14+
# RUN: %{python} %s %{libcxx-dir}/utils
1415
# END.
1516

1617
import sys
@@ -28,9 +29,6 @@
2829
{lit_header_restrictions.get(header, '')}
2930
{lit_header_undeprecations.get(header, '')}
3031
31-
// We're using compiler-specific flags in this test
32-
// REQUIRES: (gcc || clang)
33-
3432
// RUN: %{{cxx}} -c %s -o %t.first.o %{{flags}} %{{compile_flags}}
3533
// RUN: %{{cxx}} -c %s -o %t.second.o -DWITH_MAIN %{{flags}} %{{compile_flags}}
3634
// RUN: %{{cxx}} -o %t.exe %t.first.o %t.second.o %{{flags}} %{{link_flags}}

libcxx/test/std/header_inclusions.gen.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
# Test that all headers include all the other headers they're supposed to, as
1010
# prescribed by the Standard.
1111

12+
# UNSUPPORTED: FROZEN-CXX03-HEADERS-FIXME
13+
14+
# TODO: This is currently a libc++-specific way of testing the includes, but is a requirement for all implementation
15+
# REQUIRES: stdlib=libc++
16+
1217
# RUN: %{python} %s %{libcxx-dir}/utils
1318
# END.
1419

@@ -46,11 +51,6 @@
4651
print(
4752
f"""\
4853
//--- {header}.compile.pass.cpp
49-
// UNSUPPORTED: FROZEN-CXX03-HEADERS-FIXME
50-
51-
// TODO: This is currently a libc++-specific way of testing the includes, but is a requirement for all implementation
52-
// REQUIRES: stdlib=libc++
53-
5454
{lit_header_restrictions.get(header, '')}
5555
{lit_header_undeprecations.get(header, '')}
5656

libcxx/test/std/iterators/iterator.range/mandatory_inclusions.gen.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# <list>, <map>, <regex>, <set>, <span>, <string>, <string_view>, <unordered_map>,
1313
# <unordered_set>, <vector>.
1414

15+
# UNSUPPORTED: c++03
16+
1517
# RUN: %{python} %s %{libcxx-dir}/utils
1618
# END.
1719

@@ -53,7 +55,6 @@
5355
//--- {header}.pass.cpp
5456
{lit_header_restrictions.get(header, '')}
5557
{lit_header_undeprecations.get(header, '')}
56-
// UNSUPPORTED: c++03
5758
5859
#include <{header}>
5960
#include <cassert>

libcxx/utils/libcxx/test/format.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ def _checkBaseSubstitutions(substitutions):
3434

3535
def _executeScriptInternal(test, litConfig, commands):
3636
"""
37-
Returns (stdout, stderr, exitCode, timeoutInfo, parsedCommands)
37+
Returns (stdout, stderr, exitCode, timeoutInfo, parsedCommands), or an appropriate lit.Test.Result
38+
in case of an error while parsing the script.
3839
3940
TODO: This really should be easier to access from Lit itself
4041
"""
4142
parsedCommands = parseScript(test, preamble=commands)
43+
if isinstance(parsedCommands, lit.Test.Result):
44+
return parsedCommands
4245

4346
_, tmpBase = _getTempPaths(test)
4447
execDir = os.path.dirname(test.getExecPath())
@@ -65,7 +68,8 @@ def parseScript(test, preamble):
6568
"""
6669
Extract the script from a test, with substitutions applied.
6770
68-
Returns a list of commands ready to be executed.
71+
Returns a list of commands ready to be executed, or an appropriate lit.Test.Result in case of error
72+
while parsing the script (this includes the script being unsupported).
6973
7074
- test
7175
The lit.Test to parse.
@@ -350,6 +354,8 @@ def execute(self, test, litConfig):
350354
if "enable-benchmarks=run" in test.config.available_features:
351355
steps += ["%dbg(EXECUTED AS) %{exec} %t.exe --benchmark_out=%T/benchmark-result.json --benchmark_out_format=json"]
352356
return self._executeShTest(test, litConfig, steps)
357+
elif re.search('[.]gen[.][^.]+$', filename): # This only happens when a generator test is not supported
358+
return self._executeShTest(test, litConfig, [])
353359
else:
354360
return lit.Test.Result(
355361
lit.Test.UNRESOLVED, "Unknown test suffix for '{}'".format(filename)
@@ -381,11 +387,19 @@ def _generateGenTest(self, testSuite, pathInSuite, litConfig, localConfig):
381387
generatorExecDir = os.path.dirname(testSuite.getExecPath(pathInSuite))
382388
os.makedirs(generatorExecDir, exist_ok=True)
383389

384-
# Run the generator test
390+
# Run the generator test. It's possible for this to fail for two reasons: the generator test
391+
# is unsupported or the generator ran but failed at runtime -- handle both. In the first case,
392+
# we return the generator test itself, since it should produce the same result when run after
393+
# test suite generation. In the second case, it's a true error so we report it.
385394
steps = [] # Steps must already be in the script
386-
(out, err, exitCode, _, _) = _executeScriptInternal(generator, litConfig, steps)
395+
result = _executeScriptInternal(generator, litConfig, steps)
396+
if isinstance(result, lit.Test.Result):
397+
yield generator
398+
return
399+
400+
(out, err, exitCode, _, _) = result
387401
if exitCode != 0:
388-
raise RuntimeError(f"Error while trying to generate gen test\nstdout:\n{out}\n\nstderr:\n{err}")
402+
raise RuntimeError(f"Error while trying to generate gen test {'/'.join(pathInSuite)}\nstdout:\n{out}\n\nstderr:\n{err}")
389403

390404
# Split the generated output into multiple files and generate one test for each file
391405
for subfile, content in self._splitFile(out):

0 commit comments

Comments
 (0)