Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / test / src / pthread / pthread_mutexattr_test.cpp
bloba7acd580a6b8e55aee39740b9cb8eb54d0c35297
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 "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"
19 #include <errno.h>
20 #include <pthread.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) {
29 int type;
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));
35 ASSERT_EQ(
36 LIBC_NAMESPACE::pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE),
37 0);
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),
43 0);
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) {
51 int robust;
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));
57 ASSERT_EQ(
58 LIBC_NAMESPACE::pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST),
59 0);
60 ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_getrobust(&attr, &robust), 0);
61 ASSERT_EQ(robust, int(PTHREAD_MUTEX_ROBUST));
63 ASSERT_EQ(
64 LIBC_NAMESPACE::pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_STALLED),
65 0);
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) {
73 int pshared;
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),
81 0);
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),
87 0);
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);