Fix for tc_libc_sleep fail issue
authorLokesh B V <lokesh.bv@partner.samsung.com>
Wed, 16 Aug 2017 19:27:41 +0000 (00:57 +0530)
committerLokesh B V <lokesh.bv@partner.samsung.com>
Thu, 17 Aug 2017 05:23:41 +0000 (10:53 +0530)
The tx and rx tasks are used in tc_libc_unistd_pipe are alive and
wakes up the kernel_tc_main task while testing libc sleep.
So tc of libc sleep is failed.
Using 'waitpid' would solve the above issue, but 'waitpid' depends on CONFIG_SCHED_WAITPID.
And if CONFIG_SCHED_WAITPID is disabled we cannot test tc_libc_unistd_pipe.
So It's better to use pthreads instead of tasks.

Signed-off-by: Lokesh B V <lokesh.bv@partner.samsung.com>
apps/examples/testcase/le_tc/kernel/tc_libc_unistd.c

index f6f6806..457e0a4 100644 (file)
@@ -27,6 +27,7 @@
 #include <string.h>
 #include <errno.h>
 #include <sys/types.h>
+#include <pthread.h>
 #include "tc_internal.h"
 
 #define ARG_COUNT 6
@@ -42,18 +43,21 @@ int pipe_fd[2];
 const char msg[MSG_SIZE + 1] = "012345678901234567890123456789";
 char pipe_buf[MSG_SIZE + 1];
 
-static int pipe_tx_func(int argc, char *argv[])
+static void *pipe_tx_func(void *arg)
 {
        int tx_iter;
+
        for (tx_iter = 0; tx_iter < 10; tx_iter++) {
                write(pipe_fd[1], msg, MSG_SIZE);
        }
-       return 0;
+
+       return NULL;
 }
 
-static int pipe_rx_func(int argc, char *argv[])
+static void *pipe_rx_func(void *arg)
 {
        int rx_iter;
+
        for (rx_iter = 0; rx_iter < 10; rx_iter++) {
                read(pipe_fd[0], pipe_buf, MSG_SIZE);
                if (strcmp(pipe_buf, msg) != 0) {
@@ -62,7 +66,7 @@ static int pipe_rx_func(int argc, char *argv[])
        }
        sem_post(&pipe_sem);
 
-       return 0;
+       return NULL;
 }
 
 /**
@@ -227,19 +231,24 @@ static void tc_libc_unistd_usleep(void)
 static void tc_libc_unistd_pipe(void)
 {
        int ret_chk;
-       int pid[2];
+       pthread_t th_id[2];
 
        ret_chk = pipe(pipe_fd);
        TC_ASSERT_NEQ("pipe", ret_chk, ERROR);
 
        sem_init(&pipe_sem, 0, 0);
-       pid[0] = task_create("tx", 99, 1024, pipe_tx_func, NULL);
-       TC_ASSERT_GEQ_CLEANUP("task_create", pid[0], 0, goto cleanup_pipe);
 
-       pid[1] = task_create("rx", 99, 1024, pipe_rx_func, NULL);
-       TC_ASSERT_GEQ_CLEANUP("task_create", pid[1], 0, goto cleanup_pipe);
+       ret_chk = pthread_create(&th_id[0], NULL, pipe_tx_func, NULL);
+       TC_ASSERT_EQ_CLEANUP("pthread_create", ret_chk, OK, goto cleanup_pipe);
+
+       ret_chk = pthread_create(&th_id[1], NULL, pipe_rx_func, NULL);
+       TC_ASSERT_EQ_CLEANUP("pthread_create", ret_chk, OK, goto cleanup_pipe);
+
+       ret_chk = pthread_join(th_id[0], NULL);
+       TC_ASSERT_EQ("pthread_join", ret_chk, OK);
 
-       sem_wait(&pipe_sem);
+       ret_chk = pthread_join(th_id[1], NULL);
+       TC_ASSERT_EQ("pthread_join", ret_chk, OK);
 
        TC_ASSERT_EQ_CLEANUP("pipe", pipe_tc_chk, OK, goto cleanup_pipe);