forked from OSchip/llvm-project
[libc][NFC] Convert threads unittests in to integration tests.
This is mostly a mechanical change. In a future pass, all tests from pthread which create threads will also be converted to integration tests. Some of thread related features are tightly coupled with the loader. So, they can only be tested with the in-house loader. Hence, going forward, all tests which create threads will have to be integration tests. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D128381
This commit is contained in:
parent
95733a55b9
commit
d5475af2f7
|
@ -1,5 +1,10 @@
|
|||
add_custom_target(libc-integration-tests)
|
||||
|
||||
function(add_libc_integration_test_suite name)
|
||||
add_custom_target(${name})
|
||||
add_dependencies(libc-integration-tests ${name})
|
||||
endfunction()
|
||||
|
||||
add_library(
|
||||
libc_integration_test_dummy
|
||||
STATIC
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
add_subdirectory(stdlib)
|
||||
add_subdirectory(threads)
|
||||
|
|
|
@ -1,11 +1,47 @@
|
|||
add_libc_testsuite(libc_threads_unittests)
|
||||
add_libc_integration_test_suite(libc-threads-integration-tests)
|
||||
|
||||
add_libc_unittest(
|
||||
add_integration_test(
|
||||
mtx_test
|
||||
SUITE
|
||||
libc-threads-integration-tests
|
||||
SRCS
|
||||
mtx_test.cpp
|
||||
LOADER
|
||||
libc.loader.linux.crt1
|
||||
DEPENDS
|
||||
libc.include.threads
|
||||
libc.src.errno.errno
|
||||
libc.src.threads.mtx_destroy
|
||||
libc.src.threads.mtx_init
|
||||
libc.src.threads.mtx_lock
|
||||
libc.src.threads.mtx_unlock
|
||||
libc.src.threads.thrd_create
|
||||
libc.src.threads.thrd_join
|
||||
)
|
||||
|
||||
add_integration_test(
|
||||
thrd_test
|
||||
SUITE
|
||||
libc-threads-integration-tests
|
||||
SRCS
|
||||
thrd_test.cpp
|
||||
LOADER
|
||||
libc.loader.linux.crt1
|
||||
DEPENDS
|
||||
libc.include.threads
|
||||
libc.src.errno.errno
|
||||
libc.src.threads.thrd_create
|
||||
libc.src.threads.thrd_join
|
||||
)
|
||||
|
||||
add_integration_test(
|
||||
call_once_test
|
||||
SUITE
|
||||
libc_threads_unittests
|
||||
libc-threads-integration-tests
|
||||
SRCS
|
||||
call_once_test.cpp
|
||||
LOADER
|
||||
libc.loader.linux.crt1
|
||||
DEPENDS
|
||||
libc.include.threads
|
||||
libc.src.threads.call_once
|
||||
|
@ -18,42 +54,14 @@ add_libc_unittest(
|
|||
libc.src.__support.CPP.atomic
|
||||
)
|
||||
|
||||
add_libc_unittest(
|
||||
thrd_test
|
||||
SUITE
|
||||
libc_threads_unittests
|
||||
SRCS
|
||||
thrd_test.cpp
|
||||
DEPENDS
|
||||
libc.include.threads
|
||||
libc.src.errno.errno
|
||||
libc.src.threads.thrd_create
|
||||
libc.src.threads.thrd_join
|
||||
)
|
||||
|
||||
add_libc_unittest(
|
||||
mtx_test
|
||||
SUITE
|
||||
libc_threads_unittests
|
||||
SRCS
|
||||
mtx_test.cpp
|
||||
DEPENDS
|
||||
libc.include.threads
|
||||
libc.src.errno.errno
|
||||
libc.src.threads.mtx_destroy
|
||||
libc.src.threads.mtx_init
|
||||
libc.src.threads.mtx_lock
|
||||
libc.src.threads.mtx_unlock
|
||||
libc.src.threads.thrd_create
|
||||
libc.src.threads.thrd_join
|
||||
)
|
||||
|
||||
add_libc_unittest(
|
||||
add_integration_test(
|
||||
cnd_test
|
||||
SUITE
|
||||
libc_threads_unittests
|
||||
libc-threads-integration-tests
|
||||
SRCS
|
||||
cnd_test.cpp
|
||||
LOADER
|
||||
libc.loader.linux.crt1
|
||||
DEPENDS
|
||||
libc.include.threads
|
||||
libc.src.threads.cnd_init
|
|
@ -1,4 +1,4 @@
|
|||
//===-- Unittests for call_once -------------------------------------------===//
|
||||
//===-- Tests for call_once -----------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
|
@ -6,7 +6,6 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "include/threads.h"
|
||||
#include "src/__support/CPP/atomic.h"
|
||||
#include "src/threads/call_once.h"
|
||||
#include "src/threads/mtx_destroy.h"
|
||||
|
@ -15,7 +14,10 @@
|
|||
#include "src/threads/mtx_unlock.h"
|
||||
#include "src/threads/thrd_create.h"
|
||||
#include "src/threads/thrd_join.h"
|
||||
#include "utils/UnitTest/Test.h"
|
||||
|
||||
#include "utils/IntegrationTest/test.h"
|
||||
|
||||
#include <threads.h>
|
||||
|
||||
static constexpr unsigned int NUM_THREADS = 5;
|
||||
static __llvm_libc::cpp::Atomic<unsigned int> thread_count;
|
||||
|
@ -32,7 +34,7 @@ static int func(void *) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
TEST(LlvmLibcCallOnceTest, CallFrom5Threads) {
|
||||
void call_from_5_threads() {
|
||||
// Ensure the call count and thread count are 0 to begin with.
|
||||
call_count = 0;
|
||||
thread_count = 0;
|
||||
|
@ -73,7 +75,7 @@ static int once_func_caller(void *) {
|
|||
// Test the synchronization aspect of the call_once function.
|
||||
// This is not a fool proof test, but something which might be
|
||||
// useful when we add a flakiness detection scheme to UnitTest.
|
||||
TEST(LlvmLibcCallOnceTest, TestSynchronization) {
|
||||
void test_synchronization() {
|
||||
start_count = 0;
|
||||
done_count = 0;
|
||||
|
||||
|
@ -111,3 +113,9 @@ TEST(LlvmLibcCallOnceTest, TestSynchronization) {
|
|||
|
||||
__llvm_libc::mtx_destroy(&once_func_blocker);
|
||||
}
|
||||
|
||||
int main() {
|
||||
call_from_5_threads();
|
||||
test_synchronization();
|
||||
return 0;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
//===-- Unittests for condition variable broadcast fucntionality ----------===//
|
||||
//===-- Tests for standard condition variables ----------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
|
@ -6,7 +6,6 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "include/threads.h"
|
||||
#include "src/__support/CPP/atomic.h"
|
||||
#include "src/threads/cnd_broadcast.h"
|
||||
#include "src/threads/cnd_destroy.h"
|
||||
|
@ -19,7 +18,10 @@
|
|||
#include "src/threads/mtx_unlock.h"
|
||||
#include "src/threads/thrd_create.h"
|
||||
#include "src/threads/thrd_join.h"
|
||||
#include "utils/UnitTest/Test.h"
|
||||
|
||||
#include "utils/IntegrationTest/test.h"
|
||||
|
||||
#include <threads.h>
|
||||
|
||||
namespace wait_notify_broadcast_test {
|
||||
|
||||
|
@ -54,7 +56,7 @@ int broadcast_thread_func(void *) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
TEST(LlvmLibcCndVarTest, WaitNotifyBroadcastTest) {
|
||||
void wait_notify_broadcast_test() {
|
||||
__llvm_libc::cnd_init(&broadcast_cnd);
|
||||
__llvm_libc::cnd_init(&threads_ready_cnd);
|
||||
__llvm_libc::mtx_init(&broadcast_mtx, mtx_plain);
|
||||
|
@ -111,7 +113,7 @@ int waiter_thread_func(void *unused) {
|
|||
return 0x600D;
|
||||
}
|
||||
|
||||
TEST(LlvmLibcCndVarTest, SingleWaiterTest) {
|
||||
void single_waiter_test() {
|
||||
ASSERT_EQ(__llvm_libc::mtx_init(&waiter_mtx, mtx_plain), int(thrd_success));
|
||||
ASSERT_EQ(__llvm_libc::mtx_init(&main_thread_mtx, mtx_plain),
|
||||
int(thrd_success));
|
||||
|
@ -142,3 +144,9 @@ TEST(LlvmLibcCndVarTest, SingleWaiterTest) {
|
|||
}
|
||||
|
||||
} // namespace single_waiter_test
|
||||
|
||||
int main() {
|
||||
wait_notify_broadcast_test::wait_notify_broadcast_test();
|
||||
single_waiter_test::single_waiter_test();
|
||||
return 0;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
//===-- Unittests for mtx_t -----------------------------------------------===//
|
||||
//===-- Tests for mtx_t operations ----------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
|
@ -6,14 +6,16 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "include/threads.h"
|
||||
#include "src/threads/mtx_destroy.h"
|
||||
#include "src/threads/mtx_init.h"
|
||||
#include "src/threads/mtx_lock.h"
|
||||
#include "src/threads/mtx_unlock.h"
|
||||
#include "src/threads/thrd_create.h"
|
||||
#include "src/threads/thrd_join.h"
|
||||
#include "utils/UnitTest/Test.h"
|
||||
|
||||
#include "utils/IntegrationTest/test.h"
|
||||
|
||||
#include <threads.h>
|
||||
|
||||
constexpr int START = 0;
|
||||
constexpr int MAX = 10000;
|
||||
|
@ -36,7 +38,7 @@ int counter(void *arg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
TEST(LlvmLibcMutexTest, RelayCounter) {
|
||||
void relay_counter() {
|
||||
ASSERT_EQ(__llvm_libc::mtx_init(&mutex, mtx_plain),
|
||||
static_cast<int>(thrd_success));
|
||||
|
||||
|
@ -82,7 +84,7 @@ int stepper(void *arg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
TEST(LlvmLibcMutexTest, WaitAndStep) {
|
||||
void wait_and_step() {
|
||||
ASSERT_EQ(__llvm_libc::mtx_init(&start_lock, mtx_plain),
|
||||
static_cast<int>(thrd_success));
|
||||
ASSERT_EQ(__llvm_libc::mtx_init(&step_lock, mtx_plain),
|
||||
|
@ -156,7 +158,7 @@ int waiter_func(void *) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
TEST(LlvmLibcMutexTest, MultipleWaiters) {
|
||||
void multiple_waiters() {
|
||||
__llvm_libc::mtx_init(&multiple_waiter_lock, mtx_plain);
|
||||
__llvm_libc::mtx_init(&counter_lock, mtx_plain);
|
||||
|
||||
|
@ -189,3 +191,10 @@ TEST(LlvmLibcMutexTest, MultipleWaiters) {
|
|||
__llvm_libc::mtx_destroy(&multiple_waiter_lock);
|
||||
__llvm_libc::mtx_destroy(&counter_lock);
|
||||
}
|
||||
|
||||
int main() {
|
||||
relay_counter();
|
||||
wait_and_step();
|
||||
multiple_waiters();
|
||||
return 0;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
//===-- Unittests for thrd_t ----------------------------------------------===//
|
||||
//===-- Tests for thrd_t creation and joining -----------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
|
@ -6,10 +6,12 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "include/threads.h"
|
||||
#include "src/threads/thrd_create.h"
|
||||
#include "src/threads/thrd_join.h"
|
||||
#include "utils/UnitTest/Test.h"
|
||||
|
||||
#include "utils/IntegrationTest/test.h"
|
||||
|
||||
#include <threads.h>
|
||||
|
||||
static constexpr int thread_count = 1000;
|
||||
static int counter = 0;
|
||||
|
@ -18,7 +20,7 @@ static int thread_func(void *) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
TEST(LlvmLibcThreadTest, CreateAndJoin) {
|
||||
void create_and_join() {
|
||||
for (counter = 0; counter <= thread_count;) {
|
||||
thrd_t thread;
|
||||
int old_counter_val = counter;
|
||||
|
@ -33,7 +35,7 @@ TEST(LlvmLibcThreadTest, CreateAndJoin) {
|
|||
|
||||
static int return_arg(void *arg) { return *reinterpret_cast<int *>(arg); }
|
||||
|
||||
TEST(LlvmLibcThreadTest, SpawnAndJoin) {
|
||||
void spawn_and_join() {
|
||||
thrd_t thread_list[thread_count];
|
||||
int args[thread_count];
|
||||
|
||||
|
@ -50,3 +52,8 @@ TEST(LlvmLibcThreadTest, SpawnAndJoin) {
|
|||
ASSERT_EQ(retval, i);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
create_and_join();
|
||||
spawn_and_join();
|
||||
}
|
|
@ -50,7 +50,6 @@ endif()
|
|||
# add_subdirectory(assert)
|
||||
# add_subdirectory(signal)
|
||||
add_subdirectory(stdio)
|
||||
add_subdirectory(threads)
|
||||
add_subdirectory(time)
|
||||
|
||||
if(${LIBC_TARGET_OS} STREQUAL "linux")
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "src/__support/OSUtil/quick_exit.h"
|
||||
|
||||
#define __AS_STRING(val) #val
|
||||
#define __CHECK(file, line, val, should_exit) \
|
||||
#define __CHECK_TRUE(file, line, val, should_exit) \
|
||||
if (!(val)) { \
|
||||
__llvm_libc::write_to_stderr(file ":" __AS_STRING( \
|
||||
line) ": Expected '" #val "' to be true, but is false\n"); \
|
||||
|
@ -21,17 +21,41 @@
|
|||
__llvm_libc::quick_exit(127); \
|
||||
}
|
||||
|
||||
#define __CHECK_NE(file, line, val, should_exit) \
|
||||
if ((val)) { \
|
||||
#define __CHECK_FALSE(file, line, val, should_exit) \
|
||||
if (val) { \
|
||||
__llvm_libc::write_to_stderr(file ":" __AS_STRING( \
|
||||
line) ": Expected '" #val "' to be false, but is true\n"); \
|
||||
if (should_exit) \
|
||||
__llvm_libc::quick_exit(127); \
|
||||
}
|
||||
|
||||
#define EXPECT_TRUE(val) __CHECK(__FILE__, __LINE__, val, false)
|
||||
#define ASSERT_TRUE(val) __CHECK(__FILE__, __LINE__, val, true)
|
||||
#define EXPECT_FALSE(val) __CHECK_NE(__FILE__, __LINE__, val, false)
|
||||
#define ASSERT_FALSE(val) __CHECK_NE(__FILE__, __LINE__, val, true)
|
||||
#define __CHECK_EQ(file, line, val1, val2, should_exit) \
|
||||
if ((val1) != (val2)) { \
|
||||
__llvm_libc::write_to_stderr(file ":" __AS_STRING( \
|
||||
line) ": Expected '" #val1 "' to be equal to '" #val2 "'\n"); \
|
||||
if (should_exit) \
|
||||
__llvm_libc::quick_exit(127); \
|
||||
}
|
||||
|
||||
#define __CHECK_NE(file, line, val1, val2, should_exit) \
|
||||
if ((val1) == (val2)) { \
|
||||
__llvm_libc::write_to_stderr(file ":" __AS_STRING( \
|
||||
line) ": Expected '" #val1 "' to not be equal to '" #val2 "'\n"); \
|
||||
if (should_exit) \
|
||||
__llvm_libc::quick_exit(127); \
|
||||
}
|
||||
|
||||
#define EXPECT_TRUE(val) __CHECK_TRUE(__FILE__, __LINE__, val, false)
|
||||
#define ASSERT_TRUE(val) __CHECK_TRUE(__FILE__, __LINE__, val, true)
|
||||
#define EXPECT_FALSE(val) __CHECK_FALSE(__FILE__, __LINE__, val, false)
|
||||
#define ASSERT_FALSE(val) __CHECK_FALSE(__FILE__, __LINE__, val, true)
|
||||
#define EXPECT_EQ(val1, val2) \
|
||||
__CHECK_EQ(__FILE__, __LINE__, (val1), (val2), false)
|
||||
#define ASSERT_EQ(val1, val2) \
|
||||
__CHECK_EQ(__FILE__, __LINE__, (val1), (val2), true)
|
||||
#define EXPECT_NE(val1, val2) \
|
||||
__CHECK_NE(__FILE__, __LINE__, (val1), (val2), false)
|
||||
#define ASSERT_NE(val1, val2) \
|
||||
__CHECK_NE(__FILE__, __LINE__, (val1), (val2), true)
|
||||
|
||||
#endif // LLVM_LIBC_UTILS_INTEGRATION_TEST_TEST_H
|
||||
|
|
Loading…
Reference in New Issue