Skip to content

Commit

Permalink
posix: Implement tests for set and get scope APIs for pthread attr
Browse files Browse the repository at this point in the history
Add tests for `pthread_attr_setscope()`
and `pthread_attr_getscope()`

signed-off-by: Gaetan Perrot <gaetanperrotpro@gmail.com>
  • Loading branch information
moonlight83340 committed Feb 5, 2024
1 parent 66c8034 commit 4af97a5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
42 changes: 42 additions & 0 deletions tests/posix/common/src/pthread_attr.c
Expand Up @@ -439,6 +439,48 @@ ZTEST(pthread_attr, test_pthread_attr_setstacksize)
}
}

ZTEST(pthread_attr, test_pthread_attr_getscope)
{
int contentionscope = BIOS_FOOD;

/* degenerate cases */
{
if (false) {
/* undefined behaviour */
zassert_equal(pthread_attr_getscope(NULL, NULL), EINVAL);
zassert_equal(pthread_attr_getscope(NULL, &contentionscope), EINVAL);
zassert_equal(pthread_attr_getscope(&uninit_attr, &contentionscope),
EINVAL);
}
zassert_equal(pthread_attr_getscope(&attr, NULL), EINVAL);
}

zassert_ok(pthread_attr_getscope(&attr, &contentionscope));
zassert_equal(contentionscope, PTHREAD_SCOPE_SYSTEM);
}

ZTEST(pthread_attr, test_pthread_attr_setscope)
{
int contentionscope = BIOS_FOOD;

/* degenerate cases */
{
if (false) {
/* undefined behaviour */
zassert_equal(pthread_attr_setscope(NULL, PTHREAD_SCOPE_SYSTEM), EINVAL);
zassert_equal(pthread_attr_setscope(NULL, contentionscope), EINVAL);
zassert_equal(pthread_attr_setscope((pthread_attr_t *)&uninit_attr,
contentionscope), EINVAL);
}
zassert_equal(pthread_attr_setscope(&attr, 3), EINVAL);
}

zassert_equal(pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS), ENOTSUP);
zassert_ok(pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM));
zassert_ok(pthread_attr_getscope(&attr, &contentionscope));
zassert_equal(contentionscope, PTHREAD_SCOPE_SYSTEM);
}

ZTEST(pthread_attr, test_pthread_attr_large_stacksize)
{
size_t actual_size;
Expand Down
8 changes: 4 additions & 4 deletions tests/posix/headers/src/pthread_h.c
Expand Up @@ -53,8 +53,8 @@ ZTEST(posix_headers, test_pthread_h)
zassert_not_equal(-1, PTHREAD_PROCESS_SHARED);
zassert_not_equal(-1, PTHREAD_PROCESS_PRIVATE);

/* zassert_not_equal(-1, PTHREAD_SCOPE_PROCESS); */ /* not implemented */
/* zassert_not_equal(-1, PTHREAD_SCOPE_SYSTEM); */ /* not implemented */
zassert_not_equal(-1, PTHREAD_SCOPE_PROCESS);
zassert_not_equal(-1, PTHREAD_SCOPE_SYSTEM);

pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t mu = PTHREAD_MUTEX_INITIALIZER;
Expand All @@ -68,7 +68,7 @@ ZTEST(posix_headers, test_pthread_h)
/* zassert_not_null(pthread_attr_getinheritsched); */ /* not implemented */
zassert_not_null(pthread_attr_getschedparam);
zassert_not_null(pthread_attr_getschedpolicy);
/* zassert_not_null(pthread_attr_getscope); */ /* not implemented */
zassert_not_null(pthread_attr_getscope);
zassert_not_null(pthread_attr_getstack);
zassert_not_null(pthread_attr_getstacksize);
zassert_not_null(pthread_attr_init);
Expand All @@ -77,7 +77,7 @@ ZTEST(posix_headers, test_pthread_h)
/* zassert_not_null(pthread_attr_setinheritsched); */ /* not implemented */
zassert_not_null(pthread_attr_setschedparam);
zassert_not_null(pthread_attr_setschedpolicy);
/* zassert_not_null(pthread_attr_setscope); */ /* not implemented */
zassert_not_null(pthread_attr_setscope);
zassert_not_null(pthread_attr_setstack);
zassert_not_null(pthread_attr_setstacksize);
zassert_not_null(pthread_barrier_destroy);
Expand Down

0 comments on commit 4af97a5

Please sign in to comment.