Skip to content

[libc] Add hooks for extra options in running hermetic tests #147931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions libc/cmake/modules/LLVMLibCTestRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ function(create_libc_unittest fq_target_name)
target_include_directories(${fq_build_target_name} SYSTEM PRIVATE ${LIBC_INCLUDE_DIR})
target_include_directories(${fq_build_target_name} PRIVATE ${LIBC_SOURCE_DIR})
target_compile_options(${fq_build_target_name} PRIVATE ${compile_options})
target_link_options(${fq_build_target_name} PRIVATE ${link_options})

string(REPLACE " " ";" EXTRA_LINK_OPTIONS "${LIBC_TEST_EXTRA_LINK_OPTIONS}")
target_link_options(${fq_build_target_name} PRIVATE ${link_options} ${EXTRA_LINK_OPTIONS})
Comment on lines +292 to +293
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have LIBC_COMPILE_OPTIONS_DEFAULT and LIBC_TEST_COMPILE_OPTIONS_DEFAULT. Does it work for you, or a separate linking flag is actually needed? If so can we add LIBC_LINK_OPTIONS_DEFAULT and LIBC_TEST_LINK_OPTIONS_DEFAULT similar to the compile option flags?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that should work for me. I'll get to work on it next week, we may need to keep the string replace due to way our build system uses ExternalProject_Add.


if(NOT LIBC_UNITTEST_CXX_STANDARD)
set(LIBC_UNITTEST_CXX_STANDARD ${CMAKE_CXX_STANDARD})
Expand Down Expand Up @@ -580,7 +582,9 @@ function(add_integration_test test_name)
-march=${LIBC_GPU_TARGET_ARCHITECTURE} -nostdlib -static
"--cuda-path=${LIBC_CUDA_ROOT}")
elseif(LIBC_CC_SUPPORTS_NOSTDLIBPP)
target_link_options(${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static)
string(REPLACE " " ";" EXTRA_LINK_OPTIONS "${LIBC_TEST_EXTRA_LINK_OPTIONS}")
target_link_options(${fq_build_target_name} PRIVATE
-nolibc -nostartfiles -nostdlib++ -static ${EXTRA_LINK_OPTIONS})
else()
# Older version of gcc does not support `nostdlib++` flag. We use
# `nostdlib` and link against libgcc_s, which cannot be linked statically.
Expand Down Expand Up @@ -774,7 +778,9 @@ function(add_libc_hermetic test_name)
-march=${LIBC_GPU_TARGET_ARCHITECTURE} -nostdlib -static
"--cuda-path=${LIBC_CUDA_ROOT}")
elseif(LIBC_CC_SUPPORTS_NOSTDLIBPP)
target_link_options(${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static)
string(REPLACE " " ";" EXTRA_LINK_OPTIONS "${LIBC_TEST_EXTRA_LINK_OPTIONS}")
target_link_options(${fq_build_target_name} PRIVATE
-nolibc -nostartfiles -nostdlib++ -static ${EXTRA_LINK_OPTIONS})
else()
# Older version of gcc does not support `nostdlib++` flag. We use
# `nostdlib` and link against libgcc_s, which cannot be linked statically.
Expand Down Expand Up @@ -809,9 +815,16 @@ function(add_libc_hermetic test_name)
endif()

if(NOT HERMETIC_TEST_NO_RUN_POSTBUILD)
set(test_cmd ${HERMETIC_TEST_ENV}
if (LIBC_TEST_CMD)
# In the form of "<command> binary=@BINARY@", e.g. "qemu-system-arm -loader$<COMMA>file=@BINARY@"
string(REPLACE "@BINARY@" "$<TARGET_FILE:${fq_build_target_name}>" test_cmd_parsed ${LIBC_TEST_CMD})
string(REPLACE " " ";" test_cmd "${test_cmd_parsed}")
else()
set(test_cmd ${HERMETIC_TEST_ENV}
$<$<BOOL:${LIBC_TARGET_OS_IS_GPU}>:${gpu_loader_exe}> ${CMAKE_CROSSCOMPILING_EMULATOR} ${HERMETIC_TEST_LOADER_ARGS}
$<TARGET_FILE:${fq_build_target_name}> ${HERMETIC_TEST_ARGS})
endif()

add_custom_target(
${fq_target_name}
DEPENDS ${fq_target_name}.__cmd__
Expand Down Expand Up @@ -863,7 +876,9 @@ function(add_libc_test test_name)
# Tests like the file tests perform file operations on disk file. If we
# don't chain up the unit test and hermetic test, then those tests will
# step on each other's files.
add_dependencies(${fq_test_name}.__hermetic__ ${fq_test_name}.__unit__)
if(NOT LIBC_TEST_HERMETIC_ONLY)
add_dependencies(${fq_test_name}.__hermetic__ ${fq_test_name}.__unit__)
endif()
endif()
endif()
endfunction(add_libc_test)
Expand Down
Loading