[libc] Compile integration tests with -ffreestanding to avoid mixup with system libc.

This commit is contained in:
Siva Chandra Reddy 2022-07-30 01:37:55 +00:00
parent fb7fa27f92
commit 12df3080fe
17 changed files with 31 additions and 15 deletions

View File

@ -486,6 +486,7 @@ function(add_integration_test test_name)
${LIBC_BUILD_DIR}
${LIBC_BUILD_DIR}/include
)
target_compile_options(${fq_target_name} PRIVATE -ffreestanding)
# We set a number of link options to prevent picking up system libc binaries.
# Also, we restrict the integration tests to fully static executables. The
# rtlib is set to compiler-rt to make the compiler drivers pick up the compiler

View File

@ -17,7 +17,7 @@ static bool my_streq(const char *lhs, const char *rhs) {
return *l == '\0' && *r == '\0';
}
int main(int argc, char **argv, char **envp) {
TEST_MAIN(int argc, char **argv, char **envp) {
ASSERT_TRUE(argc == 4);
ASSERT_TRUE(my_streq(argv[1], "1"));
ASSERT_TRUE(my_streq(argv[2], "2"));

View File

@ -6,4 +6,6 @@
//
//===----------------------------------------------------------------------===//
int main() { return 0; }
#include "utils/IntegrationTest/test.h"
TEST_MAIN() { return 0; }

View File

@ -6,4 +6,6 @@
//
//===----------------------------------------------------------------------===//
int main(int argc, char **argv) { return 0; }
#include "utils/IntegrationTest/test.h"
TEST_MAIN(int argc, char **argv) { return 0; }

View File

@ -16,7 +16,7 @@
constexpr int threadLocalDataSize = 101;
_Thread_local int a[threadLocalDataSize] = {123};
int main(int argc, char **argv, char **envp) {
TEST_MAIN(int argc, char **argv, char **envp) {
ASSERT_TRUE(a[0] == 123);
for (int i = 1; i < threadLocalDataSize; ++i)

View File

@ -50,7 +50,7 @@ void detach_cleanup_test() {
ASSERT_EQ(th.detach(), int(__llvm_libc::DetachType::CLEANUP));
}
int main() {
TEST_MAIN() {
detach_simple_test();
detach_cleanup_test();
return 0;

View File

@ -35,7 +35,7 @@ void thread_local_test() {
ASSERT_EQ(retval, INIT_VAL);
}
int main() {
TEST_MAIN() {
// From the main thread, we will update the main thread's tlval.
// This should not affect the child thread's tlval;
ASSERT_EQ(tlval, INIT_VAL);

View File

@ -31,7 +31,7 @@ static void *child_func(void *arg) {
return nullptr;
}
int main() {
TEST_MAIN() {
// We init and lock the mutex so that we guarantee that the child thread is
// waiting after startup.
ASSERT_EQ(__llvm_libc::pthread_mutex_init(&mutex, nullptr), 0);

View File

@ -185,7 +185,7 @@ void multiple_waiters() {
__llvm_libc::pthread_mutex_destroy(&counter_lock);
}
int main() {
TEST_MAIN() {
relay_counter();
wait_and_step();
multiple_waiters();

View File

@ -55,7 +55,7 @@ void spawn_and_join() {
}
}
int main() {
TEST_MAIN() {
create_and_join();
spawn_and_join();
return 0;

View File

@ -27,7 +27,7 @@ static bool my_streq(const char *lhs, const char *rhs) {
return *l == '\0' && *r == '\0';
}
int main(int argc, char **argv, char **envp) {
TEST_MAIN(int argc, char **argv, char **envp) {
ASSERT_TRUE(my_streq(__llvm_libc::getenv(""), static_cast<char *>(nullptr)));
ASSERT_TRUE(my_streq(__llvm_libc::getenv("="), static_cast<char *>(nullptr)));
ASSERT_TRUE(my_streq(__llvm_libc::getenv("MISSING ENV VARIABLE"),

View File

@ -114,7 +114,7 @@ void test_synchronization() {
__llvm_libc::mtx_destroy(&once_func_blocker);
}
int main() {
TEST_MAIN() {
call_from_5_threads();
test_synchronization();
return 0;

View File

@ -145,7 +145,7 @@ void single_waiter_test() {
} // namespace single_waiter_test
int main() {
TEST_MAIN() {
wait_notify_broadcast_test::wait_notify_broadcast_test();
single_waiter_test::single_waiter_test();
return 0;

View File

@ -192,7 +192,7 @@ void multiple_waiters() {
__llvm_libc::mtx_destroy(&counter_lock);
}
int main() {
TEST_MAIN() {
relay_counter();
wait_and_step();
multiple_waiters();

View File

@ -31,7 +31,7 @@ static int child_func(void *arg) {
return 0;
}
int main() {
TEST_MAIN() {
// We init and lock the mutex so that we guarantee that the child thread is
// waiting after startup.
ASSERT_EQ(__llvm_libc::mtx_init(&mutex, mtx_plain), int(thrd_success));

View File

@ -53,7 +53,8 @@ void spawn_and_join() {
}
}
int main() {
TEST_MAIN() {
create_and_join();
spawn_and_join();
return 0;
}

View File

@ -58,4 +58,14 @@
#define ASSERT_NE(val1, val2) \
__CHECK_NE(__FILE__, __LINE__, (val1), (val2), true)
// Integration tests are compiled with -ffreestanding which stops treating
// the main function as a non-overloadable special function. Hence, we use a
// convenience macro which declares it 'extern "C"'.
//
// When we are able to reuse the unit test infrastructure for integration
// tests, then we should not need to explicitly declare/define the main
// function in individual integration tests. We will not need this macro
// then.
#define TEST_MAIN extern "C" int main
#endif // LLVM_LIBC_UTILS_INTEGRATION_TEST_TEST_H