Skip to content
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

[libc][test] make str_to_float_comparison_test independent of C++ headers. #133978

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b645618
[libc][test] make test independent of C++ headers
bassiounix Apr 1, 2025
70ecf01
remove executable and convert to unit test
bassiounix Apr 1, 2025
6eb6fae
make test support more than one test file
bassiounix Apr 2, 2025
e0e77cd
remove unnecessary condition
bassiounix Apr 2, 2025
8154f3f
add `NO_RUN_POSTBUILD` to hermitic test
bassiounix Apr 2, 2025
bad7c0c
add `ENV` to unit test
bassiounix Apr 2, 2025
a0d1cff
fix target naming collision
bassiounix Apr 2, 2025
9c28f83
Merge branch 'main' into str_to_float_comparison_test/hermitic_test
bassiounix Apr 2, 2025
81b9a9c
fix argument name
bassiounix Apr 2, 2025
95d43fb
move `ENV` above `DEPENDS`
bassiounix Apr 2, 2025
10ddac3
remove GPU configs from unit test
bassiounix Apr 2, 2025
9cdff93
change cmd target name
bassiounix Apr 2, 2025
2ad8344
copy string to prevent env pointer manipulation
bassiounix Apr 4, 2025
d2c9f1b
Update LLVMLibCTestRules.cmake
bassiounix Apr 4, 2025
34b4f14
fix formatting
bassiounix Apr 5, 2025
7590cc7
remove unnecessary free operation
bassiounix Apr 5, 2025
0f481ed
remove unnecessary command
bassiounix Apr 5, 2025
0ab1f9d
fix: make test independent from file I/O
bassiounix Apr 5, 2025
ced0005
remove `FILES` env variable
bassiounix Apr 5, 2025
7194754
pack values to `ParseResult struct`
bassiounix Apr 5, 2025
bcd11e0
Add `ParseStatus` to parse operations
bassiounix Apr 5, 2025
c90a4da
mark `lines` array as `constexpr`
bassiounix Apr 7, 2025
73dd1f5
apply suggested changes
bassiounix Apr 9, 2025
b7edcfc
apply suggested changes
bassiounix Apr 9, 2025
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
52 changes: 30 additions & 22 deletions libc/cmake/modules/LLVMLibCTestRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ endfunction(get_object_files_for_test)
# SRCS <list of .cpp files for the test>
# HDRS <list of .h files for the test>
# DEPENDS <list of dependencies>
# ENV <list of environment variables to set before running the test>
# COMPILE_OPTIONS <list of special compile options for this target>
# LINK_LIBRARIES <list of linking libraries for this target>
# )
Expand All @@ -203,7 +204,7 @@ function(create_libc_unittest fq_target_name)
"LIBC_UNITTEST"
"NO_RUN_POSTBUILD;C_TEST" # Optional arguments
"SUITE;CXX_STANDARD" # Single value arguments
"SRCS;HDRS;DEPENDS;COMPILE_OPTIONS;LINK_LIBRARIES;FLAGS" # Multi-value arguments
"SRCS;HDRS;DEPENDS;ENV;COMPILE_OPTIONS;LINK_LIBRARIES;FLAGS" # Multi-value arguments
${ARGN}
)
if(NOT LIBC_UNITTEST_SRCS)
Expand Down Expand Up @@ -319,7 +320,7 @@ function(create_libc_unittest fq_target_name)
if(NOT LIBC_UNITTEST_NO_RUN_POSTBUILD)
add_custom_target(
${fq_target_name}
COMMAND ${fq_build_target_name}
COMMAND ${LIBC_UNITTEST_ENV} ${CMAKE_CROSSCOMPILING_EMULATOR} ${fq_build_target_name}
COMMENT "Running unit test ${fq_target_name}"
)
endif()
Expand Down Expand Up @@ -642,7 +643,7 @@ function(add_libc_hermetic test_name)
endif()
cmake_parse_arguments(
"HERMETIC_TEST"
"IS_GPU_BENCHMARK" # Optional arguments
"IS_GPU_BENCHMARK;NO_RUN_POSTBUILD" # Optional arguments
"SUITE;CXX_STANDARD" # Single value arguments
"SRCS;HDRS;DEPENDS;ARGS;ENV;COMPILE_OPTIONS;LINK_LIBRARIES;LOADER_ARGS" # Multi-value arguments
${ARGN}
Expand Down Expand Up @@ -713,7 +714,12 @@ function(add_libc_hermetic test_name)
set_target_properties(${fq_target_name}.__libc__
PROPERTIES ARCHIVE_OUTPUT_NAME ${fq_target_name}.libc)

set(fq_build_target_name ${fq_target_name}.__build__)
if(HERMETIC_TEST_NO_RUN_POSTBUILD)
set(fq_build_target_name ${fq_target_name})
else()
set(fq_build_target_name ${fq_target_name}.__build__)
endif()

add_executable(
${fq_build_target_name}
EXCLUDE_FROM_ALL
Expand Down Expand Up @@ -794,26 +800,28 @@ function(add_libc_hermetic test_name)
get_target_property(gpu_loader_exe libc.utils.gpu.loader "EXECUTABLE")
endif()

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})
add_custom_target(
${fq_target_name}
DEPENDS ${fq_target_name}-cmd
)
if(NOT HERMETIC_TEST_NO_RUN_POSTBUILD)
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})
add_custom_target(
${fq_target_name}
DEPENDS ${fq_target_name}.__cmd__
)

