-
Notifications
You must be signed in to change notification settings - Fork 7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: posix: common: move barrier test to barrier.c
Move the one barrier test to its own file and create a ZTEST_SUITE() for barrier. Signed-off-by: Christopher Friedt <[email protected]>
- Loading branch information
Showing
2 changed files
with
41 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2023, Harshil Bhatt | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <pthread.h> | ||
#include <semaphore.h> | ||
|
||
#include <zephyr/sys/util.h> | ||
#include <zephyr/ztest.h> | ||
|
||
ZTEST(barrier, test_barrier) | ||
{ | ||
int ret, pshared; | ||
pthread_barrierattr_t attr; | ||
|
||
ret = pthread_barrierattr_init(&attr); | ||
zassert_equal(ret, 0, "pthread_barrierattr_init failed"); | ||
|
||
ret = pthread_barrierattr_getpshared(&attr, &pshared); | ||
zassert_equal(ret, 0, "pthread_barrierattr_getpshared failed"); | ||
zassert_equal(pshared, PTHREAD_PROCESS_PRIVATE, "pshared attribute not set correctly"); | ||
|
||
ret = pthread_barrierattr_setpshared(&attr, PTHREAD_PROCESS_PRIVATE); | ||
zassert_equal(ret, 0, "pthread_barrierattr_setpshared failed"); | ||
|
||
ret = pthread_barrierattr_setpshared(&attr, PTHREAD_PROCESS_PUBLIC); | ||
zassert_equal(ret, 0, "pthread_barrierattr_setpshared failed"); | ||
|
||
ret = pthread_barrierattr_getpshared(&attr, &pshared); | ||
zassert_equal(pshared, PTHREAD_PROCESS_PUBLIC, "pshared attribute not retrieved correctly"); | ||
|
||
ret = pthread_barrierattr_setpshared(&attr, 42); | ||
zassert_equal(ret, -EINVAL, "pthread_barrierattr_setpshared did not return EINVAL"); | ||
|
||
ret = pthread_barrierattr_destroy(&attr); | ||
zassert_equal(ret, 0, "pthread_barrierattr_destroy failed"); | ||
} | ||
|
||
ZTEST_SUITE(barrier, NULL, NULL, NULL, NULL, NULL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters