Skip to content

Commit 57ca748

Browse files
authored
[libc++][modules] Adds module testing. (#76246)
This adds a new module test infrastructure. This requires tagging tests using modules. The test runner uses this information to determine the compiler flags needed to build and use the module. Currently modules are build per test, which allows testing them for tests with ADDITIONAL_COMPILE_FLAGS. At the moment only 4 tests use modules. Therefore the performance penalty is not measurable. If in the future more tests use modules it would be good to measure the overhead and determine whether it's acceptable.
1 parent d06ae33 commit 57ca748

File tree

13 files changed

+184
-11
lines changed

13 files changed

+184
-11
lines changed

libcxx/docs/TestingLibcxx.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ Custom Directives
394394
~~~~~~~~~~~~~~~~~
395395

396396
Lit has many directives built in (e.g., ``DEFINE``, ``UNSUPPORTED``). In addition to those directives, libc++ adds two additional libc++-specific directives that makes
397-
writing tests easier. See `libc++-specific Lit Directives`_ for more information about the ``FILE_DEPENDENCIES`` and ``ADDITIONAL_COMPILE_FLAGS`` libc++-specific directives.
397+
writing tests easier. See `libc++-specific Lit Directives`_ for more information about the ``FILE_DEPENDENCIES``, ``ADDITIONAL_COMPILE_FLAGS``, and ``MODULE_DEPENDENCIES`` libc++-specific directives.
398398

399399
.. _libc++-specific Lit Directives:
400400
.. list-table:: libc++-specific Lit Directives
@@ -417,6 +417,13 @@ writing tests easier. See `libc++-specific Lit Directives`_ for more information
417417
- The additional compiler flags specified by a space-separated list to the ``ADDITIONAL_COMPILE_FLAGS`` libc++-specific Lit directive will be added to the end of the ``%{compile_flags}``
418418
substitution for the test that contains it. This libc++-specific Lit directive makes it possible to add special compilation flags without having to resort to writing a ``.sh.cpp`` test (see
419419
`Lit Meaning of libc++ Test Filenames`_), more powerful but perhaps overkill.
420+
* - ``MODULE_DEPENDENCIES``
421+
- ``// MODULE_DEPENDENCIES: std std.compat``
422+
- This directive will build the required C++23 standard library
423+
modules and add the additional compiler flags in
424+
%{compile_flags}. (Libc++ offers these modules in C++20 as an
425+
extension.)
426+
420427

421428
Benchmarks
422429
==========

libcxx/test/libcxx/module_std.gen.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
3131
"%{cxx}",
3232
"%{flags} %{compile_flags}",
33+
"std",
3334
)
3435

3536

libcxx/test/libcxx/module_std_compat.gen.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
3131
"%{cxx}",
3232
"%{flags} %{compile_flags}",
33+
"std.compat",
3334
)
3435

3536

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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 that the compile flags contain no module information.
10+
11+
// MODULE_DEPENDENCIES:
12+
13+
// RUN: echo "%{compile_flags}" | grep -v "std.pcm"
14+
// RUN: echo "%{compile_flags}" | grep -v "std.compat.pcm"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10+
// UNSUPPORTED: clang-modules-build
11+
// UNSUPPORTED: gcc
12+
13+
// XFAIL: has-no-cxx-module-support
14+
15+
// Make sure that the compile flags contain the expected elements.
16+
// The tests only look for the expected components and not the exact flags.
17+
// Otherwise changing the location of the module would break this test.
18+
19+
// MODULE_DEPENDENCIES: std std.compat
20+
21+
// RUN: echo "%{compile_flags}" | grep -- "-fmodule-file=std=.*/std.pcm .*/std.pcm"
22+
// RUN: echo "%{compile_flags}" | grep -- "-fmodule-file=std.compat=.*/std.compat.pcm .*/std.compat.pcm"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10+
// UNSUPPORTED: clang-modules-build
11+
// UNSUPPORTED: gcc
12+
13+
// XFAIL: has-no-cxx-module-support
14+
15+
// Make sure that the compile flags contain the expected elements.
16+
// The tests only look for the expected components and not the exact flags.
17+
// Otherwise changing the location of the module would break this test.
18+
19+
// MODULE_DEPENDENCIES: std
20+
21+
// RUN: echo "%{compile_flags}" | grep -- "-fmodule-file=std=.*/std.pcm .*/std.pcm"
22+
23+
// The std module should not provide the std.compat module
24+
// RUN: echo "%{compile_flags}" | grep -v "std.compat.pcm"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10+
// UNSUPPORTED: clang-modules-build
11+
// UNSUPPORTED: gcc
12+
13+
// XFAIL: has-no-cxx-module-support
14+
15+
// Make sure that the compile flags contain the expected elements.
16+
// The tests only look for the expected components and not the exact flags.
17+
// Otherwise changing the location of the module would break this test.
18+
19+
// MODULE_DEPENDENCIES: std.compat
20+
21+
// RUN: echo "%{compile_flags}" | grep -- "-fmodule-file=std.compat=.*/std.compat.pcm .*/std.compat.pcm"
22+
23+
// It's unspecified whether std.compat is built on the std module.
24+
// Therefore don't test its presence

libcxx/test/std/modules/std.compat.pass.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88

99
// UNSUPPORTED: c++03, c++11, c++14, c++17
1010
// UNSUPPORTED: clang-modules-build
11+
// UNSUPPORTED: gcc
1112

12-
// XFAIL: *
13+
// XFAIL: has-no-cxx-module-support
1314

1415
// A minimal test to validate import works.
1516

17+
// MODULE_DEPENDENCIES: std.compat
18+
1619
import std.compat;
1720

1821
int main(int, char**) { return !(::strlen("Hello modular world") == 19); }

libcxx/test/std/modules/std.pass.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88

99
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
1010
// UNSUPPORTED: clang-modules-build
11+
// UNSUPPORTED: gcc
1112

12-
// XFAIL: *
13+
// XFAIL: has-no-cxx-module-support
1314

1415
// A minimal test to validate import works.
1516

17+
// MODULE_DEPENDENCIES: std
18+
1619
import std;
1720

1821
int main(int, char**) {

libcxx/utils/libcxx/test/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def _getSubstitution(substitution, config):
1616
raise ValueError("Substitution {} is not in the config.".format(substitution))
1717

1818

19+
def _appendToSubstitution(substitutions, key, value):
20+
return [(k, v + " " + value) if k == key else (k, v) for (k, v) in substitutions]
21+
22+
1923
def configure(parameters, features, config, lit_config):
2024
note = lambda s: lit_config.note("({}) {}".format(config.name, s))
2125
config.environment = dict(os.environ)

0 commit comments

Comments
 (0)