Skip to content

Commit b613c3d

Browse files
committed
[ATFE] Run llvmlibc tests against generated sysroot matching final multilib layout.
LLVM libc tests now run against a generated build-tree sysroot so tests can be compiled and linked using the same multilib layout that will be installed in the final package. LLVM libc tests need to resolve headers and libraries through the multilib layout, including the optimized common-header layout when enabled. Building a dedicated test sysroot lets the tests exercise the generated multilib package structure instead of relying only on per-variant temporary install directories. This is particularly important for the layered multilib layout, where minor variants contain only the payload required for their subarchive and rely on content inherited from base variants. As a result, individual per-variant temporary install directories no longer represent a complete view of the installed sysroot and are not suitable as test environments. Using a generated test sysroot ensures tests resolve files exactly as they will in the final packaged multilib installation This patch: - Adds LLVM_LIBC_TEST_SYSROOT. - When C_LIBRARY=llvmlibc, creates a new target: llvmlibc-test-sysroot. - That target deletes/recreates the test sysroot, copies either: - multilib-optimised/ if header optimisation is enabled, or - multilib/ otherwise. - For LLVM libc tests, the test compile and link options now include: - --sysroot=<LLVM_LIBC_TEST_SYSROOT>. - the variant's multilib flags - A dependency from LLVM libc check targets to the generated test sysroot
1 parent bb674aa commit b613c3d

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

