Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc] fixup nascent pthread_condattr_test #89308

Merged
merged 2 commits into from
Apr 19, 2024

Conversation

nickdesaulniers
Copy link
Member

  • use namespaced identifiers
  • add corresponding headers for namespaced declarations
  • replace time.h and errno.h with finer grain includes
  • update cmake

Fixes: #88987
Fixes: #89261
Link: #88997
Link: #89262

- use namespaced identifiers
- add corresponding headers for namespaced declarations
- replace time.h and errno.h with finer grain includes
- update cmake

Fixes: llvm#88987
Fixes: llvm#89261
Link: llvm#88997
Link: llvm#89262
@nickdesaulniers
Copy link
Member Author

cc @Flandini

@llvmbot llvmbot added the libc label Apr 18, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 18, 2024

@llvm/pr-subscribers-libc

Author: Nick Desaulniers (nickdesaulniers)

Changes
  • use namespaced identifiers
  • add corresponding headers for namespaced declarations
  • replace time.h and errno.h with finer grain includes
  • update cmake

Fixes: #88987
Fixes: #89261
Link: #88997
Link: #89262


Full diff: https://github.com/llvm/llvm-project/pull/89308.diff

2 Files Affected:

  • (modified) libc/test/src/pthread/CMakeLists.txt (+2-2)
  • (modified) libc/test/src/pthread/pthread_condattr_test.cpp (+28-21)
