[libcxx] [libcxxabi] [llvm] [libc++][WIP] Move the libc++ test format to Lit (PR #90803)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 1 17:15:10 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {darker}-->
:warning: Python code formatter, darker found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
darker --check --diff -r a00bbcbe7c7b1d5fb437d530555a6940c0b8d06a...a4f20fee50b89fe1c9c40aa6f9b6455fcc99257d llvm/utils/lit/lit/formats/standardlibrarytest.py libcxx/utils/libcxx/test/dsl.py libcxx/utils/libcxx/test/format.py llvm/utils/lit/lit/formats/__init__.py
``````````
</details>
<details>
<summary>
View the diff from darker here.
</summary>
``````````diff
--- libcxx/utils/libcxx/test/dsl.py 2024-05-02 00:10:07.000000 +0000
+++ libcxx/utils/libcxx/test/dsl.py 2024-05-02 00:14:45.599306 +0000
@@ -97,11 +97,13 @@
debug=False,
isWindows=platform.system() == "Windows",
order="smart",
params={},
)
- return lit.formats.standardlibrarytest._executeScriptInternal(test, litConfig, commands)
+ return lit.formats.standardlibrarytest._executeScriptInternal(
+ test, litConfig, commands
+ )
def _makeConfigTest(config):
# Make sure the support directories exist, which is needed to create
# the temporary file %t below.
--- libcxx/utils/libcxx/test/format.py 2024-05-02 00:10:07.000000 +0000
+++ libcxx/utils/libcxx/test/format.py 2024-05-02 00:14:45.646987 +0000
@@ -25,14 +25,19 @@
substitutions = lit.TestRunner.getDefaultSubstitutions(test, tmpDir, tmpBase)
substituted = lit.TestRunner.applySubstitutions(
[command], substitutions, recursion_limit=test.config.recursiveExpansionLimit
)
- (out, err, exitCode, _) = lit.TestRunner.executeScriptInternal(test, litConfig, tmpBase, substituted, execDir)
+ (out, err, exitCode, _) = lit.TestRunner.executeScriptInternal(
+ test, litConfig, tmpBase, substituted, execDir
+ )
if exitCode != 0:
return lit.Test.Result(
- lit.Test.UNRESOLVED, "Failed to build module std for '{}':\n{}\n{}".format(test.getFilePath(), out, err)
+ lit.Test.UNRESOLVED,
+ "Failed to build module std for '{}':\n{}\n{}".format(
+ test.getFilePath(), out, err
+ ),
)
class LibcxxTest(lit.formats.StandardLibraryTest):
def execute(self, test, litConfig):
@@ -43,11 +48,13 @@
"MODULE_DEPENDENCIES:",
lit.TestRunner.ParserKind.SPACE_LIST,
initial_value=modules,
)
]
- lit.TestRunner.parseIntegratedTestScript(test, additional_parsers=parsers, require_script=False)
+ lit.TestRunner.parseIntegratedTestScript(
+ test, additional_parsers=parsers, require_script=False
+ )
# Build the modules if needed and tweak the compiler flags of the rest of the test so
# it knows about the just-built modules.
moduleCompileFlags = []
if modules:
@@ -56,29 +63,39 @@
# Make sure the std module is built before std.compat. Libc++'s
# std.compat module depends on the std module. It is not
# known whether the compiler expects the modules in the order of
# their dependencies. However it's trivial to provide them in
# that order.
- command = ("%dbg(MODULE std) %{cxx} %{flags} %{compile_flags} "
- "-Wno-reserved-module-identifier -Wno-reserved-user-defined-literal "
- "--precompile -o %T/std.pcm -c %{module-dir}/std.cppm")
+ command = (
+ "%dbg(MODULE std) %{cxx} %{flags} %{compile_flags} "
+ "-Wno-reserved-module-identifier -Wno-reserved-user-defined-literal "
+ "--precompile -o %T/std.pcm -c %{module-dir}/std.cppm"
+ )
res = _buildModule(test, litConfig, command)
if isinstance(res, lit.Test.Result):
return res
moduleCompileFlags.extend(["-fmodule-file=std=%T/std.pcm", "%T/std.pcm"])
if "std.compat" in modules:
- command = ("%dbg(MODULE std.compat) %{cxx} %{flags} %{compile_flags} "
- "-Wno-reserved-module-identifier -Wno-reserved-user-defined-literal "
- "-fmodule-file=std=%T/std.pcm " # The std.compat module imports std.
- "--precompile -o %T/std.compat.pcm -c %{module-dir}/std.compat.cppm")
+ command = (
+ "%dbg(MODULE std.compat) %{cxx} %{flags} %{compile_flags} "
+ "-Wno-reserved-module-identifier -Wno-reserved-user-defined-literal "
+ "-fmodule-file=std=%T/std.pcm " # The std.compat module imports std.
+ "--precompile -o %T/std.compat.pcm -c %{module-dir}/std.compat.cppm"
+ )
res = _buildModule(test, litConfig, command)
if isinstance(res, lit.Test.Result):
return res
- moduleCompileFlags.extend(["-fmodule-file=std.compat=%T/std.compat.pcm", "%T/std.compat.pcm"])
+ moduleCompileFlags.extend(
+ ["-fmodule-file=std.compat=%T/std.compat.pcm", "%T/std.compat.pcm"]
+ )
# Add compile flags required for the test to use the just-built modules
- test.config.substitutions = lit.formats.standardlibrarytest._appendToSubstitution(
- test.config.substitutions, "%{compile_flags}", " ".join(moduleCompileFlags)
+ test.config.substitutions = (
+ lit.formats.standardlibrarytest._appendToSubstitution(
+ test.config.substitutions,
+ "%{compile_flags}",
+ " ".join(moduleCompileFlags),
+ )
)
return super().execute(test, litConfig)
--- llvm/utils/lit/lit/formats/standardlibrarytest.py 2024-05-02 00:10:07.000000 +0000
+++ llvm/utils/lit/lit/formats/standardlibrarytest.py 2024-05-02 00:14:45.748389 +0000
@@ -14,11 +14,11 @@
def _getSubstitution(substitution, config):
"""
Helper function to get a specific substitution from a config object.
"""
- for (orig, replacement) in config.substitutions:
+ for orig, replacement in config.substitutions:
if orig == substitution:
return replacement
raise ValueError("Substitution {} is not in the config.".format(substitution))
@@ -64,11 +64,11 @@
# Note: We use -Wno-error with %{verify} to make sure that we don't treat all diagnostics as
# errors, which doesn't make sense for clang-verify tests because we may want to check
# for specific warning diagnostics.
"%{cxx} %s %{flags} %{compile_flags} -fsyntax-only -Wno-error -Xclang -verify -Xclang -verify-ignore-unexpected=note -ferror-limit=0",
),
- ("%{run}", "%{exec} %t.exe")
+ ("%{run}", "%{exec} %t.exe"),
]
def _executeScriptInternal(test, litConfig, commands):
"""
@@ -124,11 +124,11 @@
),
lit.TestRunner.IntegratedTestKeywordParser(
"ADDITIONAL_COMPILE_FLAGS:",
lit.TestRunner.ParserKind.SPACE_LIST,
initial_value=additionalCompileFlags,
- )
+ ),
]
# Add conditional parsers for ADDITIONAL_COMPILE_FLAGS. This should be replaced by first
# class support for conditional keywords in Lit, which would allow evaluating arbitrary
# Lit boolean expressions instead.
@@ -230,18 +230,26 @@
sourcePath = testSuite.getSourcePath(pathInSuite)
filename = os.path.basename(sourcePath)
# Ignore dot files, excluded tests and tests with an unsupported suffix
- hasSupportedSuffix = lambda f: any([re.search(ext, f) for ext in SUPPORTED_SUFFIXES])
- if filename.startswith(".") or filename in localConfig.excludes or not hasSupportedSuffix(filename):
+ hasSupportedSuffix = lambda f: any(
+ [re.search(ext, f) for ext in SUPPORTED_SUFFIXES]
+ )
+ if (
+ filename.startswith(".")
+ or filename in localConfig.excludes
+ or not hasSupportedSuffix(filename)
+ ):
return
# If this is a generated test, run the generation step and add
# as many Lit tests as necessary.
- if re.search('[.]gen[.][^.]+$', filename):
- for test in self._generateGenTest(testSuite, pathInSuite, litConfig, localConfig):
+ if re.search("[.]gen[.][^.]+$", filename):
+ for test in self._generateGenTest(
+ testSuite, pathInSuite, litConfig, localConfig
+ ):
yield test
else:
yield lit.Test.Test(testSuite, pathInSuite, localConfig)
def execute(self, test, litConfig):
@@ -322,34 +330,38 @@
# Make sure we have a directory to execute the generator test in
generatorExecDir = os.path.dirname(testSuite.getExecPath(pathInSuite))
os.makedirs(generatorExecDir, exist_ok=True)
# Run the generator test
- steps = [] # Steps must already be in the script
+ steps = [] # Steps must already be in the script
(out, err, exitCode, _, _) = _executeScriptInternal(generator, litConfig, steps)
if exitCode != 0:
- raise RuntimeError(f"Error while trying to generate gen test\nstdout:\n{out}\n\nstderr:\n{err}")
+ raise RuntimeError(
+ f"Error while trying to generate gen test\nstdout:\n{out}\n\nstderr:\n{err}"
+ )
# Split the generated output into multiple files and generate one test for each file
for subfile, content in self._splitFile(out):
generatedFile = testSuite.getExecPath(pathInSuite + (subfile,))
os.makedirs(os.path.dirname(generatedFile), exist_ok=True)
- with open(generatedFile, 'w') as f:
+ with open(generatedFile, "w") as f:
f.write(content)
yield lit.Test.Test(testSuite, (generatedFile,), localConfig)
def _splitFile(self, input):
- DELIM = r'^(//|#)---(.+)'
+ DELIM = r"^(//|#)---(.+)"
lines = input.splitlines()
currentFile = None
thisFileContent = []
for line in lines:
match = re.match(DELIM, line)
if match:
if currentFile is not None:
- yield (currentFile, '\n'.join(thisFileContent))
+ yield (currentFile, "\n".join(thisFileContent))
currentFile = match.group(2).strip()
thisFileContent = []
- assert currentFile is not None, f"Some input to split-file doesn't belong to any file, input was:\n{input}"
+ assert (
+ currentFile is not None
+ ), f"Some input to split-file doesn't belong to any file, input was:\n{input}"
thisFileContent.append(line)
if currentFile is not None:
- yield (currentFile, '\n'.join(thisFileContent))
+ yield (currentFile, "\n".join(thisFileContent))
``````````
</details>
https://github.com/llvm/llvm-project/pull/90803
More information about the llvm-commits
mailing list