tests: kernel: posix: add ztest to pthread_cancel

Added ztest to pthread_cancel.

Signed-off-by: Niranjhana N <niranjhana.n@intel.com>
This commit is contained in:
Niranjhana N 2018-02-23 15:19:01 +05:30 committed by Anas Nashif
commit a8d3286a31
3 changed files with 24 additions and 19 deletions

View file

@ -1,2 +1,2 @@
CONFIG_TEST=y
CONFIG_ZTEST=y
CONFIG_PTHREAD_IPC=y

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <tc_util.h>
#include <ztest.h>
#include <pthread.h>
int pthread_cancel(pthread_t pthread);
@ -27,26 +27,25 @@ void *thread_top(void *p1)
}
self = pthread_self();
TC_PRINT("Canceling thread %d\n", (s32_t) p1);
printk("Cancelling thread %d\n", (s32_t) p1);
pthread_cancel(self);
TC_PRINT("Thread %d could not be canceled\n", (s32_t) p1);
printk("Thread %d could not be cancelled\n", (s32_t) p1);
sleep(ONE_SECOND);
exit_count++;
TC_PRINT("Exiting thread %d\n", (s32_t)p1);
pthread_exit(p1);
TC_PRINT("Exited thread %d\n", (s32_t)p1);
printk("Exited thread %d\n", (s32_t)p1);
return NULL;
}
void main(void)
void test_pthread_cancel(void)
{
s32_t i, ret, status = TC_FAIL;
s32_t i, ret;
pthread_attr_t attr[N_THR];
struct sched_param schedparam;
pthread_t newthread[N_THR];
void *retval;
TC_START("POSIX thread cancel APIs\n");
printk("POSIX thread cancel APIs\n");
/* Creating 4 threads with lowest application priority */
for (i = 0; i < N_THR; i++) {
pthread_attr_init(&attr[i]);
@ -69,23 +68,28 @@ void main(void)
pthread_attr_setstack(&attr[i], &stacks[i][0], STACKSZ);
ret = pthread_create(&newthread[i], &attr[i], thread_top,
(void *)i);
if (ret != 0) {
TC_ERROR("Number of threads exceeds Maximum Limit\n");
goto done;
}
/*TESTPOINT: Check if thread is created successfully*/
zassert_false(ret, "Number of threads exceeds max limit\n");
}
for (i = 0; i < N_THR; i++) {
TC_PRINT("Waiting for pthread %d to Join\n", i);
printk("Waiting for pthread %d to Join\n", i);
pthread_join(newthread[i], &retval);
TC_PRINT("Pthread %d joined to %s\n", i, __func__);
printk("Pthread %d joined to %s\n", i, __func__);
}
TC_PRINT("pthread join test over\n");
printk("Pthread join test over\n");
/* Test PASS if all threads have exited before main exit */
status = exit_count == 1 ? TC_PASS : TC_FAIL;
zassert_equal(exit_count, 1, "pthread_cancel test failed\n");
sleep(ONE_SECOND);
done:
TC_END_REPORT(status);
}
void test_main(void)
{
ztest_test_suite(test_pthreads_cancel,
ztest_unit_test(test_pthread_cancel));
ztest_run_test_suite(test_pthreads_cancel);
}

View file

@ -1,3 +1,4 @@
tests:
test:
min_ram: 16
tags: core