diff --git a/libc/test/src/pthread/CMakeLists.txt b/libc/test/src/pthread/CMakeLists.txt
index 51954a5babd2c5..4d01b667f12c83 100644
--- a/libc/test/src/pthread/CMakeLists.txt
+++ b/libc/test/src/pthread/CMakeLists.txt
@@ -47,9 +47,9 @@ add_libc_unittest(
   SRCS
     pthread_condattr_test.cpp
   DEPENDS
-    libc.include.errno
+    libc.include.llvm-libc-macros.generic_error_number_macros
+    libc.include.llvm-libc-macros.time_macros
     libc.include.pthread
-    libc.include.time
     libc.src.pthread.pthread_condattr_destroy
     libc.src.pthread.pthread_condattr_getclock
     libc.src.pthread.pthread_condattr_getpshared
diff --git a/libc/test/src/pthread/pthread_condattr_test.cpp b/libc/test/src/pthread/pthread_condattr_test.cpp
index accb62de92e45f..b1fa4dab14ed22 100644
--- a/libc/test/src/pthread/pthread_condattr_test.cpp
+++ b/libc/test/src/pthread/pthread_condattr_test.cpp
@@ -6,16 +6,23 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "include/llvm-libc-macros/generic-error-number-macros.h" // EINVAL
+#include "include/llvm-libc-macros/time-macros.h" // CLOCK_REALTIME, CLOCK_MONOTONIC
+#include "src/pthread/pthread_condattr_destroy.h"
+#include "src/pthread/pthread_condattr_getclock.h"
+#include "src/pthread/pthread_condattr_getpshared.h"
+#include "src/pthread/pthread_condattr_init.h"
+#include "src/pthread/pthread_condattr_setclock.h"
+#include "src/pthread/pthread_condattr_setpshared.h"
 #include "test/UnitTest/Test.h"
 
-#include <errno.h>
-#include <pthread.h>
-#include <time.h>
+// TODO: https://github.com/llvm/llvm-project/issues/88997
+#include <pthread.h> // PTHREAD_PROCESS_PRIVATE, PTHREAD_PROCESS_SHARED
 
 TEST(LlvmLibcPThreadCondAttrTest, InitAndDestroy) {
   pthread_condattr_t cond;
-  ASSERT_EQ(pthread_condattr_init(&cond), 0);
-  ASSERT_EQ(pthread_condattr_destroy(&cond), 0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_init(&cond), 0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_destroy(&cond), 0);
 }
 
 TEST(LlvmLibcPThreadCondAttrTest, GetDefaultValues) {
@@ -26,12 +33,12 @@ TEST(LlvmLibcPThreadCondAttrTest, GetDefaultValues) {
   // Invalid value.
   int pshared = 42;
 
-  ASSERT_EQ(pthread_condattr_init(&cond), 0);
-  ASSERT_EQ(pthread_condattr_getclock(&cond, &clock), 0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_init(&cond), 0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_getclock(&cond, &clock), 0);
   ASSERT_EQ(clock, CLOCK_REALTIME);
-  ASSERT_EQ(pthread_condattr_getpshared(&cond, &pshared), 0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_getpshared(&cond, &pshared), 0);
   ASSERT_EQ(pshared, PTHREAD_PROCESS_PRIVATE);
-  ASSERT_EQ(pthread_condattr_destroy(&cond), 0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_destroy(&cond), 0);
 }
 
 TEST(LlvmLibcPThreadCondAttrTest, SetGoodValues) {
@@ -42,14 +49,14 @@ TEST(LlvmLibcPThreadCondAttrTest, SetGoodValues) {
   // Invalid value.
   int pshared = 42;
 
-  ASSERT_EQ(pthread_condattr_init(&cond), 0);
-  ASSERT_EQ(pthread_condattr_setclock(&cond, CLOCK_MONOTONIC), 0);
-  ASSERT_EQ(pthread_condattr_getclock(&cond, &clock), 0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_init(&cond), 0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_setclock(&cond, CLOCK_MONOTONIC), 0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_getclock(&cond, &clock), 0);
   ASSERT_EQ(clock, CLOCK_MONOTONIC);
-  ASSERT_EQ(pthread_condattr_setpshared(&cond, PTHREAD_PROCESS_SHARED), 0);
-  ASSERT_EQ(pthread_condattr_getpshared(&cond, &pshared), 0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_setpshared(&cond, PTHREAD_PROCESS_SHARED), 0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_getpshared(&cond, &pshared), 0);
   ASSERT_EQ(pshared, PTHREAD_PROCESS_SHARED);
-  ASSERT_EQ(pthread_condattr_destroy(&cond), 0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_destroy(&cond), 0);
 }
 
 TEST(LlvmLibcPThreadCondAttrTest, SetBadValues) {
@@ -60,12 +67,12 @@ TEST(LlvmLibcPThreadCondAttrTest, SetBadValues) {
   // Invalid value.
   int pshared = 42;
 
-  ASSERT_EQ(pthread_condattr_init(&cond), 0);
-  ASSERT_EQ(pthread_condattr_setclock(&cond, clock), EINVAL);
-  ASSERT_EQ(pthread_condattr_getclock(&cond, &clock), 0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_init(&cond), 0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_setclock(&cond, clock), EINVAL);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_getclock(&cond, &clock), 0);
   ASSERT_EQ(clock, CLOCK_REALTIME);
-  ASSERT_EQ(pthread_condattr_setpshared(&cond, pshared), EINVAL);
-  ASSERT_EQ(pthread_condattr_getpshared(&cond, &pshared), 0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_setpshared(&cond, pshared), EINVAL);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_getpshared(&cond, &pshared), 0);
   ASSERT_EQ(pshared, PTHREAD_PROCESS_PRIVATE);
-  ASSERT_EQ(pthread_condattr_destroy(&cond), 0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_destroy(&cond), 0);
 }

Copy link

github-actions bot commented Apr 18, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nickdesaulniers nickdesaulniers merged commit 854cc89 into llvm:main Apr 19, 2024
4 checks passed
aniplcc pushed a commit to aniplcc/llvm-project that referenced this pull request Apr 21, 2024
- use namespaced identifiers
- add corresponding headers for namespaced declarations
- replace time.h and errno.h with finer grain includes
- update cmake

Fixes: llvm#88987
Fixes: llvm#89261
Link: llvm#88997
Link: llvm#89262
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[libc][test] link error running pthreads tests on linux, x86_64
3 participants