arm-software/embedded/arm-multilib/CMakeLists.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ set(ENABLE_VARIANTS "all" CACHE STRING "Semicolon separated list of variants to
2525
set(C_LIBRARY "picolibc" CACHE STRING "Which C library to use.")
2626
set_property(CACHE C_LIBRARY PROPERTY STRINGS picolibc newlib newlib-nano llvmlibc)
2727
set(PROJECT_PREFIX "${CMAKE_BINARY_DIR}/lib-builds" CACHE STRING "Directory to build subprojects in.")
28+
set(LLVM_LIBC_TEST_SYSROOT "${PROJECT_PREFIX}/test-sysroot" CACHE PATH "Build-tree package-style sysroot for LLVM libc tests.")
2829
option(
2930
NUMERICAL_BUILD_NAMES
3031
"Instead of using the full variant name to label build directories, use an index number. This may help shorten paths."
@@ -121,6 +122,24 @@ add_dependencies(
121122
check-unwind
122123
)
123124

125+
if(C_LIBRARY STREQUAL llvmlibc)
126+
if(ENABLE_MULTILIB_HEADER_OPTIMISATION)
127+
set(LLVM_LIBC_TEST_SYSROOT_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/multilib-optimised")
128+
else()
129+
set(LLVM_LIBC_TEST_SYSROOT_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/multilib")
130+
endif()
131+
list(APPEND passthrough_dirs "-DLLVM_LIBC_TEST_SYSROOT=${LLVM_LIBC_TEST_SYSROOT}")
132+
add_custom_target(
133+
llvmlibc-test-sysroot
134+
COMMAND ${CMAKE_COMMAND} -E rm -rf "${LLVM_LIBC_TEST_SYSROOT}"
135+
COMMAND ${CMAKE_COMMAND} -E make_directory "${LLVM_LIBC_TEST_SYSROOT}"
136+
COMMAND ${CMAKE_COMMAND} -E copy_directory
137+
"${LLVM_LIBC_TEST_SYSROOT_SOURCE_DIR}"
138+
"${LLVM_LIBC_TEST_SYSROOT}"
139+
COMMENT "Generating llvm-libc test sysroot"
140+
)
141+
endif()
142+
124143
if(ENABLE_PARALLEL_LIB_CONFIG OR ENABLE_PARALLEL_LIB_BUILD)
125144
# Additional targets to build the variant subprojects in parallel.
126145
# The build steps can use multible jobs to compile in parallel, but
@@ -247,6 +266,7 @@ foreach(lib_idx RANGE ${lib_count_dec})
247266
${passthrough_dirs}
248267
${additional_cmake_args}
249268
-DVARIANT_JSON=${variant_json_file}
269+
-DVARIANT_MULTILIB_FLAGS=${variant_multilib_flags}
250270
-DC_LIBRARY=${C_LIBRARY}
251271
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
252272
-DPROJECT_PREFIX=${PROJECT_PREFIX}
@@ -334,6 +354,13 @@ foreach(lib_idx RANGE ${lib_count_dec})
334354
${check_target}
335355
runtimes-${variant}-build
336356
)
357+
if(C_LIBRARY STREQUAL llvmlibc AND check_target STREQUAL check-llvmlibc)
358+
ExternalProject_Add_StepDependencies(
359+
runtimes-${variant}
360+
${check_target}
361+
llvmlibc-test-sysroot
362+
)
363+
endif()
337364
add_custom_target(${check_target}-${variant})
338365
add_dependencies(${check_target} runtimes-${variant}-${check_target})
339366
add_dependencies(${check_target}-${variant} runtimes-${variant}-${check_target})
@@ -432,3 +459,11 @@ if(ENABLE_MULTILIB_HEADER_OPTIMISATION)
432459
DESTINATION .
433460
)
434461
endif()
462+
463+
if(C_LIBRARY STREQUAL llvmlibc)
464+
if(ENABLE_MULTILIB_HEADER_OPTIMISATION)
465+
add_dependencies(llvmlibc-test-sysroot generate-multilib-common-headers)
466+
else()
467+
add_dependencies(llvmlibc-test-sysroot ${all_runtime_targets} multilib-yaml)
468+
endif()
469+
endif()

arm-software/embedded/arm-runtimes/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ endif()
5959
set(TARGET_ARCH ${TARGET_ARCH_def} CACHE STRING "Architecture being targetted.")
6060
set(VARIANT ${VARIANT_def} CACHE STRING "Name for the variant, usually architecture + suffix.")
6161
set(COMPILE_FLAGS ${COMPILE_FLAGS_def} CACHE STRING "Flags required to build the variant.")
62+
set(VARIANT_MULTILIB_FLAGS "" CACHE STRING "Flags that select this variant in multilib.yaml.")
6263
set(TEST_EXECUTOR ${TEST_EXECUTOR_def} CACHE STRING "Program used to run tests.")
6364
set_property(CACHE TEST_EXECUTOR PROPERTY STRINGS fvp qemu)
6465
set(FVP_MODEL ${FVP_MODEL_def} CACHE STRING "FVP model to use, if FVP is the test executor.")
@@ -100,6 +101,7 @@ set(ENABLE_LIBC_TESTS ${ENABLE_LIBC_TESTS_def} CACHE BOOL "Enable libc tests (pi
100101
set(ENABLE_COMPILER_RT_TESTS ${ENABLE_COMPILER_RT_TESTS_def} CACHE BOOL "Enable compiler-rt tests.")
101102
set(ENABLE_LIBCXX_TESTS ${ENABLE_LIBCXX_TESTS_def} CACHE BOOL "Enable libcxx tests.")
102103
set(LLVM_BINARY_DIR "" CACHE PATH "Path to LLVM toolchain root to build libraries with")
104+
set(LLVM_LIBC_TEST_SYSROOT "" CACHE PATH "Build-tree package-style sysroot for LLVM libc tests.")
103105
option(LLVM_USE_RELATIVE_PATHS_IN_MACROS "Use relative paths in macro expansions" ON)
104106

105107
set(PROJECT_PREFIX "subproj" CACHE STRING "Directory to build subprojects in.")
@@ -765,6 +767,18 @@ if(C_LIBRARY STREQUAL llvmlibc)
765767
-T
766768
llvmlibc.ld
767769
)
770+
set(llvmlibc_test_compile_options "")
771+
if(LLVM_LIBC_TEST_SYSROOT)
772+
set(llvmlibc_test_sysroot "--sysroot=${LLVM_LIBC_TEST_SYSROOT}")
773+
list(APPEND llvmlibc_test_compile_options ${llvmlibc_test_sysroot})
774+
list(APPEND llvmlibc_test_link_options ${llvmlibc_test_sysroot})
775+
endif()
776+
if(VARIANT_MULTILIB_FLAGS)
777+
separate_arguments(llvmlibc_test_multilib_flags NATIVE_COMMAND ${VARIANT_MULTILIB_FLAGS})
778+
list(APPEND llvmlibc_test_compile_options ${llvmlibc_test_multilib_flags})
779+
list(APPEND llvmlibc_test_link_options ${llvmlibc_test_multilib_flags})
780+
endif()
781+
list(JOIN llvmlibc_test_compile_options "," llvmlibc_test_compile_options_default)
768782
if(VARIANT MATCHES "(^|_)pacret_bti(_|$)")
769783
set(enable_dummypackeys ON)
770784
list(APPEND llvmlibc_test_link_options -ldummypackeys)
@@ -835,6 +849,7 @@ if(C_LIBRARY STREQUAL llvmlibc)
835849
-DLLVM_ENABLE_RUNTIMES=libc
836850
-DLLVM_LIBC_ALL_HEADERS=ON
837851
-DLLVM_LIBC_FULL_BUILD=ON
852+
-DLIBC_TEST_COMPILE_OPTIONS_DEFAULT=${llvmlibc_test_compile_options_default}
838853
-DLIBC_TEST_LINK_OPTIONS_DEFAULT=${llvmlibc_test_link_options_default}
839854
-DLIBC_TEST_CMD=${test_cmd}
840855
-DLIBC_TEST_HERMETIC_ONLY=ON

0 commit comments

Comments
 (0)