Skip to content

Commit 56224a8

Browse files
bassiounixYilin Li
authored and
Yilin Li
committed
[libc][test] make str_to_float_comparison_test independent of C++ headers. (llvm#133978)
This is an attempt to move away from C++ headers to be able to run the test without `libcxx`. closes llvm#129838 cc @lntue @RossComputerGuy
1 parent a26efd3 commit 56224a8

File tree

3 files changed

+207
-143
lines changed

3 files changed

+207
-143
lines changed

libc/cmake/modules/LLVMLibCTestRules.cmake

+30-22
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ endfunction(get_object_files_for_test)
191191
# SRCS <list of .cpp files for the test>
192192
# HDRS <list of .h files for the test>
193193
# DEPENDS <list of dependencies>
194+
# ENV <list of environment variables to set before running the test>
194195
# COMPILE_OPTIONS <list of special compile options for this target>
195196
# LINK_LIBRARIES <list of linking libraries for this target>
196197
# )
@@ -203,7 +204,7 @@ function(create_libc_unittest fq_target_name)
203204
"LIBC_UNITTEST"
204205
"NO_RUN_POSTBUILD;C_TEST" # Optional arguments
205206
"SUITE;CXX_STANDARD" # Single value arguments
206-
"SRCS;HDRS;DEPENDS;COMPILE_OPTIONS;LINK_LIBRARIES;FLAGS" # Multi-value arguments
207+
"SRCS;HDRS;DEPENDS;ENV;COMPILE_OPTIONS;LINK_LIBRARIES;FLAGS" # Multi-value arguments
207208
${ARGN}
208209
)
209210
if(NOT LIBC_UNITTEST_SRCS)
@@ -319,7 +320,7 @@ function(create_libc_unittest fq_target_name)
319320
if(NOT LIBC_UNITTEST_NO_RUN_POSTBUILD)
320321
add_custom_target(
321322
${fq_target_name}
322-
COMMAND ${fq_build_target_name}
323+
COMMAND ${LIBC_UNITTEST_ENV} ${CMAKE_CROSSCOMPILING_EMULATOR} ${fq_build_target_name}
323324
COMMENT "Running unit test ${fq_target_name}"
324325
)
325326
endif()
@@ -642,7 +643,7 @@ function(add_libc_hermetic test_name)
642643
endif()
643644
cmake_parse_arguments(
644645
"HERMETIC_TEST"
645-
"IS_GPU_BENCHMARK" # Optional arguments
646+
"IS_GPU_BENCHMARK;NO_RUN_POSTBUILD" # Optional arguments
646647
"SUITE;CXX_STANDARD" # Single value arguments
647648
"SRCS;HDRS;DEPENDS;ARGS;ENV;COMPILE_OPTIONS;LINK_LIBRARIES;LOADER_ARGS" # Multi-value arguments
648649
${ARGN}
@@ -713,7 +714,12 @@ function(add_libc_hermetic test_name)
713714
set_target_properties(${fq_target_name}.__libc__
714715
PROPERTIES ARCHIVE_OUTPUT_NAME ${fq_target_name}.libc)
715716

716-
set(fq_build_target_name ${fq_target_name}.__build__)
717+
if(HERMETIC_TEST_NO_RUN_POSTBUILD)
718+
set(fq_build_target_name ${fq_target_name})
719+
else()
720+
set(fq_build_target_name ${fq_target_name}.__build__)
721+
endif()
722+
717723
add_executable(
718724
${fq_build_target_name}
719725
EXCLUDE_FROM_ALL
@@ -794,26 +800,28 @@ function(add_libc_hermetic test_name)
794800
get_target_property(gpu_loader_exe libc.utils.gpu.loader "EXECUTABLE")
795801
endif()
796802

797-
set(test_cmd ${HERMETIC_TEST_ENV}
798-
$<$<BOOL:${LIBC_TARGET_OS_IS_GPU}>:${gpu_loader_exe}> ${CMAKE_CROSSCOMPILING_EMULATOR} ${HERMETIC_TEST_LOADER_ARGS}
799-
$<TARGET_FILE:${fq_build_target_name}> ${HERMETIC_TEST_ARGS})
800-
add_custom_target(
801-
${fq_target_name}
802-
DEPENDS ${fq_target_name}-cmd
803-
)
803+
if(NOT HERMETIC_TEST_NO_RUN_POSTBUILD)
804+
set(test_cmd ${HERMETIC_TEST_ENV}
805+
$<$<BOOL:${LIBC_TARGET_OS_IS_GPU}>:${gpu_loader_exe}> ${CMAKE_CROSSCOMPILING_EMULATOR} ${HERMETIC_TEST_LOADER_ARGS}
806+
$<TARGET_FILE:${fq_build_target_name}> ${HERMETIC_TEST_ARGS})
807+
add_custom_target(
808+
${fq_target_name}
809+
DEPENDS ${fq_target_name}.__cmd__
810+
)
804811

805-
add_custom_command(
806-
OUTPUT ${fq_target_name}-cmd
807-
COMMAND ${test_cmd}
808-
COMMAND_EXPAND_LISTS
809-
COMMENT "Running hermetic test ${fq_target_name}"
810-
${LIBC_HERMETIC_TEST_JOB_POOL}
811-
)
812+
add_custom_command(
813+
OUTPUT ${fq_target_name}.__cmd__
814+
COMMAND ${test_cmd}
815+
COMMAND_EXPAND_LISTS
816+
COMMENT "Running hermetic test ${fq_target_name}"
817+
${LIBC_HERMETIC_TEST_JOB_POOL}
818+
)
812819

813-
set_source_files_properties(${fq_target_name}-cmd
814-
PROPERTIES
815-
SYMBOLIC "TRUE"
816-
)
820+
set_source_files_properties(${fq_target_name}.__cmd__
821+
PROPERTIES
822+
SYMBOLIC "TRUE"
823+
)
824+
endif()
817825

818826
add_dependencies(${HERMETIC_TEST_SUITE} ${fq_target_name})
819827
if(NOT ${HERMETIC_TEST_IS_GPU_BENCHMARK})

libc/test/src/__support/CMakeLists.txt

+18-25
Original file line numberDiff line numberDiff line change
@@ -249,32 +249,25 @@ add_libc_test(
249249
libc.src.__support.memory_size
250250
)
251251

252-
# FIXME: We shouldn't have regular executables created because we could be
253-
# cross-compiling the tests and running through an emulator.
254-
if(NOT LIBC_TARGET_OS_IS_GPU)
255-
add_executable(
256-
libc_str_to_float_comparison_test
257-
str_to_float_comparison_test.cpp
258-
)
259-
260-
target_link_libraries(libc_str_to_float_comparison_test
261-
PRIVATE
262-
"${LIBC_TARGET}"
263-
)
264-
265-
add_executable(
266-
libc_system_str_to_float_comparison_test
252+
add_libc_test(
253+
str_to_float_comparison_test
254+
NO_RUN_POSTBUILD
255+
SUITE
256+
libc-support-tests
257+
SRCS
267258
str_to_float_comparison_test.cpp
268-
)
269-
270-
set(float_test_file ${CMAKE_CURRENT_SOURCE_DIR}/str_to_float_comparison_data.txt)
271-
272-
add_custom_command(TARGET libc_str_to_float_comparison_test
273-
POST_BUILD
274-
COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:libc_str_to_float_comparison_test> ${float_test_file}
275-
COMMENT "Test the strtof and strtod implementations against precomputed results."
276-
VERBATIM)
277-
endif()
259+
DEPENDS
260+
libc.src.stdio.printf
261+
libc.src.stdio.fopen
262+
libc.src.stdio.fclose
263+
libc.src.stdio.fgets
264+
libc.src.stdlib.strtof
265+
libc.src.stdlib.strtod
266+
libc.src.stdlib.getenv
267+
libc.src.string.strtok
268+
libc.src.string.strdup
269+
libc.src.__support.CPP.bit
270+
)
278271

279272
add_subdirectory(CPP)
280273
add_subdirectory(File)

0 commit comments

Comments
 (0)