1 /*
2  * Copyright (c) 2022 Meta
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include "_common.h"
8 
9 #ifdef CONFIG_POSIX_API
10 #include <pthread.h>
11 #else
12 #include <zephyr/posix/pthread.h>
13 #endif
14 
15 #pragma GCC diagnostic push
16 #pragma GCC diagnostic ignored "-Wunused-variable"
17 /**
18  * @brief existence test for `<pthread.h>`
19  *
20  * @see <a href="https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/pthread.h.html">pthread.h</a>
21  */
ZTEST(posix_headers,test_pthread_h)22 ZTEST(posix_headers, test_pthread_h)
23 {
24 #ifdef CONFIG_POSIX_API
25 	zassert_not_equal(-1, PTHREAD_BARRIER_SERIAL_THREAD);
26 
27 	zassert_not_equal(-1, PTHREAD_CANCEL_ASYNCHRONOUS);
28 	zassert_not_equal(-1, PTHREAD_CANCEL_DEFERRED);
29 
30 	zassert_not_equal(-1, PTHREAD_CANCEL_ENABLE);
31 	zassert_not_equal(-1, PTHREAD_CANCEL_DISABLE);
32 
33 	zassert_not_equal((void *)-42, PTHREAD_CANCELED);
34 
35 	zassert_not_equal(-1, PTHREAD_CREATE_DETACHED);
36 	zassert_not_equal(-1, PTHREAD_CREATE_JOINABLE);
37 
38 	zassert_not_equal(-1, PTHREAD_EXPLICIT_SCHED);
39 	zassert_not_equal(-1, PTHREAD_INHERIT_SCHED);
40 
41 	zassert_not_equal(-1, PTHREAD_MUTEX_DEFAULT);
42 	zassert_not_equal(-1, PTHREAD_MUTEX_ERRORCHECK);
43 	zassert_not_equal(-1, PTHREAD_MUTEX_ERRORCHECK);
44 	zassert_not_equal(-1, PTHREAD_MUTEX_RECURSIVE);
45 	/* zassert_not_equal(-1, PTHREAD_MUTEX_ROBUST); */  /* not implemented */
46 	/* zassert_not_equal(-1, PTHREAD_MUTEX_STALLED); */ /* not implemented */
47 
48 	pthread_once_t once = PTHREAD_ONCE_INIT;
49 
50 	/* zassert_not_equal(-1, PTHREAD_PRIO_INHERIT); */ /* not implemented */
51 	zassert_not_equal(-1, PTHREAD_PRIO_NONE);
52 	/* zassert_not_equal(-1, PTHREAD_PRIO_PROTECT); */ /* not implemented */
53 
54 	zassert_not_equal(-1, PTHREAD_PROCESS_SHARED);
55 	zassert_not_equal(-1, PTHREAD_PROCESS_PRIVATE);
56 
57 	zassert_not_equal(-1, PTHREAD_SCOPE_PROCESS);
58 	zassert_not_equal(-1, PTHREAD_SCOPE_SYSTEM);
59 
60 	pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
61 	pthread_mutex_t mu = PTHREAD_MUTEX_INITIALIZER;
62 	/* pthread_rwlock_t lock = POSIX_READER_WRITER_LOCKS_INITIALIZER; */ /* not implemented */
63 
64 	zassert_not_null(pthread_atfork);
65 	zassert_not_null(pthread_attr_destroy);
66 	zassert_not_null(pthread_attr_getdetachstate);
67 	zassert_not_null(pthread_attr_getguardsize);
68 	zassert_not_null(pthread_attr_getinheritsched);
69 	zassert_not_null(pthread_attr_getschedparam);
70 	zassert_not_null(pthread_attr_getschedpolicy);
71 	zassert_not_null(pthread_attr_getscope);
72 	zassert_not_null(pthread_attr_getstack);
73 	zassert_not_null(pthread_attr_getstacksize);
74 	zassert_not_null(pthread_attr_init);
75 	zassert_not_null(pthread_attr_setdetachstate);
76 	zassert_not_null(pthread_attr_setguardsize);
77 	zassert_not_null(pthread_attr_setinheritsched);
78 	zassert_not_null(pthread_attr_setschedparam);
79 	zassert_not_null(pthread_attr_setschedpolicy);
80 	zassert_not_null(pthread_attr_setscope);
81 	zassert_not_null(pthread_attr_setstack);
82 	zassert_not_null(pthread_attr_setstacksize);
83 	zassert_not_null(pthread_barrier_destroy);
84 	zassert_not_null(pthread_barrier_init);
85 	zassert_not_null(pthread_barrier_wait);
86 	zassert_not_null(pthread_barrierattr_destroy);
87 	/* zassert_not_null(pthread_barrierattr_getpshared); */ /* not implemented */
88 	zassert_not_null(pthread_barrierattr_init);
89 	/* zassert_not_null(pthread_barrierattr_setpshared); */ /* not implemented */
90 	zassert_not_null(pthread_cancel);
91 	zassert_not_null(pthread_cond_broadcast);
92 	zassert_not_null(pthread_cond_destroy);
93 	zassert_not_null(pthread_cond_init);
94 	zassert_not_null(pthread_cond_signal);
95 	zassert_not_null(pthread_cond_timedwait);
96 	zassert_not_null(pthread_cond_wait);
97 	zassert_not_null(pthread_condattr_destroy);
98 	zassert_not_null(pthread_condattr_getclock);
99 	/* zassert_not_null(pthread_condattr_getpshared); */ /* not implemented */
100 	zassert_not_null(pthread_condattr_init);
101 	zassert_not_null(pthread_condattr_setclock);
102 	/* zassert_not_null(pthread_condattr_setpshared); */ /* not implemented */
103 	zassert_not_null(pthread_create);
104 	zassert_not_null(pthread_detach);
105 	zassert_not_null(pthread_equal);
106 	zassert_not_null(pthread_exit);
107 	zassert_not_null(pthread_getconcurrency);
108 	/* zassert_not_null(pthread_getcpuclockid); */ /* not implemented */
109 	zassert_not_null(pthread_getschedparam);
110 	zassert_not_null(pthread_getspecific);
111 	zassert_not_null(pthread_join);
112 	zassert_not_null(pthread_key_create);
113 	zassert_not_null(pthread_key_delete);
114 	/* zassert_not_null(pthread_mutex_consistent); */ /* not implemented */
115 	zassert_not_null(pthread_mutex_destroy);
116 	zassert_not_null(pthread_mutex_getprioceiling);
117 	zassert_not_null(pthread_mutex_init);
118 	zassert_not_null(pthread_mutex_lock);
119 	zassert_not_null(pthread_mutex_setprioceiling);
120 	zassert_not_null(pthread_mutex_timedlock);
121 	zassert_not_null(pthread_mutex_trylock);
122 	zassert_not_null(pthread_mutex_unlock);
123 	zassert_not_null(pthread_mutexattr_destroy);
124 	zassert_not_null(pthread_mutexattr_getprioceiling);
125 	zassert_not_null(pthread_mutexattr_getprotocol);
126 	/* zassert_not_null(pthread_mutexattr_getpshared); */ /* not implemented */
127 	/* zassert_not_null(pthread_mutexattr_getrobust); */  /* not implemented */
128 	zassert_not_null(pthread_mutexattr_gettype);
129 	zassert_not_null(pthread_mutexattr_init);
130 	zassert_not_null(pthread_mutexattr_setprioceiling);
131 	zassert_not_null(pthread_mutexattr_setprotocol);
132 	/* zassert_not_null(pthread_mutexattr_setpshared); */     /* not implemented */
133 	/* zassert_not_null(pthread_mutexattr_setrobust); */      /* not implemented */
134 	zassert_not_null(pthread_mutexattr_settype);
135 	zassert_not_null(pthread_once);
136 	zassert_not_null(pthread_rwlock_destroy);
137 	zassert_not_null(pthread_rwlock_init);
138 	zassert_not_null(pthread_rwlock_rdlock);
139 	zassert_not_null(pthread_rwlock_timedrdlock);
140 	zassert_not_null(pthread_rwlock_timedwrlock);
141 	zassert_not_null(pthread_rwlock_tryrdlock);
142 	zassert_not_null(pthread_rwlock_trywrlock);
143 	zassert_not_null(pthread_rwlock_unlock);
144 	zassert_not_null(pthread_rwlock_wrlock);
145 	zassert_not_null(pthread_rwlockattr_destroy);
146 	zassert_not_null(pthread_rwlockattr_getpshared);
147 	zassert_not_null(pthread_rwlockattr_init);
148 	zassert_not_null(pthread_rwlockattr_setpshared);
149 	zassert_not_null(pthread_self);
150 	zassert_not_null(pthread_setcancelstate);
151 	zassert_not_null(pthread_setcanceltype);
152 	zassert_not_null(pthread_setconcurrency);
153 	zassert_not_null(pthread_setschedparam);
154 	zassert_not_null(pthread_setschedprio);
155 	zassert_not_null(pthread_setspecific);
156 	zassert_not_null(pthread_spin_destroy);
157 	zassert_not_null(pthread_spin_init);
158 	zassert_not_null(pthread_spin_lock);
159 	zassert_not_null(pthread_spin_trylock);
160 	zassert_not_null(pthread_spin_unlock);
161 	zassert_not_null(pthread_testcancel);
162 #endif
163 }
164 #pragma GCC diagnostic pop
165