Skip to content

Commit 10c2d9a

Browse files
committed
[libc++][modules] Adds module testing.
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 5c5c968 commit 10c2d9a

File tree

12 files changed

+180
-11
lines changed

12 files changed

+180
-11
lines changed

libcxx/test/libcxx/module_std.gen.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"%{clang-tidy}",
3030
"%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
3131
"%{cxx}",
32-
"%{flags} %{compile_flags}",
32+
"%{flags} %{compile_flags} %{module_flags}",
33+
"std",
3334
)
3435

3536

libcxx/test/libcxx/module_std_compat.gen.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"%{clang-tidy}",
3030
"%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
3131
"%{cxx}",
32-
"%{flags} %{compile_flags}",
32+
"%{flags} %{compile_flags} %{module_flags}",
33+
"std.compat",
3334
)
3435

3536

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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 module flags are empty when no module is supplied.
10+
11+
// MODULES:
12+
// RUN: echo "%{module_flags}" | grep "^$"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
// XFAIL: has-no-module-support
10+
11+
// Make sure that the module flags contain the expected elements.
12+
// The tests only look for the expected components and not the exact flags.
13+
// Otherwise changing the location of the module breaks this test.
14+
15+
// MODULES: std std.compat
16+
//
17+
// RUN: echo "%{module_flags}" | grep -- "-fprebuilt-module-path="
18+
// RUN: echo "%{module_flags}" | grep "std.pcm"
19+
// RUN: echo "%{module_flags}" | grep "std.compat.pcm"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
// XFAIL: has-no-module-support
10+
11+
// Make sure that the module flags contain the expected elements.
12+
// The tests only look for the expected components and not the exact flags.
13+
// Otherwise changing the location of the module breaks this test.
14+
15+
// MODULES: std
16+
//
17+
// RUN: echo "%{module_flags}" | grep -- "-fprebuilt-module-path="
18+
// RUN: echo "%{module_flags}" | grep "std.pcm"
19+
20+
// The std module should not provide the std.compat module
21+
// RUN: echo "%{module_flags}" | grep -v "std.compat.pcm"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
// XFAIL: has-no-module-support
10+
11+
// Make sure that the module flags contain the expected elements.
12+
// The tests only look for the expected components and not the exact flags.
13+
// Otherwise changing the location of the module breaks this test.
14+
15+
// MODULES: std.compat
16+
//
17+
// RUN: echo "%{module_flags}" | grep -- "-fprebuilt-module-path="
18+
// RUN: echo "%{module_flags}" | grep "std.compat.pcm"
19+
20+
// It's unspecified whether std.compat is built on the std module.
21+
// Therefore don't test its presence
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 modules that are unknown fail.
10+
11+
// MODULES: this_module_is_not_a_standard_library_module
12+
13+
// XFAIL: *

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
// UNSUPPORTED: c++03, c++11, c++14, c++17
1010
// UNSUPPORTED: clang-modules-build
1111

12-
// XFAIL: *
12+
// XFAIL: has-no-module-support
1313

1414
// A minimal test to validate import works.
1515

16+
// MODULES: std.compat
17+
1618
import std.compat;
1719

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

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
1010
// UNSUPPORTED: clang-modules-build
1111

12-
// XFAIL: *
12+
// XFAIL: has-no-module-support
1313

1414
// A minimal test to validate import works.
1515

16+
// MODULES: std
17+
1618
import std;
1719

1820
int main(int, char**) {

libcxx/utils/libcxx/test/features.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,19 @@ def _getAndroidDeviceApi(cfg):
317317
AddSubstitution("%{clang-tidy}", lambda cfg: _getSuitableClangTidy(cfg))
318318
],
319319
),
320+
# Whether module support for the platform is available.
321+
Feature(
322+
name="has-no-module-support",
323+
# The libc of these platforms have functions with internal linkages.
324+
# This is not allowed per C11 7.1.2 Standard headers/6
325+
# Any declaration of a library function shall have external linkage.
326+
when=lambda cfg: "__ANDROID__" in compilerMacros(cfg)
327+
or "__PICOLIBC__" in compilerMacros(cfg)
328+
or platform.system().lower().startswith("aix")
329+
# Avoid building on platforms that don't support modules properly.
330+
or not hasCompileFlag(cfg, "-Wno-reserved-module-identifier"),
331+
),
332+
320333
]
321334

322335
# Deduce and add the test features that that are implied by the #defines in

0 commit comments

Comments
 (0)