Skip to content

Commit 2cbda75

Browse files
committed
Remove extra C functions in LibcTest.cpp, HermeticTestUtils.cpp, and test.cpp
that are not needed anymore.
1 parent d86f998 commit 2cbda75

File tree

4 files changed

+12
-90
lines changed

4 files changed

+12
-90
lines changed

libc/test/IntegrationTest/test.cpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,6 @@
99
#include <stddef.h>
1010
#include <stdint.h>
1111

12-
// Integration tests rely on the following memory functions. This is because the
13-
// compiler code generation can emit calls to them. We want to map the external
14-
// entrypoint to the internal implementation of the function used for testing.
15-
// This is done manually as not all targets support aliases.
16-
17-
namespace LIBC_NAMESPACE {
18-
19-
int bcmp(const void *lhs, const void *rhs, size_t count);
20-
void bzero(void *ptr, size_t count);
21-
int memcmp(const void *lhs, const void *rhs, size_t count);
22-
void *memcpy(void *__restrict, const void *__restrict, size_t);
23-
void *memmove(void *dst, const void *src, size_t count);
24-
void *memset(void *ptr, int value, size_t count);
25-
int atexit(void (*func)(void));
26-
27-
} // namespace LIBC_NAMESPACE
28-
29-
extern "C" {
30-
31-
int bcmp(const void *lhs, const void *rhs, size_t count) {
32-
return LIBC_NAMESPACE::bcmp(lhs, rhs, count);
33-
}
34-
void bzero(void *ptr, size_t count) { LIBC_NAMESPACE::bzero(ptr, count); }
35-
int memcmp(const void *lhs, const void *rhs, size_t count) {
36-
return LIBC_NAMESPACE::memcmp(lhs, rhs, count);
37-
}
38-
void *memcpy(void *__restrict dst, const void *__restrict src, size_t count) {
39-
return LIBC_NAMESPACE::memcpy(dst, src, count);
40-
}
41-
void *memmove(void *dst, const void *src, size_t count) {
42-
return LIBC_NAMESPACE::memmove(dst, src, count);
43-
}
44-
void *memset(void *ptr, int value, size_t count) {
45-
return LIBC_NAMESPACE::memset(ptr, value, count);
46-
}
47-
48-
// This is needed if the test was compiled with '-fno-use-cxa-atexit'.
49-
int atexit(void (*func)(void)) { return LIBC_NAMESPACE::atexit(func); }
50-
51-
} // extern "C"
52-
5312
// Integration tests cannot use the SCUDO standalone allocator as SCUDO pulls
5413
// various other parts of the libc. Since SCUDO development does not use
5514
// LLVM libc build rules, it is very hard to keep track or pull all that SCUDO

libc/test/UnitTest/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ function(add_unittest_framework_library name)
1818
set(library_type STATIC)
1919
endif()
2020

21+
set(clock_target "")
22+
if(TARGET libc.src.time.clock)
23+
set(clock_target libc.src.time.clock)
24+
endif()
25+
2126
foreach(lib IN ITEMS ${name}.unit ${name}.hermetic)
2227
add_library(
2328
${lib}
@@ -28,7 +33,7 @@ function(add_unittest_framework_library name)
2833
)
2934
target_include_directories(${lib} PUBLIC ${LIBC_SOURCE_DIR})
3035
target_compile_options(${lib} PRIVATE -fno-exceptions -fno-rtti)
31-
if(TARGET libc.src.time.clock)
36+
if(${clock_target})
3237
target_compile_definitions(${lib} PRIVATE TARGET_SUPPORTS_CLOCK)
3338
endif()
3439
endforeach()
@@ -70,6 +75,7 @@ add_unittest_framework_library(
7075
libc.src.__support.CPP.type_traits
7176
libc.src.__support.OSUtil.osutil
7277
libc.src.__support.uint128
78+
${clock_target}
7379
)
7480

7581
set(libc_death_test_srcs LibcDeathTestExecutors.cpp)
@@ -114,6 +120,7 @@ add_unittest_framework_library(
114120
libc.src.__support.FPUtil.fpbits_str
115121
libc.src.__support.FPUtil.fenv_impl
116122
libc.src.__support.FPUtil.rounding_mode
123+
libc.src.errno.errno
117124
)
118125

