scripts: Fix fortify checks if compiler does not support _FORTIFY_SOURCE=3
[glibc.git] / nptl / test-rwlockattr-printers.c
blobcdc0c7206a88a0b5239f6e86506988f2ca7854e6
1 /* Helper program for testing the pthread_rwlock_t and pthread_rwlockattr_t
2 pretty printers.
4 Copyright (C) 2016-2023 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 <https://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
29 /* Need these so we don't have lines longer than 79 chars. */
30 #define SET_KIND(attr, kind) pthread_rwlockattr_setkind_np (attr, kind)
31 #define SET_SHARED(attr, shared) pthread_rwlockattr_setpshared (attr, shared)
33 static int rwlock_reinit (pthread_rwlock_t *rwlock,
34 const pthread_rwlockattr_t *attr);
35 static int test_setkind_np (pthread_rwlock_t *rwlock,
36 pthread_rwlockattr_t *attr);
37 static int test_setpshared (pthread_rwlock_t *rwlock,
38 pthread_rwlockattr_t *attr);
40 int
41 main (void)
43 pthread_rwlock_t rwlock;
44 pthread_rwlockattr_t attr;
45 int result = FAIL;
47 if (pthread_rwlockattr_init (&attr) == 0
48 && pthread_rwlock_init (&rwlock, NULL) == 0
49 && test_setkind_np (&rwlock, &attr) == PASS
50 && test_setpshared (&rwlock, &attr) == PASS)
51 result = PASS;
52 /* Else, one of the pthread_rwlock* functions failed. */
54 return result;
57 /* Destroys RWLOCK and re-initializes it using ATTR. */
58 static int
59 rwlock_reinit (pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
61 int result = FAIL;
63 if (pthread_rwlock_destroy (rwlock) == 0
64 && pthread_rwlock_init (rwlock, attr) == 0)
65 result = PASS;
67 return result;
70 /* Tests setting whether the rwlock prefers readers or writers. */
71 static int
72 test_setkind_np (pthread_rwlock_t *rwlock, pthread_rwlockattr_t *attr)
74 int result = FAIL;
76 if (SET_KIND (attr, PTHREAD_RWLOCK_PREFER_READER_NP) == 0 /* Set kind. */
77 && rwlock_reinit (rwlock, attr) == PASS
78 && SET_KIND (attr, PTHREAD_RWLOCK_PREFER_WRITER_NP) == 0
79 && rwlock_reinit (rwlock, attr) == PASS
80 && SET_KIND (attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP) == 0
81 && rwlock_reinit (rwlock, attr) == PASS)
82 result = PASS;
84 return result;
87 /* Tests setting whether the rwlock can be shared between processes. */
88 static int
89 test_setpshared (pthread_rwlock_t *rwlock, pthread_rwlockattr_t *attr)
91 int result = FAIL;
93 if (SET_SHARED (attr, PTHREAD_PROCESS_SHARED) == 0 /* Set shared. */
94 && rwlock_reinit (rwlock, attr) == PASS
95 && SET_SHARED (attr, PTHREAD_PROCESS_PRIVATE) == 0
96 && rwlock_reinit (rwlock, attr) == PASS)
97 result = PASS;
99 return result;