tests: posix: pthread: Clean up test for pthread_getname/setname_np

Recently added test for pthread_getname_np()/pthread_setname_np()
functions used uninitialized array value. As we can't check behavior
for arbitrary uninitialized value, but at most NULL value, make the
test calls to explicitly use NULL, to make the test intent clear
(instead of for example initializing the original array with zeros).

Also, these test cases use variable names not consistent with Zephyr
codestyle, and named to generically to cause confuse when used in a
general context of the test_posix_pthread_execution() function, so
rename them to be specific. (And alternative would be to separate
pthread_getname_np()/pthread_setname_np() tests into a separate
function, but it was indeed practical to piggyback them on existing
test_posix_pthread_execution()).

Fixes: #23473

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
This commit is contained in:
Paul Sokolovsky 2020-03-18 13:09:36 +02:00 committed by Anas Nashif
commit 79a58ddffa

View file

@ -239,8 +239,8 @@ void test_posix_pthread_execution(void)
void *retval, *stackaddr;
size_t stacksize;
int serial_threads = 0;
char name[] = "thread name";
char getName[CONFIG_THREAD_MAX_NAME_LEN];
const char thr_name[] = "thread name";
char thr_name_buf[CONFIG_THREAD_MAX_NAME_LEN];
sem_init(&main_sem, 0, 1);
schedparam.sched_priority = CONFIG_NUM_COOP_PRIORITIES - 1;
@ -289,12 +289,16 @@ void test_posix_pthread_execution(void)
ret = pthread_attr_destroy(&attr[0]);
zassert_equal(ret, EINVAL, "uninitialized attr destroyed!");
/* TESTPOINT: Try getting thread name before init */
ret = pthread_getname_np(newthread[0], getName, sizeof(getName));
/* TESTPOINT: Try getting name of NULL thread (aka uninitialized
* thread var).
*/
ret = pthread_getname_np(NULL, thr_name_buf, sizeof(thr_name_buf));
zassert_equal(ret, ESRCH, "uninitialized getname!");
/* TESTPOINT: Try setting thread name before init */
ret = pthread_setname_np(newthread[0], name);
/* TESTPOINT: Try setting name of NULL thread (aka uninitialized
* thread var).
*/
ret = pthread_setname_np(NULL, thr_name);
zassert_equal(ret, ESRCH, "uninitialized setname!");
/* TESTPOINT: Try creating thread before attr init */
@ -340,7 +344,7 @@ void test_posix_pthread_execution(void)
}
/* TESTPOINT: Try getting thread name with no buffer */
ret = pthread_getname_np(newthread[0], NULL, sizeof(getName));
ret = pthread_getname_np(newthread[0], NULL, sizeof(thr_name_buf));
zassert_equal(ret, EINVAL, "uninitialized getname!");
/* TESTPOINT: Try setting thread name with no buffer */
@ -348,15 +352,17 @@ void test_posix_pthread_execution(void)
zassert_equal(ret, EINVAL, "uninitialized setname!");
/* TESTPOINT: Try setting thread name */
ret = pthread_setname_np(newthread[0], name);
zassert_false(ret, "Set name failed!");
ret = pthread_setname_np(newthread[0], thr_name);
zassert_false(ret, "Set thread name failed!");
/* TESTPOINT: Try getting thread name */
ret = pthread_getname_np(newthread[0], getName, sizeof(getName));
zassert_false(ret, "Get name failed!");
ret = pthread_getname_np(newthread[0], thr_name_buf,
sizeof(thr_name_buf));
zassert_false(ret, "Get thread name failed!");
/* TESTPOINT: Thread names match */
ret = strncmp(name, getName, min(strlen(name), strlen(getName)));
ret = strncmp(thr_name, thr_name_buf, min(strlen(thr_name),
strlen(thr_name_buf)));
zassert_false(ret, "Thread names don't match!");
while (!bounce_test_done()) {