1 //===-- Unittests for pthread_mutexattr_t ---------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "src/pthread/pthread_mutexattr_destroy.h"
10 #include "src/pthread/pthread_mutexattr_getpshared.h"
11 #include "src/pthread/pthread_mutexattr_getrobust.h"
12 #include "src/pthread/pthread_mutexattr_gettype.h"
13 #include "src/pthread/pthread_mutexattr_init.h"
14 #include "src/pthread/pthread_mutexattr_setpshared.h"
15 #include "src/pthread/pthread_mutexattr_setrobust.h"
16 #include "src/pthread/pthread_mutexattr_settype.h"
17 #include "test/UnitTest/Test.h"
22 TEST(LlvmLibcPThreadMutexAttrTest
, InitAndDestroy
) {
23 pthread_mutexattr_t attr
;
24 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_init(&attr
), 0);
25 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_destroy(&attr
), 0);
28 TEST(LlvmLibcPThreadMutexAttrTest
, SetAndGetType
) {
30 pthread_mutexattr_t attr
;
31 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_init(&attr
), 0);
32 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_gettype(&attr
, &type
), 0);
33 ASSERT_EQ(type
, int(PTHREAD_MUTEX_DEFAULT
));
36 LIBC_NAMESPACE::pthread_mutexattr_settype(&attr
, PTHREAD_MUTEX_RECURSIVE
),
38 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_gettype(&attr
, &type
), 0);
39 ASSERT_EQ(type
, int(PTHREAD_MUTEX_RECURSIVE
));
41 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_settype(&attr
,
42 PTHREAD_MUTEX_ERRORCHECK
),
44 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_gettype(&attr
, &type
), 0);
45 ASSERT_EQ(type
, int(PTHREAD_MUTEX_ERRORCHECK
));
47 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_settype(&attr
, 0xBAD), EINVAL
);
50 TEST(LlvmLibcPThreadMutexAttrTest
, SetAndGetRobust
) {
52 pthread_mutexattr_t attr
;
53 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_init(&attr
), 0);
54 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_getrobust(&attr
, &robust
), 0);
55 ASSERT_EQ(robust
, int(PTHREAD_MUTEX_STALLED
));
58 LIBC_NAMESPACE::pthread_mutexattr_setrobust(&attr
, PTHREAD_MUTEX_ROBUST
),
60 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_getrobust(&attr
, &robust
), 0);
61 ASSERT_EQ(robust
, int(PTHREAD_MUTEX_ROBUST
));
64 LIBC_NAMESPACE::pthread_mutexattr_setrobust(&attr
, PTHREAD_MUTEX_STALLED
),
66 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_getrobust(&attr
, &robust
), 0);
67 ASSERT_EQ(robust
, int(PTHREAD_MUTEX_STALLED
));
69 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_setrobust(&attr
, 0xBAD), EINVAL
);
72 TEST(LlvmLibcPThreadMutexAttrTest
, SetAndGetPShared
) {
74 pthread_mutexattr_t attr
;
75 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_init(&attr
), 0);
76 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_getpshared(&attr
, &pshared
), 0);
77 ASSERT_EQ(pshared
, int(PTHREAD_PROCESS_PRIVATE
));
79 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_setpshared(
80 &attr
, PTHREAD_PROCESS_SHARED
),
82 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_getpshared(&attr
, &pshared
), 0);
83 ASSERT_EQ(pshared
, int(PTHREAD_PROCESS_SHARED
));
85 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_setpshared(
86 &attr
, PTHREAD_PROCESS_PRIVATE
),
88 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_getpshared(&attr
, &pshared
), 0);
89 ASSERT_EQ(pshared
, int(PTHREAD_PROCESS_PRIVATE
));
91 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_setpshared(&attr
, 0xBAD), EINVAL
);