[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / libc / test / src / pthread / pthread_mutexattr_test.cpp
blob7fbdd2efd9858e7b3a0da228eec9bae5016c7341
1 //===-- Unittests for pthread_mutexattr_t ---------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "hdr/errno_macros.h"
10 #include "src/pthread/pthread_mutexattr_destroy.h"
11 #include "src/pthread/pthread_mutexattr_getpshared.h"
12 #include "src/pthread/pthread_mutexattr_getrobust.h"
13 #include "src/pthread/pthread_mutexattr_gettype.h"
14 #include "src/pthread/pthread_mutexattr_init.h"
15 #include "src/pthread/pthread_mutexattr_setpshared.h"
16 #include "src/pthread/pthread_mutexattr_setrobust.h"
17 #include "src/pthread/pthread_mutexattr_settype.h"
18 #include "test/UnitTest/Test.h"
19 #include <pthread.h>
21 TEST(LlvmLibcPThreadMutexAttrTest, InitAndDestroy) {
22 pthread_mutexattr_t attr;
23 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_init(&attr), 0);
24 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_destroy(&attr), 0);
27 TEST(LlvmLibcPThreadMutexAttrTest, SetAndGetType) {
28 int type;
29 pthread_mutexattr_t attr;
30 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_init(&attr), 0);
31 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_gettype(&attr, &type), 0);
32 ASSERT_EQ(type, int(PTHREAD_MUTEX_DEFAULT));
34 ASSERT_EQ(
35 LIBC_NAMESPACE::pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE),
36 0);
37 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_gettype(&attr, &type), 0);
38 ASSERT_EQ(type, int(PTHREAD_MUTEX_RECURSIVE));
40 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_settype(&attr,
41 PTHREAD_MUTEX_ERRORCHECK),
42 0);
43 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_gettype(&attr, &type), 0);
44 ASSERT_EQ(type, int(PTHREAD_MUTEX_ERRORCHECK));
46 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_settype(&attr, 0xBAD), EINVAL);
49 TEST(LlvmLibcPThreadMutexAttrTest, SetAndGetRobust) {
50 int robust;
51 pthread_mutexattr_t attr;
52 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_init(&attr), 0);
53 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_getrobust(&attr, &robust), 0);
54 ASSERT_EQ(robust, int(PTHREAD_MUTEX_STALLED));
56 ASSERT_EQ(
57 LIBC_NAMESPACE::pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST),
58 0);
59 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_getrobust(&attr, &robust), 0);
60 ASSERT_EQ(robust, int(PTHREAD_MUTEX_ROBUST));
62 ASSERT_EQ(
63 LIBC_NAMESPACE::pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_STALLED),
64 0);
65 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_getrobust(&attr, &robust), 0);
66 ASSERT_EQ(robust, int(PTHREAD_MUTEX_STALLED));
68 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_setrobust(&attr, 0xBAD), EINVAL);
71 TEST(LlvmLibcPThreadMutexAttrTest, SetAndGetPShared) {
72 int pshared;
73 pthread_mutexattr_t attr;
74 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_init(&attr), 0);
75 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_getpshared(&attr, &pshared), 0);
76 ASSERT_EQ(pshared, int(PTHREAD_PROCESS_PRIVATE));
78 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_setpshared(
79 &attr, PTHREAD_PROCESS_SHARED),
80 0);
81 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_getpshared(&attr, &pshared), 0);
82 ASSERT_EQ(pshared, int(PTHREAD_PROCESS_SHARED));
84 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_setpshared(
85 &attr, PTHREAD_PROCESS_PRIVATE),
86 0);
87 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_getpshared(&attr, &pshared), 0);
88 ASSERT_EQ(pshared, int(PTHREAD_PROCESS_PRIVATE));
90 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_setpshared(&attr, 0xBAD), EINVAL);