[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / libc / test / src / pthread / pthread_mutexattr_test.cpp
blob3ecbc4f5896a4650c4bf0f06339bc9b3b6a911bf
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(__llvm_libc::pthread_mutexattr_init(&attr), 0);
25 ASSERT_EQ(__llvm_libc::pthread_mutexattr_destroy(&attr), 0);
28 TEST(LlvmLibcPThreadMutexAttrTest, SetAndGetType) {
29 int type;
30 pthread_mutexattr_t attr;
31 ASSERT_EQ(__llvm_libc::pthread_mutexattr_init(&attr), 0);
32 ASSERT_EQ(__llvm_libc::pthread_mutexattr_gettype(&attr, &type), 0);
33 ASSERT_EQ(type, int(PTHREAD_MUTEX_DEFAULT));
35 ASSERT_EQ(
36 __llvm_libc::pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE),
37 0);
38 ASSERT_EQ(__llvm_libc::pthread_mutexattr_gettype(&attr, &type), 0);
39 ASSERT_EQ(type, int(PTHREAD_MUTEX_RECURSIVE));
41 ASSERT_EQ(
42 __llvm_libc::pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK),
43 0);
44 ASSERT_EQ(__llvm_libc::pthread_mutexattr_gettype(&attr, &type), 0);
45 ASSERT_EQ(type, int(PTHREAD_MUTEX_ERRORCHECK));
47 ASSERT_EQ(__llvm_libc::pthread_mutexattr_settype(&attr, 0xBAD), EINVAL);
50 TEST(LlvmLibcPThreadMutexAttrTest, SetAndGetRobust) {
51 int robust;
52 pthread_mutexattr_t attr;
53 ASSERT_EQ(__llvm_libc::pthread_mutexattr_init(&attr), 0);
54 ASSERT_EQ(__llvm_libc::pthread_mutexattr_getrobust(&attr, &robust), 0);
55 ASSERT_EQ(robust, int(PTHREAD_MUTEX_STALLED));
57 ASSERT_EQ(
58 __llvm_libc::pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST), 0);
59 ASSERT_EQ(__llvm_libc::pthread_mutexattr_getrobust(&attr, &robust), 0);
60 ASSERT_EQ(robust, int(PTHREAD_MUTEX_ROBUST));
62 ASSERT_EQ(
63 __llvm_libc::pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_STALLED),
64 0);
65 ASSERT_EQ(__llvm_libc::pthread_mutexattr_getrobust(&attr, &robust), 0);
66 ASSERT_EQ(robust, int(PTHREAD_MUTEX_STALLED));
68 ASSERT_EQ(__llvm_libc::pthread_mutexattr_setrobust(&attr, 0xBAD), EINVAL);
71 TEST(LlvmLibcPThreadMutexAttrTest, SetAndGetPShared) {
72 int pshared;
73 pthread_mutexattr_t attr;
74 ASSERT_EQ(__llvm_libc::pthread_mutexattr_init(&attr), 0);
75 ASSERT_EQ(__llvm_libc::pthread_mutexattr_getpshared(&attr, &pshared), 0);
76 ASSERT_EQ(pshared, int(PTHREAD_PROCESS_PRIVATE));
78 ASSERT_EQ(
79 __llvm_libc::pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED),
80 0);
81 ASSERT_EQ(__llvm_libc::pthread_mutexattr_getpshared(&attr, &pshared), 0);
82 ASSERT_EQ(pshared, int(PTHREAD_PROCESS_SHARED));
84 ASSERT_EQ(
85 __llvm_libc::pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_PRIVATE),
86 0);
87 ASSERT_EQ(__llvm_libc::pthread_mutexattr_getpshared(&attr, &pshared), 0);
88 ASSERT_EQ(pshared, int(PTHREAD_PROCESS_PRIVATE));
90 ASSERT_EQ(__llvm_libc::pthread_mutexattr_setpshared(&attr, 0xBAD), EINVAL);