119126
add_unittest_framework_library(

libc/test/UnitTest/HermeticTestUtils.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@
99
#include <stddef.h>
1010
#include <stdint.h>
1111

12-
namespace LIBC_NAMESPACE {
13-
14-
int bcmp(const void *lhs, const void *rhs, size_t count);
15-
void bzero(void *ptr, size_t count);
16-
int memcmp(const void *lhs, const void *rhs, size_t count);
17-
void *memcpy(void *__restrict, const void *__restrict, size_t);
18-
void *memmove(void *dst, const void *src, size_t count);
19-
void *memset(void *ptr, int value, size_t count);
20-
int atexit(void (*func)(void));
21-
22-
} // namespace LIBC_NAMESPACE
23-
2412
namespace {
2513

2614
// Integration tests cannot use the SCUDO standalone allocator as SCUDO pulls
@@ -37,31 +25,6 @@ static uint8_t *ptr = memory;
3725

3826
extern "C" {
3927

40-
// Hermetic tests rely on the following memory functions. This is because the
41-
// compiler code generation can emit calls to them. We want to map the external
42-
// entrypoint to the internal implementation of the function used for testing.
43-
// This is done manually as not all targets support aliases.
44-
45-
int bcmp(const void *lhs, const void *rhs, size_t count) {
46-
return LIBC_NAMESPACE::bcmp(lhs, rhs, count);
47-
}
48-
void bzero(void *ptr, size_t count) { LIBC_NAMESPACE::bzero(ptr, count); }
49-
int memcmp(const void *lhs, const void *rhs, size_t count) {
50-
return LIBC_NAMESPACE::memcmp(lhs, rhs, count);
51-
}
52-
void *memcpy(void *__restrict dst, const void *__restrict src, size_t count) {
53-
return LIBC_NAMESPACE::memcpy(dst, src, count);
54-
}
55-
void *memmove(void *dst, const void *src, size_t count) {
56-
return LIBC_NAMESPACE::memmove(dst, src, count);
57-
}
58-
void *memset(void *ptr, int value, size_t count) {
59-
return LIBC_NAMESPACE::memset(ptr, value, count);
60-
}
61-
62-
// This is needed if the test was compiled with '-fno-use-cxa-atexit'.
63-
int atexit(void (*func)(void)) { return LIBC_NAMESPACE::atexit(func); }
64-
6528
constexpr uint64_t ALIGNMENT = alignof(uintptr_t);
6629

6730
void *malloc(size_t s) {

libc/test/UnitTest/LibcTest.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,6 @@
1313
#include "src/__support/UInt128.h"
1414
#include "test/UnitTest/TestLogger.h"
1515

16-
#if __STDC_HOSTED__
17-
#include <time.h>
18-
#define LIBC_TEST_USE_CLOCK
19-
#elif defined(TARGET_SUPPORTS_CLOCK)
20-
#include <time.h>
21-
22-
#include "src/time/clock.h"
23-
extern "C" clock_t clock() noexcept { return LIBC_NAMESPACE::clock(); }
24-
#define LIBC_TEST_USE_CLOCK
25-
#endif
26-
2716
namespace LIBC_NAMESPACE {
2817
namespace testing {
2918

@@ -126,13 +115,17 @@ int Test::runTests(const char *TestFilter) {
126115
continue;
127116
}
128117
tlog << GREEN << "[ RUN ] " << RESET << TestName << '\n';
118+
#ifdef LIBC_TEST_USE_CLOCK
129119
[[maybe_unused]] const auto start_time = clock();
120+
#endif
130121
RunContext Ctx;
131122
T->SetUp();
132123
T->setContext(&Ctx);
133124
T->Run();
134125
T->TearDown();
126+
#ifdef LIBC_TEST_USE_CLOCK
135127
[[maybe_unused]] const auto end_time = clock();
128+
#endif // LIBC_TEST_USE_CLOCK
136129
switch (Ctx.status()) {
137130
case RunContext::RunResult::Fail:
138131
tlog << RED << "[ FAILED ] " << RESET << TestName << '\n';

0 commit comments

Comments
 (0)