Skip to content

[libc] Fix issue with using clock() in hermetic testing #146069

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
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion libc/test/UnitTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function(add_unittest_framework_library name)
${TEST_LIB_HDRS}
)
target_include_directories(${lib} PRIVATE ${LIBC_SOURCE_DIR})
if(TARGET libc.src.time.clock)
if(TARGET libc.src.time.${LIBC_TARGET_OS}.clock)
target_compile_definitions(${lib} PRIVATE TARGET_SUPPORTS_CLOCK)
endif()
endforeach()
Expand Down
3 changes: 3 additions & 0 deletions libc/test/UnitTest/LibcTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include "src/time/clock.h"
extern "C" clock_t clock() noexcept { return LIBC_NAMESPACE::clock(); }
#define LIBC_TEST_USE_CLOCK
#else
#include <time.h>
extern "C" [[gnu::weak]] clock_t clock() noexcept { return 0; }
#endif

namespace LIBC_NAMESPACE_DECL {
Expand Down
Loading