Added yesstr/nostr for nds_DE and nds_NL
[glibc.git] / nptl / test-mutexattr-printers.c
blob4893f52cc3c8915d0d2330dbfcec24cbdbbee1ac
1 /* Helper program for testing the pthread_mutex_t and pthread_mutexattr_t
2 pretty printers.
4 Copyright (C) 2016-2017 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <http://www.gnu.org/licenses/>. */
21 /* Keep the calls to the pthread_* functions on separate lines to make it easy
22 to advance through the program using the gdb 'next' command. */
24 #include <pthread.h>
26 #define PASS 0
27 #define FAIL 1
28 #define PRIOCEILING 42
30 /* Need these so we don't have lines longer than 79 chars. */
31 #define SET_TYPE(attr, type) pthread_mutexattr_settype (attr, type)
32 #define SET_ROBUST(attr, robust) pthread_mutexattr_setrobust (attr, robust)
33 #define SET_SHARED(attr, shared) pthread_mutexattr_setpshared (attr, shared)
34 #define SET_PROTOCOL(attr, protocol) \
35 pthread_mutexattr_setprotocol (attr, protocol)
36 #define SET_PRIOCEILING(mutex, prioceiling, old_ceiling) \
37 pthread_mutex_setprioceiling (mutex, prioceiling, old_ceiling)
39 static int mutex_reinit (pthread_mutex_t *mutex,
40 const pthread_mutexattr_t *attr);
41 static int test_settype (pthread_mutex_t *mutex, pthread_mutexattr_t *attr);
42 static int test_setrobust (pthread_mutex_t *mutex, pthread_mutexattr_t *attr);
43 static int test_setpshared (pthread_mutex_t *mutex, pthread_mutexattr_t *attr);
44 static int test_setprotocol (pthread_mutex_t *mutex,
45 pthread_mutexattr_t *attr);
47 int
48 main (void)
50 pthread_mutex_t mutex;
51 pthread_mutexattr_t attr;
52 int result = FAIL;
54 if (pthread_mutexattr_init (&attr) == 0
55 && pthread_mutex_init (&mutex, NULL) == 0
56 && test_settype (&mutex, &attr) == PASS
57 && test_setrobust (&mutex, &attr) == PASS
58 && test_setpshared (&mutex, &attr) == PASS
59 && test_setprotocol (&mutex, &attr) == PASS)
60 result = PASS;
61 /* Else, one of the pthread_mutex* functions failed. */
63 return result;
66 /* Destroys MUTEX and re-initializes it using ATTR. */
67 static int
68 mutex_reinit (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
70 int result = FAIL;
72 if (pthread_mutex_destroy (mutex) == 0
73 && pthread_mutex_init (mutex, attr) == 0)
74 result = PASS;
76 return result;
79 /* Tests setting the mutex type. */
80 static int
81 test_settype (pthread_mutex_t *mutex, pthread_mutexattr_t *attr)
83 int result = FAIL;
85 if (SET_TYPE (attr, PTHREAD_MUTEX_ERRORCHECK) == 0 /* Set type. */
86 && mutex_reinit (mutex, attr) == 0
87 && SET_TYPE (attr, PTHREAD_MUTEX_RECURSIVE) == 0
88 && mutex_reinit (mutex, attr) == 0
89 && SET_TYPE (attr, PTHREAD_MUTEX_NORMAL) == 0
90 && mutex_reinit (mutex, attr) == 0)
91 result = PASS;
93 return result;
96 /* Tests setting whether the mutex is robust. */
97 static int
98 test_setrobust (pthread_mutex_t *mutex, pthread_mutexattr_t *attr)
100 int result = FAIL;
102 if (SET_ROBUST (attr, PTHREAD_MUTEX_ROBUST) == 0 /* Set robust. */
103 && mutex_reinit (mutex, attr) == 0
104 && SET_ROBUST (attr, PTHREAD_MUTEX_STALLED) == 0
105 && mutex_reinit (mutex, attr) == 0)
106 result = PASS;
108 return result;
111 /* Tests setting whether the mutex can be shared between processes. */
112 static int
113 test_setpshared (pthread_mutex_t *mutex, pthread_mutexattr_t *attr)
115 int result = FAIL;
117 if (SET_SHARED (attr, PTHREAD_PROCESS_SHARED) == 0 /* Set shared. */
118 && mutex_reinit (mutex, attr) == 0
119 && SET_SHARED (attr, PTHREAD_PROCESS_PRIVATE) == 0
120 && mutex_reinit (mutex, attr) == 0)
121 result = PASS;
123 return result;
126 /* Tests setting the mutex protocol and, for Priority Protect, the Priority
127 Ceiling. */
128 static int
129 test_setprotocol (pthread_mutex_t *mutex, pthread_mutexattr_t *attr)
131 int result = FAIL;
132 int old_prioceiling;
134 if (SET_PROTOCOL (attr, PTHREAD_PRIO_INHERIT) == 0 /* Set protocol. */
135 && mutex_reinit (mutex, attr) == 0
136 && SET_PROTOCOL (attr, PTHREAD_PRIO_PROTECT) == 0
137 && mutex_reinit (mutex, attr) == 0
138 && SET_PRIOCEILING(mutex, PRIOCEILING, &old_prioceiling) == 0
139 && SET_PROTOCOL (attr, PTHREAD_PRIO_NONE) == 0
140 && mutex_reinit (mutex, attr) == 0)
141 result = PASS;
143 return result;