Skip to content

Commit 4871a82

Browse files
committed
[libc++][WIP] Move the libc++ test format to Lit
This allows the generally-useful parts of the test format to be shipped alongside Lit, which would make it usable for third-party developers as well. This came up at C++Now in the context of the Beman project where we'd like to set up a non-LLVM project that can use the same testing framework as libc++. With the test format moved to Lit, the format would be available after installing Lit with pip, which is really convenient.
1 parent 0370beb commit 4871a82

File tree

8 files changed

+437
-398
lines changed

8 files changed

+437
-398
lines changed

libcxx/test/configs/cmake-bridge.cfg.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import libcxx.test.format
1818
# Basic configuration of the test suite
1919
config.name = os.path.basename('@LIBCXX_TEST_CONFIG@')
2020
config.test_source_root = os.path.join('@LIBCXX_SOURCE_DIR@', 'test')
21-
config.test_format = libcxx.test.format.CxxStandardLibraryTest()
21+
config.test_format = libcxx.test.format.LibcxxTest()
2222
config.recursiveExpansionLimit = 10
2323
config.test_exec_root = os.path.join('@CMAKE_BINARY_DIR@', 'test')
2424

libcxx/utils/libcxx/test/config.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,7 @@
77
# ===----------------------------------------------------------------------===##
88

99
import os
10-
11-
12-
def _getSubstitution(substitution, config):
13-
for (orig, replacement) in config.substitutions:
14-
if orig == substitution:
15-
return replacement
16-
raise ValueError("Substitution {} is not in the config.".format(substitution))
17-
18-
19-
def _appendToSubstitution(substitutions, key, value):
20-
return [(k, v + " " + value) if k == key else (k, v) for (k, v) in substitutions]
21-
10+
import lit.formats
2211

2312
def configure(parameters, features, config, lit_config):
2413
note = lambda s: lit_config.note("({}) {}".format(config.name, s))
@@ -53,7 +42,7 @@ def configure(parameters, features, config, lit_config):
5342

5443
# Print the basic substitutions
5544
for sub in ("%{cxx}", "%{flags}", "%{compile_flags}", "%{link_flags}", "%{exec}"):
56-
note("Using {} substitution: '{}'".format(sub, _getSubstitution(sub, config)))
45+
note("Using {} substitution: '{}'".format(sub, lit.formats.standardlibrarytest._getSubstitution(sub, config)))
5746

5847
# Print all available features
5948
note("All available features: {}".format(", ".join(sorted(config.available_features))))

libcxx/utils/libcxx/test/dsl.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import shutil
1414
import tempfile
1515

16-
import libcxx.test.format
1716
import lit
17+
import lit.formats
1818
import lit.LitConfig
1919
import lit.Test
2020
import lit.TestRunner
@@ -99,7 +99,7 @@ def _executeWithFakeConfig(test, commands):
9999
order="smart",
100100
params={},
101101
)
102-
return libcxx.test.format._executeScriptInternal(test, litConfig, commands)
102+
return lit.formats.standardlibrarytest._executeScriptInternal(test, litConfig, commands)
103103

104104

105105
def _makeConfigTest(config):
@@ -121,12 +121,12 @@ def _makeConfigTest(config):
121121

122122
class TestWrapper(lit.Test.Test):
123123
def __enter__(self):
124-
testDir, _ = libcxx.test.format._getTempPaths(self)
124+
testDir, _ = lit.formats.standardlibrarytest._getTempPaths(self)
125125
os.makedirs(testDir)
126126
return self
127127

128128
def __exit__(self, *args):
129-
testDir, _ = libcxx.test.format._getTempPaths(self)
129+
testDir, _ = lit.formats.standardlibrarytest._getTempPaths(self)
130130
shutil.rmtree(testDir)
131131
os.remove(tmp.name)
132132

@@ -348,18 +348,6 @@ def featureTestMacros(config, flags=""):
348348
}
349349

350350

351-
def _getSubstitution(substitution, config):
352-
for (orig, replacement) in config.substitutions:
353-
if orig == substitution:
354-
return replacement
355-
raise ValueError('Substitution {} is not in the config.'.format(substitution))
356-
357-
def _appendToSubstitution(substitutions, key, value):
358-
return [(k, v + " " + value) if k == key else (k, v) for (k, v) in substitutions]
359-
360-
def _prependToSubstitution(substitutions, key, value):
361-
return [(k, value + " " + v) if k == key else (k, v) for (k, v) in substitutions]
362-
363351
def _ensureFlagIsSupported(config, flag):
364352
(exitCode, out, err) = tryCompileFlag(config, flag)
365353
assert (
@@ -442,7 +430,7 @@ def __init__(self, flag):
442430
def applyTo(self, config):
443431
flag = self._getFlag(config)
444432
_ensureFlagIsSupported(config, flag)
445-
config.substitutions = _appendToSubstitution(
433+
config.substitutions = lit.formats.standardlibrarytest._appendToSubstitution(
446434
config.substitutions, "%{flags}", flag
447435
)
448436

@@ -464,7 +452,7 @@ def __init__(self, flag):
464452
def applyTo(self, config):
465453
flag = self._getFlag(config)
466454
if hasCompileFlag(config, flag):
467-
config.substitutions = _appendToSubstitution(
455+
config.substitutions = lit.formats.standardlibrarytest._appendToSubstitution(
468456
config.substitutions, "%{flags}", flag
469457
)
470458

@@ -486,7 +474,7 @@ def __init__(self, flag):
486474
def applyTo(self, config):
487475
flag = self._getFlag(config)
488476
_ensureFlagIsSupported(config, flag)
489-
config.substitutions = _appendToSubstitution(
477+
config.substitutions = lit.formats.standardlibrarytest._appendToSubstitution(
490478
config.substitutions, "%{compile_flags}", flag
491479
)
492480

@@ -508,7 +496,7 @@ def __init__(self, flag):
508496
def applyTo(self, config):
509497
flag = self._getFlag(config)
510498
_ensureFlagIsSupported(config, flag)
511-
config.substitutions = _appendToSubstitution(
499+
config.substitutions = lit.formats.standardlibrarytest._appendToSubstitution(
512500
config.substitutions, "%{link_flags}", flag
513501
)
514502

@@ -530,7 +518,7 @@ def __init__(self, flag):
530518
def applyTo(self, config):
531519
flag = self._getFlag(config)
532520
_ensureFlagIsSupported(config, flag)
533-
config.substitutions = _prependToSubstitution(
521+
config.substitutions = lit.formats.standardlibrarytest._prependToSubstitution(
534522
config.substitutions, "%{link_flags}", flag
535523
)
536524

@@ -554,7 +542,7 @@ def applyTo(self, config):
554542
flag = self._getFlag(config)
555543
# Use -Werror to make sure we see an error about the flag being unsupported.
556544
if hasCompileFlag(config, "-Werror " + flag):
557-
config.substitutions = _appendToSubstitution(
545+
config.substitutions = lit.formats.standardlibrarytest._appendToSubstitution(
558546
config.substitutions, "%{compile_flags}", flag
559547
)
560548

0 commit comments

Comments
 (0)