@@ -233,7 +233,11 @@ function(create_libc_unittest fq_target_name)
233233 _get_common_test_compile_options(compile_options "${LIBC_UNITTEST_C_TEST} "
234234 "${LIBC_UNITTEST_FLAGS} " )
235235 # TODO: Ideally we would have a separate function for link options.
236- set (link_options ${compile_options} )
236+ set (link_options
237+ ${compile_options}
238+ ${LIBC_LINK_OPTIONS_DEFAULT}
239+ ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
240+ )
237241 list (APPEND compile_options ${LIBC_UNITTEST_COMPILE_OPTIONS} )
238242
239243 if (SHOW_INTERMEDIATE_OBJECTS)
@@ -580,12 +584,26 @@ function(add_integration_test test_name)
580584 -march=${LIBC_GPU_TARGET_ARCHITECTURE} -nostdlib -static
581585 "--cuda-path=${LIBC_CUDA_ROOT} " )
582586 elseif (LIBC_CC_SUPPORTS_NOSTDLIBPP)
583- target_link_options (${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static )
587+ set (link_options
588+ -nolibc
589+ -nostartfiles
590+ -nostdlib++
591+ -static
592+ ${LIBC_LINK_OPTIONS_DEFAULT}
593+ ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
594+ )
595+ target_link_options (${fq_build_target_name} PRIVATE ${link_options} )
584596 else ()
585597 # Older version of gcc does not support `nostdlib++` flag. We use
586598 # `nostdlib` and link against libgcc_s, which cannot be linked statically.
587- target_link_options (${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib)
588- list (APPEND link_libraries ${LIBGCC_S_LOCATION} )
599+ set (link_options
600+ -nolibc
601+ -nostartfiles
602+ -static
603+ ${LIBC_LINK_OPTIONS_DEFAULT}
604+ ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
605+ )
606+ target_link_options (${fq_build_target_name} PRIVATE ${link_options} )
589607 endif ()
590608 target_link_libraries (
591609 ${fq_build_target_name}
@@ -774,11 +792,26 @@ function(add_libc_hermetic test_name)
774792 -march=${LIBC_GPU_TARGET_ARCHITECTURE} -nostdlib -static
775793 "--cuda-path=${LIBC_CUDA_ROOT} " )
776794 elseif (LIBC_CC_SUPPORTS_NOSTDLIBPP)
777- target_link_options (${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static )
795+ set (link_options
796+ -nolibc
797+ -nostartfiles
798+ -nostdlib++
799+ -static
800+ ${LIBC_LINK_OPTIONS_DEFAULT}
801+ ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
802+ )
803+ target_link_options (${fq_build_target_name} PRIVATE ${link_options} )
778804 else ()
779805 # Older version of gcc does not support `nostdlib++` flag. We use
780806 # `nostdlib` and link against libgcc_s, which cannot be linked statically.
781- target_link_options (${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib)
807+ set (link_options
808+ -nolibc
809+ -nostartfiles
810+ -static
811+ ${LIBC_LINK_OPTIONS_DEFAULT}
812+ ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
813+ )
814+ target_link_options (${fq_build_target_name} PRIVATE ${link_options} )
782815 list (APPEND link_libraries ${LIBGCC_S_LOCATION} )
783816 endif ()
784817 target_link_libraries (
@@ -809,9 +842,16 @@ function(add_libc_hermetic test_name)
809842 endif ()
810843
811844 if (NOT HERMETIC_TEST_NO_RUN_POSTBUILD)
812- set (test_cmd ${HERMETIC_TEST_ENV}
845+ if (LIBC_TEST_CMD)
846+ # In the form of "<command> binary=@BINARY@", e.g. "qemu-system-arm -loader$<COMMA>file=@BINARY@"
847+ string (REPLACE "@BINARY@" "$<TARGET_FILE:${fq_build_target_name} >" test_cmd_parsed ${LIBC_TEST_CMD} )
848+ string (REPLACE " " ";" test_cmd "${test_cmd_parsed} " )
849+ else ()
850+ set (test_cmd ${HERMETIC_TEST_ENV}
813851 $<$<BOOL :${LIBC_TARGET_OS_IS_GPU} >:${gpu_loader_exe} > ${CMAKE_CROSSCOMPILING_EMULATOR} ${HERMETIC_TEST_LOADER_ARGS}
814852 $<TARGET_FILE:${fq_build_target_name} > ${HERMETIC_TEST_ARGS} )
853+ endif ()
854+
815855 add_custom_target (
816856 ${fq_target_name}
817857 DEPENDS ${fq_target_name} .__cmd__
@@ -863,7 +903,9 @@ function(add_libc_test test_name)
863903 # Tests like the file tests perform file operations on disk file. If we
864904 # don't chain up the unit test and hermetic test, then those tests will
865905 # step on each other's files.
866- add_dependencies (${fq_test_name} .__hermetic__ ${fq_test_name} .__unit__)
906+ if (NOT LIBC_TEST_HERMETIC_ONLY)
907+ add_dependencies (${fq_test_name} .__hermetic__ ${fq_test_name} .__unit__)
908+ endif ()
867909 endif ()
868910 endif ()
869911endfunction (add_libc_test)
0 commit comments