[libc][NFC] Convert pthread tests which create threads to integration tests.
authorSiva Chandra Reddy <sivachandra@google.com>
Wed, 22 Jun 2022 22:51:26 +0000 (22:51 +0000)
committerSiva Chandra Reddy <sivachandra@google.com>
Thu, 23 Jun 2022 20:36:20 +0000 (20:36 +0000)
libc/test/integration/src/CMakeLists.txt
libc/test/integration/src/pthread/CMakeLists.txt [new file with mode: 0644]
libc/test/integration/src/pthread/pthread_mutex_test.cpp [moved from libc/test/src/pthread/pthread_mutex_test.cpp with 95% similarity]
libc/test/integration/src/pthread/pthread_test.cpp [moved from libc/test/src/pthread/pthread_test.cpp with 88% similarity]
libc/test/src/pthread/CMakeLists.txt

index 659e4b5..f175dc4 100644 (file)
@@ -1,2 +1,3 @@
+add_subdirectory(pthread)
 add_subdirectory(stdlib)
 add_subdirectory(threads)
diff --git a/libc/test/integration/src/pthread/CMakeLists.txt b/libc/test/integration/src/pthread/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0f52d8a
--- /dev/null
@@ -0,0 +1,34 @@
+add_libc_integration_test_suite(libc-pthread-integration-tests)
+
+add_integration_test(
+  pthread_mutex_test
+  SUITE
+    libc-pthread-integration-tests
+  SRCS
+    pthread_mutex_test.cpp
+  LOADER
+    libc.loader.linux.crt1
+  DEPENDS
+    libc.include.pthread
+    libc.src.errno.errno
+    libc.src.pthread.pthread_mutex_destroy
+    libc.src.pthread.pthread_mutex_init
+    libc.src.pthread.pthread_mutex_lock
+    libc.src.pthread.pthread_mutex_unlock
+    libc.src.pthread.pthread_create
+    libc.src.pthread.pthread_join
+)
+
+add_integration_test(
+  pthread_test
+  SUITE
+    libc-pthread-integration-tests
+  SRCS
+    pthread_test.cpp
+  LOADER
+    libc.loader.linux.crt1
+  DEPENDS
+    libc.include.pthread
+    libc.src.pthread.pthread_create
+    libc.src.pthread.pthread_join
+)
@@ -1,4 +1,4 @@
-//===-- Unittests for pthread_mutex_t -------------------------------------===//
+//===-- Tests for pthread_mutex_t -----------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -14,7 +14,7 @@
 #include "src/pthread/pthread_create.h"
 #include "src/pthread/pthread_join.h"
 
-#include "utils/UnitTest/Test.h"
+#include "utils/IntegrationTest/test.h"
 
 #include <pthread.h>
 
@@ -39,7 +39,7 @@ void *counter(void *arg) {
   return nullptr;
 }
 
-TEST(LlvmLibcMutexTest, RelayCounter) {
+void relay_counter() {
   ASSERT_EQ(__llvm_libc::pthread_mutex_init(&mutex, nullptr), 0);
 
   // The idea of this test is that two competing threads will update
@@ -84,7 +84,7 @@ void *stepper(void *arg) {
   return nullptr;
 }
 
-TEST(LlvmLibcMutexTest, WaitAndStep) {
+void wait_and_step() {
   ASSERT_EQ(__llvm_libc::pthread_mutex_init(&start_lock, nullptr), 0);
   ASSERT_EQ(__llvm_libc::pthread_mutex_init(&step_lock, nullptr), 0);
 
@@ -151,7 +151,7 @@ void *waiter_func(void *) {
   return nullptr;
 }
 
-TEST(LlvmLibcMutexTest, MultipleWaiters) {
+void multiple_waiters() {
   __llvm_libc::pthread_mutex_init(&multiple_waiter_lock, nullptr);
   __llvm_libc::pthread_mutex_init(&counter_lock, nullptr);
 
@@ -184,3 +184,10 @@ TEST(LlvmLibcMutexTest, MultipleWaiters) {
   __llvm_libc::pthread_mutex_destroy(&multiple_waiter_lock);
   __llvm_libc::pthread_mutex_destroy(&counter_lock);
 }
+
+int main() {
+  relay_counter();
+  wait_and_step();
+  multiple_waiters();
+  return 0;
+}
similarity index 88%
rename from libc/test/src/pthread/pthread_test.cpp
rename to libc/test/integration/src/pthread/pthread_test.cpp
index 3a3d587..f5be1c6 100644 (file)
@@ -1,4 +1,4 @@
-//===-- Unittests for pthread_t -------------------------------------------===//
+//===-- Tests for pthread_t -----------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,7 +8,7 @@
 
 #include "src/pthread/pthread_create.h"
 #include "src/pthread/pthread_join.h"
-#include "utils/UnitTest/Test.h"
+#include "utils/IntegrationTest/test.h"
 
 #include <pthread.h>
 
@@ -19,7 +19,7 @@ static void *thread_func(void *) {
   return nullptr;
 }
 
-TEST(LlvmLibcThreadTest, CreateAndJoin) {
+void create_and_join() {
   for (counter = 0; counter <= thread_count;) {
     pthread_t thread;
     int old_counter_val = counter;
@@ -36,7 +36,7 @@ TEST(LlvmLibcThreadTest, CreateAndJoin) {
 
 static void *return_arg(void *arg) { return arg; }
 
-TEST(LlvmLibcThreadTest, SpawnAndJoin) {
+void spawn_and_join() {
   pthread_t thread_list[thread_count];
   int args[thread_count];
 
@@ -54,3 +54,9 @@ TEST(LlvmLibcThreadTest, SpawnAndJoin) {
     ASSERT_EQ(*reinterpret_cast<int *>(retval), i);
   }
 }
+
+int main() {
+  create_and_join();
+  spawn_and_join();
+  return 0;
+}
index f69c77f..db0516c 100644 (file)
@@ -39,32 +39,3 @@ add_libc_unittest(
     libc.src.pthread.pthread_mutexattr_setrobust
     libc.src.pthread.pthread_mutexattr_settype
 )
-
-add_libc_unittest(
-  pthread_mutex_test
-  SUITE
-    libc_pthread_unittests
-  SRCS
-    pthread_mutex_test.cpp
-  DEPENDS
-    libc.include.pthread
-    libc.src.errno.errno
-    libc.src.pthread.pthread_mutex_destroy
-    libc.src.pthread.pthread_mutex_init
-    libc.src.pthread.pthread_mutex_lock
-    libc.src.pthread.pthread_mutex_unlock
-    libc.src.pthread.pthread_create
-    libc.src.pthread.pthread_join
-)
-
-add_libc_unittest(
-  pthread_test
-  SUITE
-    libc_pthread_unittests
-  SRCS
-    pthread_test.cpp
-  DEPENDS
-    libc.include.pthread
-    libc.src.pthread.pthread_create
-    libc.src.pthread.pthread_join
-)