[libc-commits] [libc] 0a537a1 - [libc][NFC] Convert pthread tests which create threads to integration tests.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Thu Jun 23 13:38:26 PDT 2022


Author: Siva Chandra Reddy
Date: 2022-06-23T20:36:20Z
New Revision: 0a537a1299b03126b23938c36edbfd2edbea44c1

URL: https://github.com/llvm/llvm-project/commit/0a537a1299b03126b23938c36edbfd2edbea44c1
DIFF: https://github.com/llvm/llvm-project/commit/0a537a1299b03126b23938c36edbfd2edbea44c1.diff

LOG: [libc][NFC] Convert pthread tests which create threads to integration tests.

Added: 
    libc/test/integration/src/pthread/CMakeLists.txt
    libc/test/integration/src/pthread/pthread_mutex_test.cpp
    libc/test/integration/src/pthread/pthread_test.cpp

Modified: 
    libc/test/integration/src/CMakeLists.txt
    libc/test/src/pthread/CMakeLists.txt

Removed: 
    libc/test/src/pthread/pthread_mutex_test.cpp
    libc/test/src/pthread/pthread_test.cpp


################################################################################
diff  --git a/libc/test/integration/src/CMakeLists.txt b/libc/test/integration/src/CMakeLists.txt
index 659e4b5bea710..f175dc4f23bcd 100644
--- a/libc/test/integration/src/CMakeLists.txt
+++ b/libc/test/integration/src/CMakeLists.txt
@@ -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
index 0000000000000..0f52d8ac28e63
--- /dev/null
+++ b/libc/test/integration/src/pthread/CMakeLists.txt
@@ -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
+)

diff  --git a/libc/test/src/pthread/pthread_mutex_test.cpp b/libc/test/integration/src/pthread/pthread_mutex_test.cpp
similarity index 95%
rename from libc/test/src/pthread/pthread_mutex_test.cpp
rename to libc/test/integration/src/pthread/pthread_mutex_test.cpp
index 28c06b01eb1a1..823efe393eab4 100644
--- a/libc/test/src/pthread/pthread_mutex_test.cpp
+++ b/libc/test/integration/src/pthread/pthread_mutex_test.cpp
@@ -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;
+}

diff  --git a/libc/test/src/pthread/pthread_test.cpp b/libc/test/integration/src/pthread/pthread_test.cpp
similarity index 88%
rename from libc/test/src/pthread/pthread_test.cpp
rename to libc/test/integration/src/pthread/pthread_test.cpp
index 3a3d587ab5d51..f5be1c67f3536 100644
--- a/libc/test/src/pthread/pthread_test.cpp
+++ b/libc/test/integration/src/pthread/pthread_test.cpp
@@ -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;
+}

diff  --git a/libc/test/src/pthread/CMakeLists.txt b/libc/test/src/pthread/CMakeLists.txt
index f69c77fd4c3ec..db0516cecc4fd 100644
--- a/libc/test/src/pthread/CMakeLists.txt
+++ b/libc/test/src/pthread/CMakeLists.txt
@@ -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
-)


        


More information about the libc-commits mailing list