[libc-commits] [libc] 854cc89 - [libc] fixup nascent pthread_condattr_test (#89308)
via libc-commits
libc-commits at lists.llvm.org
Fri Apr 19 09:15:51 PDT 2024
Author: Nick Desaulniers
Date: 2024-04-19T09:15:47-07:00
New Revision: 854cc8986650267846c5eaf8ba164584a9ea7c01
URL: https://github.com/llvm/llvm-project/commit/854cc8986650267846c5eaf8ba164584a9ea7c01
DIFF: https://github.com/llvm/llvm-project/commit/854cc8986650267846c5eaf8ba164584a9ea7c01.diff
LOG: [libc] fixup nascent pthread_condattr_test (#89308)
- 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
Added:
Modified:
libc/test/src/pthread/CMakeLists.txt
libc/test/src/pthread/pthread_condattr_test.cpp
Removed:
################################################################################
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..5fcdbd99cb0e20 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,17 @@ 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 +70,13 @@ 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);
}
More information about the libc-commits
mailing list