[libc-commits] [libc] [libc] fixup nascent pthread_condattr_test (PR #89308)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Thu Apr 18 14:07:15 PDT 2024
https://github.com/nickdesaulniers updated https://github.com/llvm/llvm-project/pull/89308
>From 3d4d4702f1cb23b94cfa686301bf129838c2a3e4 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Thu, 18 Apr 2024 13:53:05 -0700
Subject: [PATCH 1/2] [libc] fixup nascent pthread_condattr_test
- 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
---
libc/test/src/pthread/CMakeLists.txt | 4 +-
.../src/pthread/pthread_condattr_test.cpp | 49 +++++++++++--------
2 files changed, 30 insertions(+), 23 deletions(-)
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);
}
>From 42d87ee2c31b0fdfda8344860a8a366a4c75bce2 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Thu, 18 Apr 2024 14:07:02 -0700
Subject: [PATCH 2/2] reformat
---
libc/test/src/pthread/pthread_condattr_test.cpp | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/libc/test/src/pthread/pthread_condattr_test.cpp b/libc/test/src/pthread/pthread_condattr_test.cpp
index b1fa4dab14ed22..5fcdbd99cb0e20 100644
--- a/libc/test/src/pthread/pthread_condattr_test.cpp
+++ b/libc/test/src/pthread/pthread_condattr_test.cpp
@@ -50,10 +50,13 @@ TEST(LlvmLibcPThreadCondAttrTest, SetGoodValues) {
int pshared = 42;
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_setclock(&cond, CLOCK_MONOTONIC),
+ 0);
ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_getclock(&cond, &clock), 0);
ASSERT_EQ(clock, CLOCK_MONOTONIC);
- ASSERT_EQ(LIBC_NAMESPACE::pthread_condattr_setpshared(&cond, PTHREAD_PROCESS_SHARED), 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(LIBC_NAMESPACE::pthread_condattr_destroy(&cond), 0);
@@ -71,7 +74,8 @@ TEST(LlvmLibcPThreadCondAttrTest, SetBadValues) {
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(LIBC_NAMESPACE::pthread_condattr_setpshared(&cond, pshared), EINVAL);
+ 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(LIBC_NAMESPACE::pthread_condattr_destroy(&cond), 0);
More information about the libc-commits
mailing list