tests: posix: Fixing pthread attr object initialization.
In some cases pthread attrib initialization may fail as garbare value may indicate that this attribute is already initialized. Destroy the attr object and recreate it. Signed-off-by: Niranjhana N <niranjhana.n@intel.com>
This commit is contained in:
parent
1ccd715577
commit
2ecaee071c
@ -197,9 +197,12 @@ void test_pthread(void)
|
||||
|
||||
for (i = 0; i < N_THR; i++) {
|
||||
ret = pthread_attr_init(&attr[i]);
|
||||
|
||||
/*TESTPOINT: Check if thread attr init is done*/
|
||||
zassert_false(ret, "Thread attribute initialization failed\n");
|
||||
if (ret != 0) {
|
||||
zassert_false(pthread_attr_destroy(&attr[i]),
|
||||
"Unable to destroy pthread object attrib\n");
|
||||
zassert_false(pthread_attr_init(&attr[i]),
|
||||
"Unable to create pthread object attrib\n");
|
||||
}
|
||||
|
||||
pthread_attr_setstack(&attr[i], &stacks[i][0], STACKSZ);
|
||||
pthread_attr_setschedpolicy(&attr[i], schedpolicy);
|
||||
|
||||
@ -22,12 +22,19 @@ void *thread_top(void *p1)
|
||||
|
||||
void test_pthread_equal(void)
|
||||
{
|
||||
int ret = 1;
|
||||
int ret = -1;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param schedparam;
|
||||
pthread_t newthread;
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
ret = pthread_attr_init(&attr);
|
||||
if (ret != 0) {
|
||||
zassert_false(pthread_attr_destroy(&attr),
|
||||
"Unable to destroy pthread object attrib\n");
|
||||
zassert_false(pthread_attr_init(&attr),
|
||||
"Unable to create pthread object attrib\n");
|
||||
}
|
||||
|
||||
schedparam.priority = 2;
|
||||
pthread_attr_setschedparam(&attr, &schedparam);
|
||||
pthread_attr_setstack(&attr, &stacks[0][0], STACKSZ);
|
||||
|
||||
@ -56,7 +56,13 @@ void test_pthread_join(void)
|
||||
printk("POSIX pthread join API\n");
|
||||
/* Creating threads with lowest application priority */
|
||||
for (i = 0; i < N_THR; i++) {
|
||||
pthread_attr_init(&attr[i]);
|
||||
ret = pthread_attr_init(&attr[i]);
|
||||
if (ret != 0) {
|
||||
zassert_false(pthread_attr_destroy(&attr[i]),
|
||||
"Unable to destroy pthread object attrib\n");
|
||||
zassert_false(pthread_attr_init(&attr[i]),
|
||||
"Unable to create pthread object attrib\n");
|
||||
}
|
||||
|
||||
/* Setting pthread as JOINABLE */
|
||||
pthread_attr_getdetachstate(&attr[i], &detachstate);
|
||||
|
||||
@ -29,11 +29,17 @@ static void test_sema(void)
|
||||
pthread_attr_t attr;
|
||||
struct sched_param schedparam;
|
||||
int schedpolicy = SCHED_FIFO;
|
||||
int val;
|
||||
int val, ret;
|
||||
|
||||
schedparam.priority = 1;
|
||||
ret = pthread_attr_init(&attr);
|
||||
if (ret != 0) {
|
||||
zassert_false(pthread_attr_destroy(&attr),
|
||||
"Unable to destroy pthread object attrib\n");
|
||||
zassert_false(pthread_attr_init(&attr),
|
||||
"Unable to create pthread object attrib\n");
|
||||
}
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstack(&attr, &stack, STACK_SIZE);
|
||||
pthread_attr_setschedpolicy(&attr, schedpolicy);
|
||||
pthread_attr_setschedparam(&attr, &schedparam);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user