1 /*
2  * Copyright (c) 2023, Harshil Bhatt
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <pthread.h>
8 #include <semaphore.h>
9 
10 #include <zephyr/sys/util.h>
11 #include <zephyr/ztest.h>
12 
ZTEST(barrier,test_barrier)13 ZTEST(barrier, test_barrier)
14 {
15 	int ret, pshared;
16 	pthread_barrierattr_t attr;
17 
18 	ret = pthread_barrierattr_init(&attr);
19 	zassert_equal(ret, 0, "pthread_barrierattr_init failed");
20 
21 	ret = pthread_barrierattr_getpshared(&attr, &pshared);
22 	zassert_equal(ret, 0, "pthread_barrierattr_getpshared failed");
23 	zassert_equal(pshared, PTHREAD_PROCESS_PRIVATE, "pshared attribute not set correctly");
24 
25 	ret = pthread_barrierattr_setpshared(&attr, PTHREAD_PROCESS_PRIVATE);
26 	zassert_equal(ret, 0, "pthread_barrierattr_setpshared failed");
27 
28 	ret = pthread_barrierattr_setpshared(&attr, PTHREAD_PROCESS_PUBLIC);
29 	zassert_equal(ret, 0, "pthread_barrierattr_setpshared failed");
30 
31 	ret = pthread_barrierattr_getpshared(&attr, &pshared);
32 	zassert_equal(pshared, PTHREAD_PROCESS_PUBLIC, "pshared attribute not retrieved correctly");
33 
34 	ret = pthread_barrierattr_setpshared(&attr, 42);
35 	zassert_equal(ret, -EINVAL, "pthread_barrierattr_setpshared did not return EINVAL");
36 
37 	ret = pthread_barrierattr_destroy(&attr);
38 	zassert_equal(ret, 0, "pthread_barrierattr_destroy failed");
39 }
40 
41 ZTEST_SUITE(barrier, NULL, NULL, NULL, NULL, NULL);
42