add_custom_command(
OUTPUT ${fq_target_name}-cmd
COMMAND ${test_cmd}
COMMAND_EXPAND_LISTS
COMMENT "Running hermetic test ${fq_target_name}"
${LIBC_HERMETIC_TEST_JOB_POOL}
)
add_custom_command(
OUTPUT ${fq_target_name}.__cmd__
COMMAND ${test_cmd}
COMMAND_EXPAND_LISTS
COMMENT "Running hermetic test ${fq_target_name}"
${LIBC_HERMETIC_TEST_JOB_POOL}
)

set_source_files_properties(${fq_target_name}-cmd
PROPERTIES
SYMBOLIC "TRUE"
)
set_source_files_properties(${fq_target_name}.__cmd__
PROPERTIES
SYMBOLIC "TRUE"
)
endif()

add_dependencies(${HERMETIC_TEST_SUITE} ${fq_target_name})
if(NOT ${HERMETIC_TEST_IS_GPU_BENCHMARK})
Expand Down
43 changes: 18 additions & 25 deletions libc/test/src/__support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,32 +249,25 @@ add_libc_test(
libc.src.__support.memory_size
)

# FIXME: We shouldn't have regular executables created because we could be
# cross-compiling the tests and running through an emulator.
if(NOT LIBC_TARGET_OS_IS_GPU)
add_executable(
libc_str_to_float_comparison_test
str_to_float_comparison_test.cpp
)

target_link_libraries(libc_str_to_float_comparison_test
PRIVATE
"${LIBC_TARGET}"
)

add_executable(
libc_system_str_to_float_comparison_test
add_libc_test(
str_to_float_comparison_test
NO_RUN_POSTBUILD
SUITE
libc-support-tests
SRCS
str_to_float_comparison_test.cpp
)

set(float_test_file ${CMAKE_CURRENT_SOURCE_DIR}/str_to_float_comparison_data.txt)

add_custom_command(TARGET libc_str_to_float_comparison_test
POST_BUILD
COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:libc_str_to_float_comparison_test> ${float_test_file}
COMMENT "Test the strtof and strtod implementations against precomputed results."
VERBATIM)
endif()
DEPENDS
libc.src.stdio.printf
libc.src.stdio.fopen
libc.src.stdio.fclose
libc.src.stdio.fgets
libc.src.stdlib.strtof
libc.src.stdlib.strtod
libc.src.stdlib.getenv
libc.src.string.strtok
libc.src.string.strdup
libc.src.__support.CPP.bit
)

add_subdirectory(CPP)
add_subdirectory(File)
Expand Down
Loading
Loading