Refactor tc; output format and tc scenario 97/114297/1
authorjunmin.kim <junmindd.kim@samsung.com>
Mon, 13 Feb 2017 01:38:42 +0000 (17:38 -0800)
committerjunmin.kim <junmindd.kim@samsung.com>
Mon, 13 Feb 2017 01:38:42 +0000 (17:38 -0800)
Apply output format : [test name] PASS/FAIL
And make sure tc work well when cancellation point is set

Change-Id: I50d38587cba38a64603a281f60a773acb1201662

32 files changed:
apps/examples/testcase/le_tc/kernel/tc_clock.c
apps/examples/testcase/le_tc/kernel/tc_environ.c
apps/examples/testcase/le_tc/kernel/tc_errno.c
apps/examples/testcase/le_tc/kernel/tc_group.c
apps/examples/testcase/le_tc/kernel/tc_libc_libgen.c
apps/examples/testcase/le_tc/kernel/tc_libc_math.c
apps/examples/testcase/le_tc/kernel/tc_libc_misc.c
apps/examples/testcase/le_tc/kernel/tc_libc_pthread.c
apps/examples/testcase/le_tc/kernel/tc_libc_queue.c
apps/examples/testcase/le_tc/kernel/tc_libc_sched.c
apps/examples/testcase/le_tc/kernel/tc_libc_semaphore.c
apps/examples/testcase/le_tc/kernel/tc_libc_signal.c
apps/examples/testcase/le_tc/kernel/tc_libc_spawn.c
apps/examples/testcase/le_tc/kernel/tc_libc_stdio.c
apps/examples/testcase/le_tc/kernel/tc_libc_stdlib.c
apps/examples/testcase/le_tc/kernel/tc_libc_string.c
apps/examples/testcase/le_tc/kernel/tc_libc_syslog.c
apps/examples/testcase/le_tc/kernel/tc_libc_timer.c
apps/examples/testcase/le_tc/kernel/tc_libc_unistd.c
apps/examples/testcase/le_tc/kernel/tc_mqueue.c
apps/examples/testcase/le_tc/kernel/tc_pthread.c
apps/examples/testcase/le_tc/kernel/tc_roundrobin.c
apps/examples/testcase/le_tc/kernel/tc_sched.c
apps/examples/testcase/le_tc/kernel/tc_semaphore.c
apps/examples/testcase/le_tc/kernel/tc_signal.c
apps/examples/testcase/le_tc/kernel/tc_tash_heapinfo.c
apps/examples/testcase/le_tc/kernel/tc_tash_stackmonitor.c
apps/examples/testcase/le_tc/kernel/tc_task.c
apps/examples/testcase/le_tc/kernel/tc_termios.c
apps/examples/testcase/le_tc/kernel/tc_timer.c
apps/examples/testcase/le_tc/kernel/tc_umm_heap.c
apps/examples/testcase/tc_common.h

index 659d887..8b126cf 100644 (file)
@@ -57,17 +57,14 @@ static void tc_clock_clock_initialize(void)
        jdn = clock_calendar2utc(CONFIG_START_YEAR, CONFIG_START_MONTH, CONFIG_START_DAY);
 
        clock_initialize();
-       /*
-          g_basetime.tv_sec base time is getting as seconds into this julian day. hence we need to compare it that same
-        */
-       if (g_basetime.tv_nsec != 0 || g_basetime.tv_sec != (jdn * SEC_PER_DAY)) {
-               printf("tc_clock_clock_initialize FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
 
-       printf("tc_clock_clock_initialize PASS\n");
-       total_pass++;
+       /* g_basetime.tv_sec base time is getting as seconds into this julian day.
+        * hence we need to compare it that same */
+
+       TC_ASSERT_EQ("clock_initialize", g_basetime.tv_nsec, 0);
+       TC_ASSERT_EQ("clock_initialize", g_basetime.tv_sec, jdn * SEC_PER_DAY);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -85,19 +82,15 @@ static void tc_clock_clock_getres(void)
        struct timespec st_res;
 
        st_res.tv_sec = SEC_10;
-       ret_chk = clock_getres(CLOCK_REALTIME, &st_res);        /* It only work for realtime. */
-       if (ret_chk != OK) {
-               printf("tc_clock_clock_getres CLOCK_REALTIME FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       if ((st_res.tv_sec != 0) || (st_res.tv_nsec != NSEC_PER_TICK)) {
-               printf("tc_clock_clock_getres CLOCK_REALTIME FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_clock_clock_getres PASS\n");
-       total_pass++;
+
+       /* It only work for realtime. */
+
+       ret_chk = clock_getres(CLOCK_REALTIME, &st_res);
+       TC_ASSERT_EQ("clock_getres", ret_chk, OK);
+       TC_ASSERT_EQ("clock_getres", st_res.tv_sec, 0);
+       TC_ASSERT_EQ("clock_getres", st_res.tv_nsec, NSEC_PER_TICK);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -111,45 +104,34 @@ static void tc_clock_clock_getres(void)
 */
 static void tc_clock_clock_set_get_time(void)
 {
+       int ret_chk;
        struct timespec stime;
        struct timespec gtime;
-       if (clock_gettime(CLOCK_REALTIME, &stime) == ERROR) {
-               printf("tc_clock_clock_set_get_time: initial gettime FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+
+       ret_chk = clock_gettime(CLOCK_REALTIME, &stime);
+       TC_ASSERT_EQ("clock_gettime", ret_chk, OK);
+
        stime.tv_sec += l_day;          /* Add one day */
        stime.tv_nsec = 0;
-       if (clock_settime(CLOCK_REALTIME, &stime) == ERROR) {
-               printf("tc_clock_clock_set_get_time FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = clock_settime(CLOCK_REALTIME, &stime);
+       TC_ASSERT_EQ("clock_settime", ret_chk, OK);
 
        sleep(SEC_2);
 
-       if (clock_gettime(CLOCK_REALTIME, &gtime) == ERROR) {
-               printf("tc_clock_clock_set_get_time: gettime FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = clock_gettime(CLOCK_REALTIME, &gtime);
+       TC_ASSERT_EQ("clock_gettime", ret_chk, OK);
 
-       if (!(stime.tv_sec + SEC_2 <= gtime.tv_sec && stime.tv_nsec <= gtime.tv_nsec)) {
-               printf("tc_clock_clock_set_get_time FAIL: get value should be greater than set value\n");
-               total_fail++;
-               RETURN_ERR;
+       TC_ASSERT_GEQ("clock_gettime", gtime.tv_sec, stime.tv_sec + SEC_2);
+       if (gtime.tv_sec == stime.tv_sec + SEC_2) {
+               TC_ASSERT_GEQ("clock_gettime", gtime.tv_nsec, stime.tv_nsec);
        }
 
        stime.tv_sec -= l_day;          /* Setting original time to system */
 
-       if (clock_settime(CLOCK_REALTIME, &stime) == ERROR) {
-               printf("tc_clock_clock_set_get_time FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = clock_settime(CLOCK_REALTIME, &stime);
+       TC_ASSERT_EQ("clock_setime", ret_chk, OK);
 
-       printf("tc_clock_clock_set_get_time PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -163,56 +145,24 @@ static void tc_clock_clock_set_get_time(void)
 */
 static void tc_clock_clock_gettimeofday(void)
 {
-       int ret_chk = 0;
-
-       struct timeval *st_tvptr_1 = (struct timeval *)malloc(sizeof(struct timeval));
-       struct timeval *st_tvptr_2 = (struct timeval *)malloc(sizeof(struct timeval));
-
-       ret_chk = gettimeofday(st_tvptr_1, NULL);
-       if (ret_chk != OK) {
-               printf("tc_clock_clock_gettimeofday FAIL, Error No: %d\n", errno);
-               total_fail++;
-               free(st_tvptr_1);
-               free(st_tvptr_2);
-               RETURN_ERR;
-       }
-       if (st_tvptr_1 == NULL) {       /* check fail condition */
-               printf("tc_clock_clock_gettimeofday FAIL: Time Value is not filled\n");
-               total_fail++;
-               free(st_tvptr_1);
-               free(st_tvptr_2);
-               RETURN_ERR;
-       }
+       int ret_chk;
+       struct timeval tv1;
+       struct timeval tv2;
+
+       ret_chk = gettimeofday(&tv1, NULL);
+       TC_ASSERT_EQ("gettimeofday", ret_chk, OK);
 
        sleep(SEC_2);
 
-       ret_chk = gettimeofday(st_tvptr_2, NULL);
-       if (ret_chk != OK) {
-               printf("tc_clock_clock_gettimeofday FAIL, Error No: %d\n", errno);
-               total_fail++;
-               free(st_tvptr_1);
-               free(st_tvptr_2);
-               RETURN_ERR;
-       }
-       if (st_tvptr_2 == NULL) {       /* check total_fail condition */
-               printf("tc_clock_clock_gettimeofday FAIL: Time Value is not filled\n");
-               total_fail++;
-               free(st_tvptr_1);
-               RETURN_ERR;
-       }
+       ret_chk = gettimeofday(&tv2, NULL);
+       TC_ASSERT_EQ("gettimeofday", ret_chk, OK);
 
-       if (st_tvptr_2->tv_sec < st_tvptr_1->tv_sec || st_tvptr_2->tv_usec < st_tvptr_1->tv_usec) {
-               printf("tc_clock_clock_gettimeofday FAIL: Time Value error\n");
-               total_fail++;
-               free(st_tvptr_1);
-               free(st_tvptr_2);
-               RETURN_ERR;
+       TC_ASSERT_GEQ("gettimeofday", tv2.tv_sec, tv1.tv_sec + SEC_2);
+       if (tv2.tv_sec == tv1.tv_sec + SEC_2) {
+               TC_ASSERT_GEQ("gettimeofday", tv2.tv_usec, tv1.tv_usec);
        }
 
-       free(st_tvptr_1);
-       free(st_tvptr_2);
-       printf("tc_clock_clock_gettimeofday PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -231,14 +181,9 @@ static void tc_clock_clock_timer(void)
        systime_t itime = g_system_timer;
        clock_timer();
        itime++;
-       if (itime != g_system_timer) {
-               printf("tc_clock_clock_timer FAIL.\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("clock_timer", itime, g_system_timer);
 
-       printf("tc_clock_clock_timer PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -255,13 +200,9 @@ static void tc_clock_clock_systimer(void)
 {
        systime_t itime = ERROR;
        itime = clock_systimer();
-       if (itime < 0) {
-               printf("tc_clock_clock_systimer FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_clock_clock_systimer PASS\n");
-       total_pass++;
+       TC_ASSERT_GEQ("clock_systimer", itime, 0);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -277,13 +218,9 @@ static void tc_clock_clock_systimer64(void)
 {
        systime_t itime = ERROR;
        itime = clock_systimer();
-       if (itime < 0) {
-               printf("tc_clock_clock_systimer64, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_clock_clock_systimer64 PASS\n");
-       total_pass++;
+       TC_ASSERT_GEQ("clock_systimer", itime, 0);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -297,37 +234,27 @@ static void tc_clock_clock_systimer64(void)
  */
 static void tc_clock_clock_abstime2ticks(void)
 {
-       struct timespec base_time;
-       struct timespec comparison_time;
+       int ret_chk;
        int base_tick;
        int comparison_tick;
-       int ret = ERROR;
+       struct timespec base_time;
+       struct timespec comparison_time;
 
        clock_gettime(CLOCK_REALTIME, &base_time);
        base_time.tv_sec *= 2;
        comparison_time.tv_sec = base_time.tv_sec * 2;
 
-       ret = clock_abstime2ticks(CLOCK_REALTIME, &base_time, &base_tick);
-       if (ret != OK) {
-               total_fail++;
-               printf("tc_clock_clock_abstime2ticks FAIL %d\n", base_tick);
-               RETURN_ERR;
-       }
-       ret = clock_abstime2ticks(CLOCK_REALTIME, &comparison_time, &comparison_tick);
-       if (ret != OK) {
-               total_fail++;
-               printf("tc_clock_clock_abstime2ticks FAIL %d %d\n", base_tick, comparison_tick);
-               RETURN_ERR;
-       }
+       ret_chk = clock_abstime2ticks(CLOCK_REALTIME, &base_time, &base_tick);
+       TC_ASSERT_EQ("clock_abstime2ticks", ret_chk, OK);
+
+       ret_chk = clock_abstime2ticks(CLOCK_REALTIME, &comparison_time, &comparison_tick);
+       TC_ASSERT_EQ("clock_abstime2ticks", ret_chk, OK);
 
        /* the difference can be 0 or 1, but should be smaller than 2 */
-       if (comparison_tick - (base_tick * 2) < 2) {
-               total_fail++;
-               printf("tc_clock_clock_abstime2ticks FAIL %d %d\n", base_tick, comparison_tick);
-               RETURN_ERR;
-       }
-       total_pass++;
-       printf("tc_clock_clock_abstime2ticks PASS\n");
+
+       TC_ASSERT_GEQ("clock_abstime2ticks", comparison_tick - (base_tick * 2), 2);
+
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index da06251..9a686cd 100644 (file)
@@ -55,64 +55,40 @@ static void tc_environ_setenv_getenv_unsetenv(void)
        char *psz_getvalue = NULL;
 
        ret_chk = setenv(psz_name, psz_value, overwrite_num);
-       if (ret_chk != OK) {
-               printf("tc_environ_setenv FAIL in setting environment with overwrite_num = 1, Error No: %d\n", errno);
-               total_fail++;
-               clearenv();
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ_CLEANUP("setenv", ret_chk, OK, get_errno(), clearenv());
 
        psz_getvalue = getenv(psz_name);
-       if (strcmp(psz_getvalue, psz_value) != OK) {
-               printf("tc_environ_getenv FAIL, set and get value are not same, Error No: %d\n", errno);
-               total_fail++;
-               clearenv();
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ_CLEANUP("getenv", strcmp(psz_getvalue, psz_value), 0, get_errno(), clearenv());
 
        /* with overwrite_num = 0, psz_value should not be updated */
+
        psz_value = "pqr";
        overwrite_num = 0;
        ret_chk = setenv(psz_name, psz_value, overwrite_num);
-       if (ret_chk != OK) {
-               printf("tc_environ_setenv FAIL in setting environment with overwrite_num = 0, Error No: %d\n", errno);
-               total_fail++;
-               clearenv();
-               RETURN_ERR;
-       }
-       psz_getvalue = getenv(psz_name);
+       TC_ASSERT_EQ_CLEANUP("setenv", ret_chk, OK, get_errno(), clearenv());
+
        /* set and get value should not be equal as overwrite is 0 */
-       if (strcmp(psz_getvalue, psz_value) == OK) {
-               printf("tc_environ_setenv FAIL, it should have not set environment variable as overwrite_num = 0, Error No: %d\n", errno);
-               total_fail++;
-               clearenv();
-               RETURN_ERR;
-       }
 
-       psz_getvalue = getenv("arv");   /* random value, getenv should fail */
-       if (psz_getvalue != NULL) {
-               printf("tc_environ_getenv FAIL, returned value should be null, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       psz_getvalue = getenv(psz_name);
+       TC_ASSERT_NEQ_CLEANUP("getenv", strcmp(psz_getvalue, psz_value), 0, get_errno(), clearenv());
+
+       /* random value, getenv should fail */
+
+       psz_getvalue = getenv("arv");
+       TC_ASSERT_EQ("getenv", psz_getvalue, NULL);
+
        /* random value, unsetenv should not fail */
+
        ret_chk = unsetenv(pusz_name);
-       if (ret_chk != OK) {
-               printf("tc_environ_unsetenv FAIL in unseting environment, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("unsetenv", ret_chk, OK);
 
-       psz_getvalue = getenv("arv");   /* getvalue should be null */
-       if (psz_getvalue != NULL) {
-               printf("tc_environ_unsetenv FAIL, getenv should return null Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_environ_setenv_getenv_unsetenv PASS \n");
+       /* getvalue should be null */
+
+       psz_getvalue = getenv("arv");
+       TC_ASSERT_EQ("getenv", psz_getvalue, NULL);
 
-       total_pass++;
        clearenv();
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -134,27 +110,15 @@ static void tc_environ_clearenv(void)
        int overwrite_num = 1;
 
        ret_chk = setenv(psz_name, psz_value, overwrite_num);
-       if (ret_chk != OK) {
-               printf("tc_environ_setenv FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("setenv", ret_chk, OK);
 
        ret_chk = clearenv();
-       if (ret_chk != OK) {
-               printf("tc_environ_clearenv FAIL, Error No: %d\n", errno);
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("clearenv", ret_chk, OK);
 
        psz_getvalue = getenv(psz_name);
-       if (psz_getvalue != NULL) {
-               printf("tc_environ_getenv, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("getenv", psz_getvalue, NULL);
 
-       printf("tc_environ_clearenv PASS \n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -169,33 +133,26 @@ static void tc_environ_clearenv(void)
 */
 static void tc_environ_putenv(void)
 {
+       int ret_chk;
        char *psz_getvalue = NULL;
        /* adding enviroment variable */
 
-       putenv("PATH=C:");
+       ret_chk = putenv("PATH=C:");
+       TC_ASSERT_EQ("putenv", ret_chk, OK);
+
        psz_getvalue = getenv("PATH");
-       if (psz_getvalue == NULL) {
-               printf("tc_environ_putenv, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (strcmp(psz_getvalue, "C:") != OK) {
-               printf("tc_environ_putenv FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("getenv", psz_getvalue);
+       TC_ASSERT_EQ("getenv", strcmp(psz_getvalue, "C:"), 0);
 
        /* Changing the value of already existing PATH variable */
-       putenv("PATH=D:");
+       ret_chk = putenv("PATH=D:");
+       TC_ASSERT_EQ("putenv", ret_chk, OK);
+
        psz_getvalue = getenv("PATH");
-       if (strcmp(psz_getvalue, "D:") != OK) {
-               printf("tc_environ_putenv FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_environ_putenv PASS \n");
-       total_pass++;
+       TC_ASSERT_EQ("getenv", strcmp(psz_getvalue, "D:"), 0);
+
        clearenv();
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -225,31 +182,21 @@ static void tc_environ_get_environ_ptr(void)
                setenv(env_name, env_val, TRUE);
                snprintf(env_arr[env_idx], ENV_TEST_LEN * 2, "%s=%s", env_name, getenv(env_name));
        }
+
        env_ptr = get_environ_ptr(&env_size);
+       TC_ASSERT_NOT_NULL("get_environ_ptr", env_ptr);
 
-       if (env_ptr == NULL) {
-               printf("tc_environ_get_environ_ptr FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
        /* env_size is set to length of all env name and val pair */
-       if (env_size != cmp_size) {
-               printf("tc_environ_get_environ_ptr FAIL : size of env, not matched\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+
+       TC_ASSERT_EQ("get_environ_ptr", env_size, cmp_size);
+
        for (env_idx = 0; env_idx < ENV_TEST_MAX_NUM; env_idx++) {
-               if (strcmp(env_arr[env_idx], env_ptr)) {
-                       printf("tc_environ_get_environ_ptr FAIL : not matched\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("get_environ_ptr", strcmp(env_arr[env_idx], env_ptr), 0);
                env_ptr += strlen(env_ptr) + 1;
        }
 
-       printf("tc_environ_get_environ_ptr PASS \n");
-       total_pass++;
        clearenv();
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index 582713d..45adb77 100644 (file)
@@ -56,40 +56,28 @@ static void tc_errno_set_get_errno_and_ptr(void)
                if (err_index != 41 && err_index != 58) {
                        errcode = err_index;
                        set_errno(errcode);
+
                        ret_chk = get_errno();
+                       TC_ASSERT_EQ("get_errno", ret_chk, errcode);
+
 #if !defined(CONFIG_BUILD_PROTECTED)
                        ret_ptr_chk = *get_errno_ptr();
+                       TC_ASSERT_EQ("get_errno_ptr", ret_ptr_chk, errcode);
 #endif
-                       if (ret_chk != errcode
-#if !defined(CONFIG_BUILD_PROTECTED)
-                               || ret_ptr_chk != errcode
-#endif
-                               ) {
-                               printf("tc_errno_set_get_errno_and_ptr FAIL, Error No: %d\n", errno);
-                               total_fail++;
-                               RETURN_ERR;
-                       }
 
                        ret_err = (char *)strerror(ret_chk);
-                       if (strncmp(ret_err, errstr_arr[err_index - 1], strlen(ret_err)) != OK) {
-                               printf("tc_errno_perror FAIL\n");
-                               total_fail++;
-                               RETURN_ERR;
-                       }
+                       TC_ASSERT_NOT_NULL("strerror", ret_err);
+                       TC_ASSERT_EQ("strerror", strncmp(ret_err, errstr_arr[err_index - 1], strlen(ret_err)), 0);
+
 #if !defined(CONFIG_BUILD_PROTECTED)
-                       ret_err = NULL;
                        ret_err = (char *)strerror(ret_ptr_chk);
-                       if (strncmp(ret_err, errstr_arr[err_index - 1], strlen(ret_err)) != OK) {
-                               printf("tc_errno_perror FAIL\n");
-                               total_fail++;
-                               RETURN_ERR;
-                       }
+                       TC_ASSERT_NOT_NULL("strerror", ret_err);
+                       TC_ASSERT_EQ("strerror", strncmp(ret_err, errstr_arr[err_index - 1], strlen(ret_err)), 0);
 #endif
                }
        }
 
-       printf("tc_errno_set_get_errno_and_ptr PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index 1c03522..f5bd651 100644 (file)
@@ -52,25 +52,13 @@ static void tc_group_group_add_find_remove_child(void)
        pid_t child_pid;
 
        st_tcb = sched_self();
-       if (!st_tcb) {
-               printf("tc_group_group_add_find_remove_child FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("sched_self", st_tcb);
 
        group = st_tcb->group;
-       if (!group) {
-               printf("tc_group_group_add_find_remove_child FAIL");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("sched_self", group);
 
        child = group_allocchild();
-       if (child == NULL) {
-               printf("tc_group_group_add_find_remove_child FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("group_allocchild", child);
 
        child_pid = -1;
        child->ch_flags = TCB_FLAG_TTYPE_TASK;
@@ -81,30 +69,20 @@ static void tc_group_group_add_find_remove_child(void)
 
        /* cross check starts */
        child_returned = group_findchild(group, child_pid);
-       if (child != child_returned) {
-               printf("tc_group_group_add_find_remove_child FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("group_findchild", child, child_returned);
 
        child_returned = group_removechild(group, child_pid);
-       if (child != child_returned) {
-               printf("tc_group_group_add_find_remove_child FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("group_removechild", child, child_returned);
+
        child_returned = group_findchild(group, child_pid);
-       if (child_returned != NULL) {
-               printf("tc_group_group_add_find_remove_child FAIL\n");
-               group_removechild(group, child_pid);
-               group_freechild(child);
-               total_fail++;
-               RETURN_ERR;
-       }
-       group_freechild(child);
+       TC_ASSERT_EQ_CLEANUP("group_removechild",
+                                                child_returned,
+                                                NULL,
+                                                get_errno(),
+                                                (group_removechild(group, child_pid), group_freechild(child)));
 
-       printf("tc_group_group_add_find_remove_child PASS\n");
-       total_pass++;
+       group_freechild(child);
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -122,41 +100,20 @@ static void tc_group_group_alloc_free_child(void)
        struct child_status_s child_dummy;
 
        st_tcb = sched_self();
-       if (!st_tcb) {
-               printf("tc_group_group_alloc_free_child FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("sched_self", st_tcb);
 
        group = st_tcb->group;
-       if (!group) {
-               printf("tc_group_group_alloc_free_child FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("sched_self", group);
 
        child = group_allocchild();
-       if (child == NULL) {
-               printf("tc_group_group_alloc_free_child FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (child->flink != NULL) {
-               printf("tc_group_group_alloc_free_child FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("group_allocchild", child);
+       TC_ASSERT_EQ("group_allocchild", child->flink, NULL);
 
        child->flink = &child_dummy;
        group_freechild(child);
-       if (child->flink == &child_dummy) {
-               printf("tc_group_group_alloc_free_child FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       printf("tc_group_group_alloc_free_child PASS \n");
-       total_pass++;
+       TC_ASSERT_NEQ("group_allocchild", child->flink, &child_dummy);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -176,47 +133,27 @@ static void tc_group_group_exit_child(void)
        pid_t child_pid;
 
        st_tcb = sched_self();
-       if (!st_tcb) {
-               printf("tc_group_group_exit_child FAIL");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("sched_self", st_tcb);
 
        group = st_tcb->group;
-       if (!group) {
-               printf("tc_group_group_exit_child FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("sched_self", group);
 
        child_pid = task_create("group", SCHED_PRIORITY_DEFAULT, CONFIG_USERMAIN_STACKSIZE, group_exitchild_func, (char *const *)NULL);
 
        child = group_findchild(group, child_pid);
-       if (child == NULL) {
-               printf("tc_group_group_exit_child FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("group_findchild", child);
+
        sleep(3);
 
        child_returned = group_exitchild(group);
-       if (child != child_returned) {
-               printf("tc_group_group_exit_child FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("group_exitchild", child, child_returned);
 
        child_returned = group_removechild(group, child_pid);
-       if (child != child_returned) {
-               printf(" tc_group_group_exit_child FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("group_removechild", child, child_returned);
 
        group_freechild(child);
 
-       printf("tc_group_group_exit_child PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -235,25 +172,13 @@ static void tc_group_group_removechildren(void)
        pid_t child_pid;
 
        st_tcb = sched_self();
-       if (!st_tcb) {
-               printf("tc_group_group_removechildren FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("sched_self", st_tcb);
 
        group = st_tcb->group;
-       if (!group) {
-               printf("tc_group_group_removechildren FAIL");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("sched_self", group);
 
        child = group_allocchild();
-       if (child == NULL) {
-               printf("tc_group_group_removechildren FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("group_allocchild", child);
 
        child_pid = -1;
        child->ch_flags = TCB_FLAG_TTYPE_TASK;
@@ -264,21 +189,12 @@ static void tc_group_group_removechildren(void)
 
        /* cross check starts */
        child_returned = group_findchild(group, child_pid);
-       if (child != child_returned) {
-               printf("tc_group_group_removechildren FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("group_findchild", child, child_returned);
 
        group_removechildren(group);
-       if (group->tg_children != NULL) {
-               printf("tc_group_group_removechildren FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       printf("tc_group_group_removechildren PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("group_removechildren", group->tg_children, NULL);
+
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index 88b1428..e13b921 100644 (file)
@@ -45,55 +45,29 @@ static void tc_libc_libgen_basename(void)
        char *path = "/etc/passwd";
 
        psz_str = basename(path);
+       TC_ASSERT_EQ("basename", strncmp(psz_str, "passwd", strlen(psz_str)), 0);
 
-       if (strncmp(psz_str, "passwd", strlen(psz_str)) != OK) {
-               printf("tc_libc_libgen_basename path: /etc/passwd FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
        path = "/etc";
        psz_str = basename(path);
+       TC_ASSERT_EQ("basename", strncmp(psz_str, "etc", strlen(psz_str)), 0);
 
-       if (strncmp(psz_str, "etc", strlen(psz_str)) != OK) {
-               printf("tc_libc_libgen_basename path: /etc FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
        path = "etc";
        psz_str = basename(path);
-
-       if (strncmp(psz_str, "etc", strlen(psz_str)) != OK) {
-               printf("tc_libc_libgen_basename path: etc FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("basename", strncmp(psz_str, "etc", strlen(psz_str)), 0);
 
        path = "/";
        psz_str = basename(path);
+       TC_ASSERT_EQ("basename", strncmp(psz_str, "/", strlen(psz_str)), 0);
 
-       if (strncmp(psz_str, "/", strlen(psz_str)) != OK) {
-               printf("tc_libc_libgen_basename path: / FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
        path = ".";
        psz_str = basename(path);
+       TC_ASSERT_EQ("basename", strncmp(psz_str, ".", strlen(psz_str)), 0);
 
-       if (strncmp(psz_str, ".", strlen(psz_str)) != OK) {
-               printf("tc_libc_libgen_basename path: . FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
        path = "..";
        psz_str = basename(path);
+       TC_ASSERT_EQ("basename", strncmp(psz_str, "..", strlen(psz_str)), 0);
 
-       if (strncmp(psz_str, "..", strlen(psz_str)) != OK) {
-               printf("tc_libc_libgen_basename path: .. FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_libgen_basename PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -112,55 +86,29 @@ static void tc_libc_libgen_dirname(void)
        char path[] = "/etc/passwd";
 
        psz_str = dirname(path);
+       TC_ASSERT_EQ("dirname", strncmp(psz_str, "/etc", strlen(psz_str)), 0);
 
-       if (strncmp(psz_str, "/etc", strlen(psz_str)) != OK) {
-               printf("tc_libc_libgen__dirname path: /etc/passwd FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
        strncpy(path, "/etc", strlen(path));
        psz_str = dirname(path);
+       TC_ASSERT_EQ("dirname", strncmp(psz_str, "/", strlen(psz_str)), 0);
 
-       if (strncmp(psz_str, "/", strlen(psz_str)) != OK) {
-               printf("tc_libc_libgen__dirname path: /etc FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
        strncpy(path, "etc", strlen(path));
        psz_str = dirname(path);
-
-       if (strncmp(psz_str, ".", strlen(psz_str)) != OK) {
-               printf("tc_libc_libgen__dirname path: etc FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("dirname", strncmp(psz_str, ".", strlen(psz_str)), 0);
 
        strncpy(path, "/", strlen(path));
        psz_str = dirname(path);
+       TC_ASSERT_EQ("dirname", strncmp(psz_str, "/", strlen(psz_str)), 0);
 
-       if (strncmp(psz_str, "/", strlen(psz_str)) != OK) {
-               printf("tc_libc_libgen__dirname path: / FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
        strncpy(path, ".", strlen(path));
        psz_str = dirname(path);
+       TC_ASSERT_EQ("dirname", strncmp(psz_str, ".", strlen(psz_str)), 0);
 
-       if (strncmp(psz_str, ".", strlen(psz_str)) != OK) {
-               printf("tc_libc_libgen__dirname path: . FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
        strncpy(path, "..", strlen(path));
        psz_str = dirname(path);
+       TC_ASSERT_EQ("dirname", strncmp(psz_str, ".", strlen(psz_str)), 0);
 
-       if (strncmp(psz_str, ".", strlen(psz_str)) != OK) {
-               printf("tc_libc_libgen__dirname path: .. FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_libgen_dirname PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index e728860..ff77b6e 100644 (file)
@@ -54,15 +54,10 @@ static void tc_libc_math_fabs(void)
 
        for (fabs_idx = 0; fabs_idx < 5; fabs_idx++) {
                ret_val[fabs_idx] = fabs(in_val[fabs_idx]);
-               if (sol_val[fabs_idx] != ret_val[fabs_idx]) {
-                       printf("tc_libc_math_fabs FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("fabs", sol_val[fabs_idx], ret_val[fabs_idx]);
        }
 
-       printf("tc_libc_math_fabs PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -83,15 +78,10 @@ static void tc_libc_math_floor(void)
 
        for (floor_idx = 0; floor_idx < 8; floor_idx++) {
                ret_val[floor_idx] = floor(in_val[floor_idx]);
-               if (sol_val[floor_idx] != ret_val[floor_idx]) {
-                       printf("tc_libc_math_floor FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("floor", sol_val[floor_idx], ret_val[floor_idx]);
        }
 
-       printf("tc_libc_math_floor PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -114,22 +104,13 @@ static void tc_libc_math_pow(void)
        for (pow_idx = 0; pow_idx < 13; pow_idx++) {
                ret_val[pow_idx] = pow(in_val[pow_idx][0], in_val[pow_idx][1]);
                if (isinf(sol_val[pow_idx])) {
-                       if (sol_val[pow_idx] != ret_val[pow_idx]) {
-                               printf("tc_libc_math_pow FAIL\n");
-                               total_fail++;
-                               RETURN_ERR;
-                       }
+                       TC_ASSERT_EQ("pow", sol_val[pow_idx], ret_val[pow_idx]);
                } else {
-                       if (fabs(sol_val[pow_idx] - ret_val[pow_idx]) > 0.00000000000001) {
-                               printf("tc_libc_math_pow FAIL\n");
-                               total_fail++;
-                               RETURN_ERR;
-                       }
+                       TC_ASSERT_LT("pow", fabs(sol_val[pow_idx] - ret_val[pow_idx]), 0.00000000000001);
                }
        }
 
-       printf("tc_libc_math_pow PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 #endif
 
index e140530..94018cc 100644 (file)
@@ -26,6 +26,7 @@
 #include <tinyara/config.h>
 #include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 #include <errno.h>
 #include <libgen.h>
 #include <crc8.h>
@@ -33,6 +34,7 @@
 #include <crc32.h>
 #include "tc_internal.h"
 
+#define USEC_100 100
 #define VAL_50 50
 #define VAL_71 71
 #define VAL_100 100
  */
 static void tc_libc_misc_crc8(void)
 {
+       uint8_t ret_chk;
        uint8_t src_arr[1] = { VAL_100 };
        size_t length = 1;
-       uint8_t ret_chk = crc8(src_arr, length);
+
        /* Return value should be 213 as calculated by crc8 */
-       if (ret_chk != VAL_213) {
-               printf("tc_libc_misc_crc8 FAIL, Value: 213 not returned as expected \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+
+       ret_chk = crc8(src_arr, length);
+       TC_ASSERT_EQ("crc8", ret_chk, VAL_213);
+
+       /* Return value should be 71 as calculated by crc8 */
 
        src_arr[0] = VAL_50;
        ret_chk = crc8(src_arr, length);
-       /* eturn value should be 71 as calculated by crc8 */
-       if (ret_chk != VAL_71) {
-               printf("tc_libc_misc_crc8 FAIL, Value: 71 not returned as expected \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_misc_crc8 PASS \n");
-       total_pass++;
+       TC_ASSERT_EQ("crc8", ret_chk, VAL_71);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -90,27 +88,23 @@ static void tc_libc_misc_crc8(void)
  */
 static void tc_libc_misc_crc8part(void)
 {
+       uint8_t ret_chk;
        uint8_t src_arr[1] = { VAL_100 };
        uint8_t crc_8val = 0;
        size_t length = 1;
-       uint8_t ret_chk = crc8part(src_arr, length, crc_8val);
+
        /* Return value should be 213 as calculated by crc8part */
-       if (ret_chk != VAL_213) {
-               printf("tc_libc_misc_crc8part FAIL, Value: 213 not returned as expected \n");
-               total_fail++;
-               RETURN_ERR;
-       }
 
-       crc_8val = VAL_255;
        ret_chk = crc8part(src_arr, length, crc_8val);
+       TC_ASSERT_EQ("crc8part", ret_chk, VAL_213);
+
        /* Return value should be 192 as calculated by crc8part */
-       if (ret_chk != VAL_192) {
-               printf("tc_libc_misc_crc8part FAIL, Value: 192 not returned as expected \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_misc_crc8part PASS \n");
-       total_pass++;
+
+       crc_8val = VAL_255;
+       ret_chk = crc8part(src_arr, length, crc_8val);
+       TC_ASSERT_EQ("crc8part", ret_chk, VAL_192);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -124,26 +118,22 @@ static void tc_libc_misc_crc8part(void)
  */
 static void tc_libc_misc_crc16(void)
 {
+       uint16_t ret_chk;
        uint8_t src_arr[1] = { VAL_100 };
        size_t length = 1;
-       uint16_t ret_chk = crc16(src_arr, length);
+
        /* Return value should be VAL_100 as calculated by crc16 */
-       if (ret_chk != VAL_100) {
-               printf("tc_libc_misc_crc16 FAIL, Value: VAL_100 not returned as expected \n");
-               total_fail++;
-               RETURN_ERR;
-       }
 
-       src_arr[0] = VAL_50;
        ret_chk = crc16(src_arr, length);
+       TC_ASSERT_EQ("crc16", ret_chk, VAL_100);
+
        /* Return value should be 50 as calculated by crc16 */
-       if (ret_chk != VAL_50) {
-               printf("tc_libc_misc_crc16 FAIL, Value: 50 not returned as expected \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_misc_crc16 PASS \n");
-       total_pass++;
+
+       src_arr[0] = VAL_50;
+       ret_chk = crc16(src_arr, length);
+       TC_ASSERT_EQ("crc16", ret_chk, VAL_50);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -157,27 +147,23 @@ static void tc_libc_misc_crc16(void)
  */
 static void tc_libc_misc_crc16part(void)
 {
+       uint16_t ret_chk;
        uint8_t src_arr[1] = { VAL_100 };
        uint16_t crc_16val = 0;
        size_t length = 1;
-       uint16_t ret_chk = crc16part(src_arr, length, crc_16val);
+
        /* Return value should be 100 as calculated by crc16part */
-       if (ret_chk != VAL_100) {
-               printf("tc_libc_misc_crc16part FAIL, Value: 100 not returned as expected \n");
-               total_fail++;
-               RETURN_ERR;
-       }
 
-       crc_16val = VAL_255;
        ret_chk = crc16part(src_arr, length, crc_16val);
+       TC_ASSERT_EQ("crc16part", ret_chk, VAL_100);
+
        /* Return value should be 65380 as calculated by crc16part */
-       if (ret_chk != VAL_65380) {
-               printf("tc_libc_misc_crc16part FAIL, Value: VAL_65380 not returned as expected \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_misc_crc16part PASS \n");
-       total_pass++;
+
+       crc_16val = VAL_255;
+       ret_chk = crc16part(src_arr, length, crc_16val);
+       TC_ASSERT_EQ("crc16part", ret_chk, VAL_65380);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -191,28 +177,22 @@ static void tc_libc_misc_crc16part(void)
  */
 static void tc_libc_misc_crc32(void)
 {
+       uint32_t ret_chk;
        uint8_t src_arr[1] = { VAL_100 };
        size_t length = 1;
-       uint32_t ret_chk = crc32(src_arr, length);
-       uint32_t test_val = VAL_CRC32_1;
 
        /* Return value should be 0x4adfa541 as calculated by crc32 */
-       if (ret_chk != test_val) {
-               printf("tc_libc_misc_crc32 FAIL, Value: VAL_CRC32_1 not returned as expected \n");
-               total_fail++;
-               RETURN_ERR;
-       }
 
-       src_arr[0] = VAL_50;
        ret_chk = crc32(src_arr, length);
+       TC_ASSERT_EQ("crc32", ret_chk, VAL_CRC32_1);
+
        /* Return value should be VAL_CRC32_2 as calculated by crc32 */
-       if (ret_chk != VAL_CRC32_2) {
-               printf("tc_libc_misc_crc32 FAIL, Value: VAL_CRC32_2 not returned as expected \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_misc_crc32 PASS \n");
-       total_pass++;
+
+       src_arr[0] = VAL_50;
+       ret_chk = crc32(src_arr, length);
+       TC_ASSERT_EQ("crc32", ret_chk, VAL_CRC32_2);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -226,28 +206,23 @@ static void tc_libc_misc_crc32(void)
  */
 static void tc_libc_misc_crc32part(void)
 {
+       uint32_t ret_chk;
        uint8_t src_arr[1] = { VAL_100 };
        uint32_t crc_32val = 0;
        size_t length = 1;
-       uint32_t ret_chk = crc32part(src_arr, length, crc_32val);
 
        /* Return value should be 0x4adfa541 as calculated by crc32part */
-       if (ret_chk != (uint32_t)VAL_CRC32_1) {
-               printf("tc_libc_misc_crc32part FAIL, Value: VAL_CRC32_1 not returned as expected \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+
+       ret_chk = crc32part(src_arr, length, crc_32val);
+       TC_ASSERT_EQ("crc32part", ret_chk, (uint32_t)VAL_CRC32_1);
+
+       /* Return value should be 0x67dd4acc as calculated by crc32part */
 
        crc_32val = VAL_255;
        ret_chk = (uint32_t)crc32part(src_arr, length, crc_32val);
-       /* Return value should be 0x67dd4acc as calculated by crc32part */
-       if (ret_chk != VAL_CRC32_3) {
-               printf("tc_libc_misc_crc32part FAIL, Value: VAL_CRC32_3 not returned as expected \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_misc_crc32part PASS \n");
-       total_pass++;
+       TC_ASSERT_EQ("crc32part", ret_chk, (uint32_t)VAL_CRC32_3);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -270,15 +245,14 @@ static void tc_libc_misc_dbg(void)
           # define dbg(format, ...) \
           syslog(LOG_ERR, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__)
         */
-       ret_chk = dbg("Examples");
+
        /* Message displayed is:  "tc_libc_misc_dbg: Examples" */
-       if (ret_chk != strlen(msg_output)) {
-               printf("tc_libc_misc_dbg FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_misc_dbg PASS \n");
-       total_pass++;
+
+       usleep(USEC_100);
+       ret_chk = dbg("Examples");
+       TC_ASSERT_EQ("dbg", ret_chk, strlen(msg_output));
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -302,15 +276,14 @@ static void tc_libc_misc_lldbg(void)
           #  define lldbg(format, ...) \
           lowsyslog(LOG_ERR, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__)
         */
-       ret_chk = lldbg("Examples");
+
        /* Message displayed is:  "tc_libc_misc_lldbg: Examples" */
-       if (ret_chk != strlen(msg_output)) {
-               printf("tc_libc_misc_lldbg FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_misc_lldbg PASS \n");
-       total_pass++;
+
+       usleep(USEC_100);
+       ret_chk = lldbg("Examples");
+       TC_ASSERT_EQ("lldbg", ret_chk, strlen(msg_output));
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -333,15 +306,14 @@ static void tc_libc_misc_llvdbg(void)
           # define llvdbg(format, ...) \
           lowsyslog(LOG_DEBUG, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__)
         */
-       ret_chk = llvdbg("Examples");
+
        /* Message displayed is:  "tc_libc_misc_llvdbg: Examples" */
-       if (ret_chk != strlen(msg_output)) {
-               printf("tc_libc_misc_llvdbg FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_misc_llvdbg PASS \n");
-       total_pass++;
+
+       usleep(USEC_100);
+       ret_chk = llvdbg("Examples");
+       TC_ASSERT_EQ("llvdbg", ret_chk, strlen(msg_output));
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -365,15 +337,14 @@ static void tc_libc_misc_vdbg(void)
           #  define vdbg(format, ...) \
           syslog(LOG_DEBUG, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__)
         */
-       ret_chk = vdbg("Examples");
+
        /* Message displayed is:  "tc_libc_misc_vdbg: Examples" */
-       if (ret_chk != strlen(msg_output)) {
-               printf("tc_libc_misc_vdbg FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_misc_vdbg PASS \n");
-       total_pass++;
+
+       usleep(USEC_100);
+       ret_chk = vdbg("Examples");
+       TC_ASSERT_EQ("vdbg", ret_chk, strlen(msg_output));
+
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index ec3abb8..47e12bc 100644 (file)
@@ -158,65 +158,34 @@ static void *work_usrthread(void *arg)
 static void tc_libc_pthread_pthread_attr_set_get_stacksize(void)
 {
        pthread_attr_t attr;
-       int status;
+       int ret_chk;
        long nstacksize = ST_SIZE;
        long nretstacksize;
 
-       status = pthread_attr_init(&attr);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_set_get_stacksize FAIL : pthread_attr_init failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_attr_init(&attr);
+       TC_ASSERT_EQ("pthread_attr_init", ret_chk, OK);
 
-       status = pthread_attr_setstacksize(&attr, nstacksize);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_set_get_stacksize FAIL : pthread_attr_setstacksize failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_attr_setstacksize(&attr, nstacksize);
+       TC_ASSERT_EQ("pthread_attr_setstacksize", ret_chk, OK);
 
-       status = pthread_create(&g_pthread_usr, &attr, work_usrthread, NULL);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_set_get_stacksize FAIL : pthread_create failed\n");
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_create(&g_pthread_usr, &attr, work_usrthread, NULL);
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
 
-       status = pthread_attr_getstacksize(&attr, &nretstacksize);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_set_get_stacksize FAIL : pthread_attr_getstacksize failed\n");
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_attr_getstacksize(&attr, &nretstacksize);
+       TC_ASSERT_EQ_CLEANUP("pthread_attr_getstacksize", ret_chk, OK, get_errno(), goto errout);
+       TC_ASSERT_EQ_CLEANUP("pthread_attr_getstacksize", nstacksize, nretstacksize, get_errno(), goto errout);
 
-       if (nstacksize != nretstacksize) {
-               printf("tc_libc_pthread_pthread_attr_set_get_stacksize FAIL :pthread_attr_stack was set as %d\n", nstacksize);
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_join(g_pthread_usr, NULL);
+       TC_ASSERT_EQ_CLEANUP("pthread_join", ret_chk, OK, get_errno(), goto errout);
 
-       status = pthread_join(g_pthread_usr, NULL);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_set_get_stacksize FAIL : pthread_join failed\n");
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_attr_destroy(&attr);
+       TC_ASSERT_EQ_CLEANUP("pthread_attr_destroy", ret_chk, OK, get_errno(), goto errout);
 
-       status = pthread_attr_destroy(&attr);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_set_get_stacksize FAIL : pthread_attr_destroy failed\n");
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_SUCCESS_RESULT();
+       return;
 
-       printf("tc_libc_pthread_pthread_attr_set_get_stacksize PASS\n");
-       total_pass++;
+errout:
+       pthread_detach(g_pthread_usr);
 }
 
 /**
@@ -236,64 +205,33 @@ static void tc_libc_pthread_pthread_attr_set_get_schedparam(void)
        pthread_attr_t attr;
        struct sched_param param;
        struct sched_param rparam;
-       int status;
-       status = pthread_attr_init(&attr);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_set_get_schedparam FAIL : pthread_attr_init failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       int ret_chk;
+
+       ret_chk = pthread_attr_init(&attr);
+       TC_ASSERT_EQ("pthread_attr_init", ret_chk, OK);
 
        param.sched_priority = SCHED_PRIOR;
 
-       status = pthread_attr_setschedparam(&attr, &param);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_set_get_schedparam FAIL : pthread_attr_setschedparam failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_attr_setschedparam(&attr, &param);
+       TC_ASSERT_EQ("pthread_attr_setschedparam", ret_chk, OK);
 
-       status = pthread_create(&g_pthread_usr, &attr, work_usrthread, NULL);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_set_get_schedparam FAIL : pthread_create failed\n");
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_create(&g_pthread_usr, &attr, work_usrthread, NULL);
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
 
-       status = pthread_attr_getschedparam(&attr, &rparam);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_set_get_schedparam FAIL : pthread_attr_getschedparam failed\n");
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_attr_getschedparam(&attr, &rparam);
+       TC_ASSERT_EQ_CLEANUP("pthread_attr_getschedparam", ret_chk, OK, get_errno(), goto errout);
+       TC_ASSERT_EQ_CLEANUP("pthread_attr_getschedparam", rparam.sched_priority, param.sched_priority, get_errno(), goto errout);
 
-       if (rparam.sched_priority != param.sched_priority) {
-               printf("tc_libc_pthread_pthread_attr_set_get_schedparam FAIL : pthread_attr_schedparam(priority) was set as %d\n", rparam.sched_priority);
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_join(g_pthread_usr, NULL);
+       TC_ASSERT_EQ_CLEANUP("pthread_join", ret_chk, OK, get_errno(), goto errout);
 
-       status = pthread_join(g_pthread_usr, NULL);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_set_get_schedparam FAIL : pthread_join failed\n");
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_attr_destroy(&attr);
+       TC_ASSERT_EQ("pthread_attr_destroy", ret_chk, OK);
 
-       status = pthread_attr_destroy(&attr);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_set_get_schedparam FAIL : pthread_attr_destroy failed\n");
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_SUCCESS_RESULT();
+       return;
 
-       printf("tc_libc_pthread_pthread_attr_set_get_schedparam PASS\n");
-       total_pass++;
+errout:
        pthread_detach(g_pthread_usr);
 }
 
@@ -317,63 +255,32 @@ static void tc_libc_pthread_pthread_attr_init_destroy_set_get_inheritsched(void)
        pthread_attr_t attr;
        int inherit_sched_setval = PTHREAD_EXPLICIT_SCHED;
        int inherit_sched_getval;
-       int status;
-       status = pthread_attr_init(&attr);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_init_destroy_set_get_inheritsched FAIL : pthread_attr_init failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       int ret_chk;
 
-       status = pthread_attr_setinheritsched(&attr, inherit_sched_setval);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_init_destroy_set_get_inheritsched FAIL : pthread_attr_setinheritsched failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_attr_init(&attr);
+       TC_ASSERT_EQ("pthread_attr_init", ret_chk, OK);
 
-       status = pthread_create(&g_pthread_usr, &attr, work_usrthread, NULL);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_init_destroy_set_get_inheritsched FAIL : pthread_create failed\n");
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_attr_setinheritsched(&attr, inherit_sched_setval);
+       TC_ASSERT_EQ("pthread_attr_setinheritsched", ret_chk, OK);
 
-       status = pthread_attr_getinheritsched(&attr, &inherit_sched_getval);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_init_destroy_set_get_inheritsched FAIL : pthread_attr_getinheritsched failed\n");
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_create(&g_pthread_usr, &attr, work_usrthread, NULL);
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
 
-       if (inherit_sched_setval != inherit_sched_getval) {
-               printf("tc_libc_pthread_pthread_attr_init_destroy_set_get_inheritsched FAIL : Inherit scheduler was set as %d\n", inherit_sched_setval);
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_attr_getinheritsched(&attr, &inherit_sched_getval);
+       TC_ASSERT_EQ_CLEANUP("pthread_attr_getinheritsched", ret_chk, OK, get_errno(), goto errout);
+       TC_ASSERT_EQ_CLEANUP("pthread_attr_getinheritsched", inherit_sched_setval, inherit_sched_getval, get_errno(), goto errout);
 
-       status = pthread_join(g_pthread_usr, NULL);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_init_destroy_set_get_inheritsched FAIL : pthread_attr_join failed\n");
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_join(g_pthread_usr, NULL);
+       TC_ASSERT_EQ_CLEANUP("pthread_join", ret_chk, OK, get_errno(), goto errout);
 
-       status = pthread_attr_destroy(&attr);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_init_destroy_set_get_inheritsched FAIL : pthread_attr_destroy failed\n");
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_attr_destroy(&attr);
+       TC_ASSERT_EQ("pthread_attr_destroy", ret_chk, OK);
 
-       printf("tc_libc_pthread_pthread_attr_init_destroy_set_get_inheritsched PASS\n");
-       total_pass++;
-       pthread_cancel(g_pthread_usr);
+       TC_SUCCESS_RESULT();
+       return;
+
+errout:
+       pthread_detach(g_pthread_usr);
 }
 
 /**
@@ -395,61 +302,30 @@ static void tc_libc_pthread_pthread_attr_schedpolicy(void)
        pthread_attr_t attr;
        int sched_policy_setval = SCHED_RR;
        int sched_policy_getval;
-       int status;
-       status = pthread_attr_init(&attr);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_schedpolicy FAIL : pthread_attr_init failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       int ret_chk;
 
-       status = pthread_attr_setschedpolicy(&attr, sched_policy_setval);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_schedpolicy FAIL : pthread_attr_setschedpolicy failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_attr_init(&attr);
+       TC_ASSERT_EQ("pthread_attr_init", ret_chk, OK);
 
-       status = pthread_create(&g_pthread_usr, &attr, work_usrthread, NULL);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_schedpolicy FAIL : pthread_create failed\n");
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_attr_setschedpolicy(&attr, sched_policy_setval);
+       TC_ASSERT_EQ("pthread_attr_setschedpolicy", ret_chk, OK);
 
-       status = pthread_attr_getschedpolicy(&attr, &sched_policy_getval);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_schedpolicy FAIL : pthread_attr_getschedpolicy failed\n");
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_create(&g_pthread_usr, &attr, work_usrthread, NULL);
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
 
-       if (sched_policy_setval != sched_policy_getval) {
-               printf("tc_libc_pthread_pthread_attr_schedpolicy FAIL :Scheduler Policy  was set as %d\n", sched_policy_setval);
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
-       status = pthread_join(g_pthread_usr, NULL);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_schedpolicy FAIL : pthread_join failed\n");
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_attr_getschedpolicy(&attr, &sched_policy_getval);
+       TC_ASSERT_EQ_CLEANUP("pthread_attr_getschedpolicy", ret_chk, OK, get_errno(), goto errout);
+       TC_ASSERT_EQ_CLEANUP("pthread_attr_getschedpolicy", sched_policy_setval, sched_policy_getval, get_errno(), goto errout);
 
-       status = pthread_attr_destroy(&attr);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_attr_schedpolicy FAIL : pthread_attr_destroy failed\n");
-               pthread_detach(g_pthread_usr);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_join(g_pthread_usr, NULL);
+       TC_ASSERT_EQ_CLEANUP("pthread_attr_getschedpolicy", ret_chk, OK, get_errno(), goto errout);
+
+       ret_chk = pthread_attr_destroy(&attr);
+       TC_ASSERT_EQ("pthread_attr_destroy", ret_chk, OK);
 
-       printf("tc_libc_pthread_pthread_attr_schedpolicy PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
+
+errout:
        pthread_detach(g_pthread_usr);
 }
 
@@ -469,80 +345,44 @@ static void tc_libc_pthread_pthread_attr_schedpolicy(void)
 static void tc_libc_pthread_pthread_barrierattr_init_destroy_set_get_pshared(void)
 {
        pthread_barrierattr_t attr;
-       int status = 0;
+       int ret_chk = 0;
        int thread_count = THREAD_CNT;
        int pshared = PTHREAD_PROCESS_PRIVATE;
        int pshared_ret;
 
-       status = pthread_barrierattr_init(&attr);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_barrierattr_init_destroy_set_get_pshared FAIL : pthread_barrierattr_init failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_barrierattr_init(&attr);
+       TC_ASSERT_EQ("pthread_barrierattr_init", ret_chk, OK);
 
-       status = pthread_barrierattr_setpshared(&attr, pshared);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_barrierattr_init_destroy_set_get_pshared FAIL : pthread_barrierattr_setpshared failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_barrierattr_setpshared(&attr, pshared);
+       TC_ASSERT_EQ("pthread_barrierattr_setpshared", ret_chk, OK);
 
-       status = pthread_barrier_init(&g_pthreadbarrier, &attr, thread_count);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_barrierattr_init_destroy_set_get_pshared FAIL : pthread_barrier_init failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_barrier_init(&g_pthreadbarrier, &attr, thread_count);
+       TC_ASSERT_EQ("pthread_barrier_init", ret_chk, OK);
 
-       status = pthread_create(&g_pthread_barrier1, NULL, barrier_thread_1, NULL);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_barrierattr_init_destroy_set_get_pshared FAIL : pthread_create failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_create(&g_pthread_barrier1, NULL, barrier_thread_1, NULL);
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
 
-       status = pthread_barrierattr_getpshared(&attr, &pshared_ret);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_barrierattr_init_destroy_set_get_pshared FAIL : pthread_barrierattr_getpshared failed\n");
-               pthread_detach(g_pthread_barrier1);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_barrierattr_getpshared(&attr, &pshared_ret);
+       TC_ASSERT_EQ_CLEANUP("pthread_barrierattr_getpshared", ret_chk, OK, get_errno(), goto errout);
+       TC_ASSERT_EQ_CLEANUP("pthread_barrierattr_getpshared", pshared_ret, pshared, get_errno(), goto errout);
 
-       if (pshared_ret != pshared) {
-               printf("tc_libc_pthread_pthread_barrierattr_init_destroy_set_get_pshared FAIL\n");
-               pthread_detach(g_pthread_barrier1);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_create(&g_pthread_barrier2, NULL, barrier_thread_2, NULL);
+       TC_ASSERT_EQ_CLEANUP("pthread_create", ret_chk, OK, get_errno(), goto errout);
 
-       status = pthread_create(&g_pthread_barrier2, NULL, barrier_thread_2, NULL);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_barrierattr_init_destroy_set_get_pshared FAIL : pthread_create failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_barrierattr_destroy(&attr);
+       TC_ASSERT_EQ_CLEANUP("pthread_barrierattr_destroy", ret_chk, OK, get_errno(), goto errout);
 
-       status = pthread_barrierattr_destroy(&attr);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_barrierattr_init_destroy_set_get_pshared FAIL : pthread_barrierattr_destroy failed\n");
-               pthread_detach(g_pthread_barrier2);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_barrier_destroy(&g_pthreadbarrier);
+       TC_ASSERT_EQ_CLEANUP("pthread_barrier_destroy", ret_chk, OK, get_errno(), goto errout);
 
-       status = pthread_barrier_destroy(&g_pthreadbarrier);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_barrierattr_init_destroy_set_get_pshared FAIL : pthread_barrier_destroy failed\n");
-               pthread_detach(g_pthread_barrier2);
-               total_fail++;
-               RETURN_ERR;
-       }
        pthread_join(g_pthread_barrier1, 0);
        pthread_join(g_pthread_barrier2, 0);
-       printf("tc_libc_pthread_pthread_barrierattr_init_destroy_set_get_pshared PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
+       return;
+
+errout:
+       pthread_detach(g_pthread_barrier1);
+       pthread_detach(g_pthread_barrier2);
 }
 
 /**
@@ -561,40 +401,26 @@ static void tc_libc_pthread_pthread_barrierattr_init_destroy_set_get_pshared(voi
 */
 static void tc_libc_pthread_pthread_condattr(void)
 {
-       int status = 0;
+       int ret_chk = 0;
        g_counter = 0;
        g_icondition_met = 0;
        int pthread_num;
        pthread_condattr_t attr;
 
        /* Create a default condition attribute */
-       status = pthread_condattr_init(&attr);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_condattr FAIL : pthread_condattr_init failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_condattr_init(&attr);
+       TC_ASSERT_EQ("pthread_condattr_init", ret_chk, OK);
 
        /* Create the condition using the condition attributes object */
-       status = pthread_cond_init(&g_pthread_cond, &attr);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_condattr FAIL : pthread_cond_init failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_cond_init(&g_pthread_cond, &attr);
+       TC_ASSERT_EQ("pthread_cond_init", ret_chk, OK);
+
        for (pthread_num = 0; pthread_num < PTHREAD_NUM; pthread_num++) {
-               pthread_create(&g_rgpthread[pthread_num], NULL, pthread_condattr_thread_func, NULL);
+               ret_chk = pthread_create(&g_rgpthread[pthread_num], NULL, pthread_condattr_thread_func, NULL);
+               TC_ASSERT_EQ_CLEANUP("pthread_create", ret_chk, OK, get_errno(), goto errout);
        }
        sleep(SEC_5);
-       if (g_counter != PTHREAD_NUM) {
-               printf("FAIL:g_counter!=threadcount\n");
-               total_fail++;
-               for (pthread_num = 0; pthread_num < PTHREAD_NUM; pthread_num++) {
-                       pthread_detach(g_rgpthread[pthread_num]);
-               }
-               printf("tc_libc_pthread_pthread_condattr FAIL : pthread_create failed\n");
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ_CLEANUP("pthread_create", g_counter, PTHREAD_NUM, get_errno(), goto errout);
 
        pthread_mutex_lock(&g_pthread_mutex);
        g_icondition_met = 1;
@@ -602,38 +428,28 @@ static void tc_libc_pthread_pthread_condattr(void)
        pthread_mutex_unlock(&g_pthread_mutex);
 
        for (pthread_num = 0; pthread_num < PTHREAD_NUM; pthread_num++) {
-               status = pthread_join(g_rgpthread[pthread_num], NULL);
-               if (status != OK) {
-                       printf("tc_libc_pthread_pthread_condattr FAIL : pthread_join failed\n");
-                       pthread_detach(g_rgpthread[pthread_num]);
-                       total_fail++;
-                       RETURN_ERR;
-               }
-       }
-       if (g_counter != 0) {
-               printf("FAIL:g_counter!=0\n");
-               total_fail++;
-               RETURN_ERR;
+               ret_chk = pthread_join(g_rgpthread[pthread_num], NULL);
+               TC_ASSERT_EQ_CLEANUP("pthread_join", ret_chk, OK, get_errno(), goto errout);
        }
+       TC_ASSERT_EQ_CLEANUP("pthread_join", g_counter, 0, get_errno(), goto errout);
 
        /* Destroy cond attribute */
-       status = pthread_condattr_destroy(&attr);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_condattr FAIL : pthread_condattr_destroy failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_condattr_destroy(&attr);
+       TC_ASSERT_EQ_CLEANUP("pthread_condattr_destroy", ret_chk, OK, get_errno(), goto errout);
 
        /* Destroy condition */
-       status = pthread_cond_destroy(&g_pthread_cond);
-       if (status != OK) {
-               printf("tc_libc_pthread_pthread_condattr FAIL : pthread_cond_destroy failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_cond_destroy(&g_pthread_cond);
+       TC_ASSERT_EQ("pthread_cond_destroy", ret_chk, OK);
 
-       printf("tc_libc_pthread_pthread_condattr PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
+       return;
+
+errout:
+       for (pthread_num = 0; pthread_num < PTHREAD_NUM; pthread_num++) {
+               pthread_detach(g_rgpthread[pthread_num]);
+       }
+       pthread_cond_destroy(&g_pthread_cond);
+       pthread_condattr_destroy(&attr);
 }
 
 /**
@@ -651,7 +467,7 @@ static void tc_libc_pthread_pthread_condattr(void)
 */
 static void tc_libc_pthread_pthread_mutexattr(void)
 {
-       int iret = 0;
+       int ret_chk = 0;
        int ithreadid = 0;
        int mutex_settype;
        int mutex_gettype = -1;
@@ -663,86 +479,54 @@ static void tc_libc_pthread_pthread_mutexattr(void)
        mutex_settype = PTHREAD_PROCESS_SHARED;
        pthread_t threads[ithreadcount];
        pthread_mutexattr_t mutexAttr;
-       iret = pthread_mutexattr_init(&mutexAttr);
 
-       if (iret != OK) {
-               printf("tc_libc_pthread_pthread_mutexattr FAIL : pthread_mutexattr_init failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_mutexattr_init(&mutexAttr);
+       TC_ASSERT_EQ("pthread_mutexattr_init", ret_chk, OK);
 
-       iret = pthread_mutexattr_setpshared(&mutexAttr, mutex_pshared_set);
-       if (iret != OK) {
-               printf("tc_libc_pthread_pthread_mutexattr FAIL : pthread_mutexattr_setpshared failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_mutexattr_setpshared(&mutexAttr, mutex_pshared_set);
+       TC_ASSERT_EQ("pthread_mutexattr_setpshared", ret_chk, OK);
 
-       iret = pthread_mutexattr_settype(&mutexAttr, mutex_settype);
-       if (iret != OK) {
-               printf("tc_libc_pthread_pthread_mutexattr FAIL : pthread_mutexattr_settype failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_mutexattr_settype(&mutexAttr, mutex_settype);
+       TC_ASSERT_EQ("pthread_mutexattr_settype", ret_chk, OK);
 
-       iret = pthread_mutex_init(&g_mutex, &mutexAttr);
-       if (iret != OK) {
-               printf("tc_libc_pthread_pthread_mutexattr FAIL : pthread_mutex_init failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_mutex_init(&g_mutex, &mutexAttr);
+       TC_ASSERT_EQ("pthread_mutex_init", ret_chk, OK);
 
        for (ithreadid = 0; ithreadid < ithreadcount; ++ithreadid) {
-               iret = pthread_create(&threads[ithreadid], NULL, mutex_testing, (void *)ithreadid);
-               if (iret != 0) {
-                       printf("[%s]pthread_create fail \n", __func__);
-               }
+               ret_chk = pthread_create(&threads[ithreadid], NULL, mutex_testing, (void *)ithreadid);
+               TC_ASSERT_EQ_CLEANUP("pthread_create", ret_chk, OK, get_errno(), goto errout);
        }
 
        /* apply join on thread */
        for (ithreadid = 0; ithreadid < ithreadcount; ++ithreadid) {
-               iret = pthread_join(threads[ithreadid], &ithread);
-               if (iret != OK) {
-                       printf("[%s]pthread_join failed \n", __func__);
-               }
+               ret_chk = pthread_join(threads[ithreadid], &ithread);
+               TC_ASSERT_EQ_CLEANUP("pthread_join", ret_chk, OK, get_errno(), goto errout);
        }
 
-       iret = pthread_mutexattr_gettype(&mutexAttr, &mutex_gettype);
-       if (iret != OK || mutex_gettype != mutex_settype) {
-               printf("tc_libc_pthread_pthread_mutexattr FAIL : pthread_mutexattr_gettype failed\n");
-               pthread_mutexattr_destroy(&mutexAttr);
-               pthread_mutex_destroy(&g_mutex);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_mutexattr_gettype(&mutexAttr, &mutex_gettype);
+       TC_ASSERT_EQ_CLEANUP("pthread_mutexattr_gettype", ret_chk, OK, get_errno(), goto errout);
+       TC_ASSERT_EQ_CLEANUP("pthread_mutexattr_gettype", mutex_gettype, mutex_settype, get_errno(), goto errout);
 
-       iret = pthread_mutexattr_getpshared(&mutexAttr, &mutex_pshared_get);
+       ret_chk = pthread_mutexattr_getpshared(&mutexAttr, &mutex_pshared_get);
+       TC_ASSERT_EQ_CLEANUP("pthread_mutexattr_getpshared", ret_chk, OK, get_errno(), goto errout);
+       TC_ASSERT_EQ_CLEANUP("pthread_mutexattr_getpshared", mutex_pshared_get, mutex_pshared_set, get_errno(), goto errout);
 
-       if (iret != OK || mutex_pshared_get != mutex_pshared_set) {
-               printf("[%s]pthread_mutexattr_getpshared failed \n", __func__);
-               pthread_mutexattr_destroy(&mutexAttr);
-               pthread_mutex_destroy(&g_mutex);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_mutexattr_destroy(&mutexAttr);
+       TC_ASSERT_EQ_CLEANUP("pthread_mutexattr_destroy", ret_chk, OK, get_errno(), goto errout);
 
-       iret = pthread_mutexattr_destroy(&mutexAttr);
-       if (iret != OK) {
-               printf("[%s]pthread_mutexattr_destroy failed \n", __func__);
-               pthread_mutex_destroy(&g_mutex);
-               total_fail++;
-               RETURN_ERR;
-       }
        /* Destroying mutex object */
-       iret = pthread_mutex_destroy(&g_mutex);
-       if (iret != OK) {
-               printf("tc_libc_pthread_pthread_mutexattr FAIL : pthread_mutexattr_destroy failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_mutex_destroy(&g_mutex);
+       TC_ASSERT_EQ("pthread_mutex_destroy", ret_chk, OK);
+
+       TC_SUCCESS_RESULT();
+       return;
 
-       printf("tc_libc_pthread_pthread_mutexattr PASS\n");
-       total_pass++;
+errout:
+       for (ithreadid = 0; ithreadid < ithreadcount; ++ithreadid) {
+               pthread_detach(threads[ithreadid]);             
+       }
+       pthread_mutex_destroy(&g_mutex);
+       pthread_mutexattr_destroy(&mutexAttr);
 }
 
 /****************************************************************************
index 8a97ae7..7d71bfa 100644 (file)
@@ -138,16 +138,13 @@ static void tc_libc_queue_dq_addlast(void)
 
        struct dq_struct *conng = (struct dq_struct *)g_active_dqlist.head;
        while (conng) {
-               if (conng->key != istart_node_val || conng->data_value != (istart_node_val + 1)) {
-                       printf("tc_libc_queue_dq_addlast FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("dq_addlast", conng->key, istart_node_val);
+               TC_ASSERT_EQ("dq_addlast", conng->data_value, istart_node_val + 1);
                istart_node_val = istart_node_val + 1;
                conng = (FAR struct dq_struct *)conng->node.flink;
        }
-       printf("tc_libc_queue_dq_addlast PASS\n");
-       total_pass++;
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -172,16 +169,13 @@ static void tc_libc_queue_dq_addfirst(void)
 
        struct dq_struct *conng = (struct dq_struct *)g_active_dqlist.head;
        while (conng) {
-               if (conng->key != istart_node_val || conng->data_value != (istart_node_val + 1)) {
-                       printf("tc_libc_queue_dq_addfirst FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("dq_addfirst", conng->key, istart_node_val);
+               TC_ASSERT_EQ("dq_addfirst", conng->data_value, istart_node_val + 1);
                istart_node_val = istart_node_val - 1;
                conng = (FAR struct dq_struct *)conng->node.flink;
        }
-       printf("tc_libc_queue_dq_addfirst PASS\n");
-       total_pass++;
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -206,40 +200,27 @@ static void tc_libc_queue_dq_addafter(void)
        /* verifying queue item inserted as expected or not. */
        while (conng) {
                i_index++;
-               if (conng->key != istart_node_val) {
-                       printf("tc_libc_queue_dq_addafter FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("dq_addfirst", conng->key, istart_node_val);
                istart_node_val = istart_node_val - 1;
                conng = (FAR struct dq_struct *)conng->node.flink;
        }
        /* Adding key value KEY_VAL after key value 3 */
        g_dqstruct_array[i_index].key = KEY_VAL;
        g_dqstruct_array[i_index].data_value = KEY_VAL + 1;
-       if (i_index < 1) {
-               printf("tc_libc_qeue_dq_addafter : failed to add on queue\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_GEQ("dq_addfirst", i_index, 1);
        dq_addafter(&g_dqstruct_array[i_index - 1].node, &g_dqstruct_array[i_index].node, &g_active_dqlist);
        conng = (struct dq_struct *)g_active_dqlist.head;
        /* verifying that newly queue item, inserted after key value 3 or not. */
        while (conng) {
                if (prev_key == (i_index - 1)) {
-                       if (conng->key == added_key) {
-                               printf("tc_libc_queue_dq_addafter PASS\n");
-                               break;
-                       } else {
-                               printf("tc_libc_queue_dq_addafter FAIL\n");
-                               total_fail++;
-                               RETURN_ERR;
-                       }
+                       TC_ASSERT_EQ("dq_addafter", conng->key, added_key);
+                       break;
                }
                prev_key = conng->key;
                conng = (FAR struct dq_struct *)conng->node.flink;
        }
-       total_pass++;
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -272,22 +253,15 @@ static void tc_libc_queue_dq_addbefore(void)
        conng = (struct dq_struct *)g_active_dqlist.head;
        while (conng) {
                if (prev_key == 2) {
-                       if (conng->key == add_before_key) {
-                               conng = (FAR struct dq_struct *)conng->node.flink;
-                               if (conng->key == 3) {
-                                       printf("tc_libc_queue_dq_addbefore PASS\n");
-                                       break;
-                               }
-                       } else {
-                               printf("tc_libc_queue_dq_addbefore FAIL\n");
-                               total_fail++;
-                               RETURN_ERR;
-                       }
+                       TC_ASSERT_EQ("dq_addbefore", conng->key, add_before_key);
+                       conng = (FAR struct dq_struct *)conng->node.flink;
+                       TC_ASSERT_EQ("dq_addbefore", conng->key, 3);
                }
                prev_key = conng->key;
                conng = (FAR struct dq_struct *)conng->node.flink;
        }
-       total_pass++;
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -315,16 +289,12 @@ static void tc_libc_queue_dq_remfirst(void)
 
        while (conng) {
                /* Since first item is removed then dqueue item order would be 2,1,0 */
-               if (conng->key != arrlist[cur_idx]) {
-                       printf("tc_libc_queue_dq_remfirst FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("dq_remfirst", conng->key, arrlist[cur_idx]);
                cur_idx = cur_idx + 1;
                conng = (FAR struct dq_struct *)conng->node.flink;
        }
-       printf("tc_libc_queue_dq_remfirst PASS\n");
-       total_pass++;
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -346,23 +316,15 @@ static void tc_libc_queue_dq_remlast(void)
        initialize_dq_addfirst();
 
        struct dq_struct *conng = (struct dq_struct *)g_active_dqlist.tail;
+       TC_ASSERT_EQ("dq_addfirst", conng->key, ilast_node_val);
 
-       if (conng->key != ilast_node_val) {
-               printf("tc_libc_queue_dq_remlast FAIL, values not added successfully\n");
-               total_fail++;
-               RETURN_ERR;
-       }
        dq_remlast(&g_active_dqlist);
 
        conng = (struct dq_struct *)g_active_dqlist.tail;
+       TC_ASSERT_NEQ("dq_remlast", conng->key, ilast_node_val);
+       TC_ASSERT_EQ("dq_remlast", conng->key, icurrentlast_node_val);
 
-       if (conng->key == ilast_node_val || conng->key != icurrentlast_node_val) {
-               printf("tc_libc_queue_dq_remlast FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_queue_dq_remlast PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -390,17 +352,13 @@ static void tc_libc_queue_dq_rem(void)
 
        while (conng) {
                /* Since item 1 is removed then dqueue item order would be 3,2,0 */
-               if (conng->key != item_arr[cur_idx]) {
-                       printf("tc_libc_queue_dq_rem FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("dq_rem", conng->key, item_arr[cur_idx]);
 
                cur_idx = cur_idx + 1;
                conng = (FAR struct dq_struct *)conng->node.flink;
        }
-       printf("tc_libc_queue_dq_rem PASS\n");
-       total_pass++;
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -419,17 +377,14 @@ static void tc_libc_queue_sq_addlast(void)
        initialize_sq_addlast();
        struct sq_struct *conng = (struct sq_struct *)g_active_sqlist.head;
        while (conng) {
-               if (conng->key != istart_node_val || conng->data_value != (istart_node_val + 1)) {
-                       printf("tc_libc_queue_sq_addlast FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("sq_addlast", conng->key, istart_node_val);
+               TC_ASSERT_EQ("sq_addlast", conng->data_value, istart_node_val + 1);
 
                istart_node_val = istart_node_val + 1;
                conng = (FAR struct sq_struct *)conng->node.flink;
        }
-       printf("tc_libc_queue_sq_addlast PASS\n");
-       total_pass++;
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -448,16 +403,14 @@ static void tc_libc_queue_sq_addfirst(void)
        initialize_sq_addfirst();
        struct sq_struct *conng = (struct sq_struct *)g_active_sqlist.head;
        while (conng) {
-               if (conng->key != istart_node_val || conng->data_value != (istart_node_val + 1)) {
-                       printf("tc_libc_queue_sq_addfirst FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("sq_addfirst", conng->key, istart_node_val);
+               TC_ASSERT_EQ("sq_addfirst", conng->data_value, istart_node_val + 1);
+
                istart_node_val = istart_node_val - 1;
                conng = (FAR struct sq_struct *)conng->node.flink;
        }
-       printf("tc_libc_queue_sq_addfirst PASS\n");
-       total_pass++;
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -482,14 +435,9 @@ static void tc_libc_queue_sq_addafter(void)
        struct sq_struct *conng = (struct sq_struct *)g_active_sqlist.head;
        while (conng) {
                i_index++;
-               if (conng->key == istart_node_val) {
-                       istart_node_val = istart_node_val - 1;
-               } else {
-                       printf("tc_libc_queue_sq_addafter FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("sq_addfirst", conng->key, istart_node_val);
 
+               istart_node_val = istart_node_val - 1;
                conng = (FAR struct sq_struct *)conng->node.flink;
        }
        /* Adding key value 44 after key value 3 */
@@ -499,19 +447,14 @@ static void tc_libc_queue_sq_addafter(void)
        conng = (struct sq_struct *)g_active_sqlist.head;
        while (conng) {
                if (prev_key == 3) {
-                       if (conng->key == addafterKey) {
-                               printf("tc_libc_queue_sq_addafter PASS\n");
-                               break;
-                       } else {
-                               printf("tc_libc_queue_sq_addafter FAIL\n");
-                               total_fail++;
-                               RETURN_ERR;
-                       }
+                       TC_ASSERT_EQ("sq_addafter", conng->key, addafterKey);
+                       break;
                }
                prev_key = conng->key;
                conng = (FAR struct sq_struct *)conng->node.flink;
        }
-       total_pass++;
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -537,16 +480,12 @@ static void tc_libc_queue_sq_remafter(void)
        sq_remafter(&g_sqstruct_array[2].node, &g_active_sqlist);
        conng = (struct sq_struct *)g_active_sqlist.head;
        while (conng) {
-               if (conng->key != arrlist[cur_idx]) {
-                       printf("tc_libc_queue_sq_remafter FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("sq_remafter", conng->key, arrlist[cur_idx]);
                cur_idx = cur_idx + 1;
                conng = (FAR struct sq_struct *)conng->node.flink;
        }
-       printf("tc_libc_queue_sq_remafter PASS\n");
-       total_pass++;
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -567,22 +506,16 @@ static void tc_libc_queue_sq_remfirst(void)
        initialize_sq_addfirst();       /* initialises queue with value {3,2,1,0} */
        struct sq_struct *conng = (struct sq_struct *)g_active_sqlist.head;
 
-       if (conng->key != ifirst_node_val) {
-               printf("tc_libc_queue_sq_remfirst FAIL, Values not added correctly in queue\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sq_addfirst", conng->key, ifirst_node_val);
+
        /* Removing first item from the queue i.e removed item is 3 */
        sq_remfirst(&g_active_sqlist);
        conng = (struct sq_struct *)g_active_sqlist.head;
 
-       if (conng->key == ifirst_node_val || conng->key != icurrentfirst_node_val) {
-               printf("tc_libc_queue_sq_remfirst FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_queue_sq_remfirst PASS\n");
-       total_pass++;
+       TC_ASSERT_NEQ("sq_remfirst", conng->key, ifirst_node_val);
+       TC_ASSERT_EQ("sq_remfirst", conng->key, icurrentfirst_node_val);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -608,13 +541,10 @@ static void tc_libc_queue_sq_remlast(void)
        conng = (struct sq_struct *)g_active_sqlist.tail;
        /* Verifying last queue item value */
 
-       if (conng->key == ikeyVal || conng->key != ilast_node_value) {
-               printf("tc_libc_queue_sq_remlast FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_queue_sq_remlast PASS\n");
-       total_pass++;
+       TC_ASSERT_NEQ("sq_remlast", conng->key, ikeyVal);
+       TC_ASSERT_EQ("sq_remlast", conng->key, ilast_node_value);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -640,16 +570,12 @@ static void tc_libc_queue_sq_rem(void)
        conng = (struct sq_struct *)g_active_sqlist.head;
        while (conng) {
                /* Since first item is removed then dqueue item order would be 3,2,0 */
-               if (conng->key != item_arr[cur_idx]) {
-                       printf("tc_libc_queue_sq_rem FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("sq_rem", conng->key, item_arr[cur_idx]);
                cur_idx = cur_idx + 1;
                conng = (FAR struct sq_struct *)conng->node.flink;
        }
-       printf("tc_libc_queue_sq_rem PASS\n");
-       total_pass++;
+
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index 88c3475..133df3e 100644 (file)
@@ -49,20 +49,12 @@ static void tc_libc_sched_sched_get_priority_max(void)
        int ret_chk;
 
        ret_chk = sched_get_priority_max(SCHED_FIFO);
-       if (ret_chk != MAX_FIFO) {
-               printf("tc_libc_sched_sched_get_priority_max FAIL Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       } else {
-               ret_chk = sched_get_priority_max(SCHED_RR);
-               if (ret_chk != MAX_RR) {
-                       printf("tc_libc_sched_sched_get_priority_max FAIL Error No: %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
-       }
-       printf("tc_libc_sched_sched_get_priority_max PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("sched_get_priority_max", ret_chk, MAX_FIFO);
+
+       ret_chk = sched_get_priority_max(SCHED_RR);
+       TC_ASSERT_EQ("sched_get_priority_max", ret_chk, MAX_RR);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -79,21 +71,12 @@ static void tc_libc_sched_sched_get_priority_min(void)
        int ret_chk;
 
        ret_chk = sched_get_priority_min(SCHED_FIFO);
-       if (ret_chk != MIN_FIFO) {
-               printf("tc_libc_sched_sched_get_priority_min FAIL Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       } else {
-               ret_chk = sched_get_priority_min(SCHED_RR);
-               if (ret_chk != MIN_RR) {
-                       printf("tc_libc_sched_sched_get_priority_min FAIL Error No: %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
-       }
+       TC_ASSERT_EQ("sched_get_priority_min", ret_chk, MIN_FIFO);
+
+       ret_chk = sched_get_priority_min(SCHED_RR);
+       TC_ASSERT_EQ("sched_get_priority_min", ret_chk, MIN_RR);
 
-       printf("tc_libc_sched_sched_get_priority_min PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index 5134961..073ab18 100644 (file)
@@ -56,23 +56,18 @@ static void tc_libc_semaphore_sem_init_getvalue(void)
        for (sem_num = 1; sem_num <= SEM_VALUE_MAX; sem_num++) {
                sem_value = sem_num;
                ret_chk = sem_init(&g_semaphore, PSHARED, sem_value);
-               if (ret_chk != OK) {
-                       printf("tc_libc_semaphore_sem_init FAIL %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("sem_init", ret_chk, OK);
+
                ret_chk = sem_getvalue(&g_semaphore, &getvalue_num);
-               if (ret_chk != OK || getvalue_num != sem_value) {
-                       printf("tc_libc_semaphore_sem_init_getvalue getvalue FAIL\n");
-                       sem_destroy(&g_semaphore);
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("sem_getvalue", ret_chk, OK);
+               TC_ASSERT_EQ_CLEANUP("sem_getvalue",
+                                                        getvalue_num, sem_value,
+                                                        get_errno(),
+                                                        sem_destroy(&g_semaphore));
                sem_destroy(&g_semaphore);
        }
-       printf("tc_libc_semaphore_sem_init_getvalue PASS\n");
 
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index 516a4db..baaa0a7 100644 (file)
@@ -52,42 +52,24 @@ static void tc_libc_signal_sigaddset_sigdelset(void)
        sigset_t sigset;
 
        ret_chk = sigemptyset(&sigset);
-       if (ret_chk != OK) {
-               printf("tc_libc_signal_sigaddset_sigdelset sigemptyset FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sigemptyset", ret_chk, OK);
 
        ret_chk = sigaddset(&sigset, SIGQUIT);
-       if (ret_chk != OK) {
-               printf("tc_libc_signal_sigaddset_sigdelset sigaddset FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sigaddset", ret_chk, OK);
 
        ret_chk = sigismember(&sigset, SIGQUIT);
-       if (ret_chk != 1) {
-               printf("tc_libc_signal_sigaddset_sigdelset :sigaddset FAIL to add signal, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sigismember", ret_chk, 1);
 
        ret_chk = sigdelset(&sigset, SIGQUIT);
-       if (ret_chk != OK) {
-               printf("tc_libc_signal_sigaddset_sigdelset :sigdelset FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sigdelset", ret_chk, OK);
+
        /* should not find that signal as it has already deleted */
+
        ret_chk = sigismember(&sigset, SIGQUIT);
-       if (ret_chk == ERROR) {
-               printf("tc_libc_signal_sigaddset_sigdelset sigdelset FAIL to delete signal, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       printf("tc_libc_signal_sigaddset_sigdelset PASS\n");
-       total_pass++;
+       TC_ASSERT_NEQ("sigismember", ret_chk, 1);
+       TC_ASSERT_NEQ("sigismember", ret_chk, ERROR);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -107,69 +89,35 @@ static void tc_libc_signal_sigemptyset_sigfillset(void)
        sigset_t sigset;
 
        ret_chk = sigfillset(&sigset);
-       if (ret_chk != OK) {
-               printf("tc_libc_signal_sigemptyset_sigfillset sigfillset FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sigfillset", ret_chk, OK);
 
        ret_chk = sigismember(&sigset, SIGQUIT);
-       if (ret_chk != 1) {
-               printf("tc_libc_signal_sigemptyset_sigfillset sigfillset FAIL, SIGQUIT not found Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sigismember", ret_chk, 1);
 
        ret_chk = sigismember(&sigset, SIGINT);
-       if (ret_chk != 1) {
-               printf("tc_libc_signal_sigemptyset_sigfillset sigfillset FAIL, SIGINT not found Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sigismember", ret_chk, 1);
 
        ret_chk = sigemptyset(&sigset);
-       if (ret_chk != OK) {
-               printf("tc_libc_signal_sigemptyset_sigfillset sigemptyset FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sigemptyset", ret_chk, OK);
 
        /* sigismember should not find any signal as all signals are set empty */
+
        ret_chk = sigismember(&sigset, SIGQUIT);
-       if (ret_chk == 1 || ret_chk == ERROR) {
-               printf("tc_libc_signal_sigemptyset_sigfillset sigemptyset FAIL, SIGQUIT found Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("sigemptyset", ret_chk, 1);
+       TC_ASSERT_NEQ("sigismember", ret_chk, ERROR);
 
-       ret_chk = sigismember(&sigset, SIGINT);
-       if (ret_chk == 1 || ret_chk == ERROR) {
-               printf("tc_libc_signal_sigemptyset_sigfillset sigemptyset FAIL, SIGINT found Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
        /* sigfillset will fill all signals to signal set */
+
        ret_chk = sigfillset(&sigset);
-       if (ret_chk != OK) {
-               printf("tc_libc_signal_sigemptyset_sigfillset sigfillset FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sigfillset", ret_chk, OK);
+
        ret_chk = sigismember(&sigset, SIGQUIT);
-       if (ret_chk != 1) {
-               printf("tc_libc_signal_sigemptyset_sigfillset sigfillset FAIL,SIGQUIT not found Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sigismember", ret_chk, 1);
+
        ret_chk = sigismember(&sigset, SIGINT);
-       if (ret_chk != 1) {
-               printf("tc_libc_signal_sigemptyset_sigfillset sigfillset FAIL, SIGINT not found Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       printf("tc_libc_signal_sigemptyset_sigfillset PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("sigismember", ret_chk, 1);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -189,35 +137,23 @@ static void tc_libc_signal_sigismember(void)
        sigset_t sigset;
 
        ret_chk = sigemptyset(&sigset);
-       if (ret_chk != OK) {
-               printf("tc_libc_signal_sigismember sigemptyset FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sigemptyset", ret_chk, OK);
 
        ret_chk = sigismember(&sigset, SIGQUIT);
-       if (ret_chk == 1 || ret_chk == ERROR) {
-               printf("tc_libc_signal_sigismember sigismember FAIL,member found Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("sigismember", ret_chk, 1);
+       TC_ASSERT_NEQ("sigismember", ret_chk, ERROR);
+
        /* sigfillset will fill all signals to signal set */
+
        ret_chk = sigfillset(&sigset);
-       if (ret_chk != OK) {
-               printf("tc_libc_signal_sigismember sigfillset FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sigfillset", ret_chk, OK);
+
        /* sigismember will find the signals which were filled by sigfillset */
+
        ret_chk = sigismember(&sigset, SIGQUIT);
-       if (ret_chk != 1) {
-               printf("tc_libc_signal_sigismember sigismember FAIL, member not found Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       printf("tc_libc_signal_sigismember PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("sigismember", ret_chk, 1);
+
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index cdcf7ef..83b5a26 100644 (file)
@@ -67,25 +67,11 @@ static void tc_libc_spawn_posix_spawnattr_init(void)
        posix_spawnattr_t st_attr;
 
        ret_chk = posix_spawnattr_init(&st_attr);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_init  : posix_spawnattr_init ret_chk FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       if (st_attr.flags != 0) {
-               printf("tc_libc_spawn_posix_spawnattr_init FAIL:  st_attr.flags is not 0  \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       if (st_attr.stacksize != CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE) {
-               printf("tc_libc_spawn_posix_spawnattr_init FAIL: st_attr.stacksize is not correct \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_spawn_posix_spawnattr_init PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("posix_spawnattr_init", ret_chk, OK);
+       TC_ASSERT_EQ("posix_spawnattr_init", st_attr.flags, 0);
+       TC_ASSERT_EQ("posix_spawnattr_init", st_attr.stacksize, CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -106,41 +92,21 @@ static void tc_libc_spawn_posix_spawnattr_setgetschedparam(void)
        posix_spawnattr_t st_attr;
 
        ret_chk = posix_spawnattr_init(&st_attr);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetschedparam  : posix_spawnattr_init FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawnattr_init", ret_chk, OK);
 
        setParam.sched_priority = HIGH_PRIORITY;
        ret_chk = posix_spawnattr_setschedparam(&st_attr, &setParam);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetschedparam : posix_spawnattr_setschedparam FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawnattr_setschedparam", ret_chk, OK);
 
        ret_chk = task_spawn(&pid, "spawn", function_name_spawn, NULL, &st_attr, (char *const *)NULL, (char *const *)NULL);
        sleep(SEC_4);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetschedparam : task_spawn FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("task_spawn", ret_chk, OK);
 
        ret_chk = posix_spawnattr_getschedparam(&st_attr, &getParam);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetschedparam : posix_spawnattr_getschedparam FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (setParam.sched_priority != getParam.sched_priority) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetschedparam : posix_spawnattr_getschedparam FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_spawn_posix_spawnattr_setgetschedparam PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("posix_spawnattr_getschedparam", ret_chk, OK);
+       TC_ASSERT_EQ("posix_spawnattr_getschedparam", setParam.sched_priority, getParam.sched_priority);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -161,41 +127,20 @@ static void tc_libc_spawn_posix_spawnattr_setgetflags(void)
        short int flags;
 
        ret_chk = posix_spawnattr_init(&st_attr);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetflags  : posix_spawnattr_init FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawnattr_init", ret_chk, OK);
 
        ret_chk = posix_spawnattr_setflags(&st_attr, POSIX_SPAWN_SETSCHEDPARAM);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetflags : posix_spawnattr_setflags FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawnattr_setflags", ret_chk, OK);
 
        ret_chk = task_spawn(&pid, "spawn_flag", function_name_spawn, NULL, &st_attr, (char *const *)NULL, (char *const *)NULL);
        sleep(SEC_3);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetflags : task_spawn FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("task_spawn", ret_chk, OK);
 
        ret_chk = posix_spawnattr_getflags(&st_attr, &flags);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetflags : posix_spawnattr_getflags FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       if (flags != POSIX_SPAWN_SETSCHEDPARAM) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetflags FAIL: set and get not equal FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_spawn_posix_spawnattr_setgetflags PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("posix_spawnattr_getflags", ret_chk, OK);
+       TC_ASSERT_EQ("posix_spawnattr_getflags", flags, POSIX_SPAWN_SETSCHEDPARAM);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -216,43 +161,20 @@ static void tc_libc_spawn_posix_spawnattr_setgetschedpolicy(void)
        int schedpolicy;
 
        ret_chk = posix_spawnattr_init(&st_attr);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetschedpolicy  : posix_spawnattr_init FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawnattr_init", ret_chk, OK);
 
        ret_chk = posix_spawnattr_setschedpolicy(&st_attr, SCHED_RR);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetschedpolicy  : posix_spawnattr_setschedpolicy FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawnattr_setschedpolicy", ret_chk, OK);
 
        ret_chk = task_spawn(&pid, "spawn_policy", function_name_spawn, NULL, &st_attr, (char *const *)NULL, (char *const *)NULL);
        sleep(SEC_4);
-
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetschedpolicy : task_spawn FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("task_spawn", ret_chk, OK);
 
        ret_chk = posix_spawnattr_getschedpolicy(&st_attr, &schedpolicy);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetschedpolicy  : posix_spawnattr_getschedpolicy FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       if (schedpolicy != SCHED_RR) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetschedpolicy : set and get not equal FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       printf("tc_libc_spawn_posix_spawnattr_setgetschedpolicy PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("posix_spawnattr_getschedpolicy", ret_chk, OK);
+       TC_ASSERT_EQ("posix_spawnattr_getschedpolicy", schedpolicy, SCHED_RR);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -273,42 +195,20 @@ static void tc_libc_spawn_task_spawnattr_setgetstacksize(void)
        size_t stacksize;
 
        ret_chk = posix_spawnattr_init(&st_attr);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_task_spawnattr_setgetstacksize  : posix_spawnattr_init FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawnattr_init", ret_chk, OK);
 
        ret_chk = task_spawnattr_setstacksize(&st_attr, CONFIG_USERMAIN_STACKSIZE);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_task_spawnattr_setgetstacksize : task_spawnattr_setstacksize FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("task_spawnattr_setstacksize", ret_chk, OK);
 
        ret_chk = task_spawn(&pid, "spawn_stacksize", function_name_spawn, NULL, &st_attr, (char *const *)NULL, (char *const *)NULL);
        sleep(SEC_4);
-
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_task_spawnattr_setgetstacksize : task_spawn FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("task_spawn", ret_chk, OK);
 
        ret_chk = task_spawnattr_getstacksize(&st_attr, &stacksize);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_task_spawnattr_setgetstacksize  : task_spawnattr_getstacksize FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       if (stacksize != CONFIG_USERMAIN_STACKSIZE) {
-               printf("tc_libc_spawn_task_spawnattr_setgetstacksize  : set and get not equal FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_spawn_task_spawnattr_setgetstacksize PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("task_spawnattr_getstacksize", ret_chk, OK);
+       TC_ASSERT_EQ("task_spawnattr_getstacksize", stacksize, CONFIG_USERMAIN_STACKSIZE);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -329,42 +229,20 @@ static void tc_libc_spawn_posix_spawnattr_setgetsigmask(void)
        pid_t pid;
 
        ret_chk = posix_spawnattr_init(&st_attr);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetsigmask  : posix_spawnattr_init FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawnattr_init", ret_chk, OK);
 
        ret_chk = posix_spawnattr_setsigmask(&st_attr, &setMask);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetsigmask  : posix_spawnattr_setsigmask FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawnattr_setsigmask", ret_chk, OK);
 
        ret_chk = task_spawn(&pid, "spawn_sigmask", function_name_spawn, NULL, &st_attr, (char *const *)NULL, (char *const *)NULL);
        sleep(SEC_4);
-
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetsigmask : task_spawn FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("task_spawn", ret_chk, OK);
 
        ret_chk = posix_spawnattr_getsigmask(&st_attr, &getMask);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetsigmask  : posix_spawnattr_getsigmask FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       if (setMask != getMask) {
-               printf("tc_libc_spawn_posix_spawnattr_setgetsigmask  : set and get not equal FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_spawn_posix_spawnattr_setgetsigmask PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("posix_spawnattr_getsigmask", ret_chk, OK);
+       TC_ASSERT_EQ("posix_spawnattr_getsigmask", setMask, getMask);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -383,31 +261,17 @@ static void tc_libc_spawn_posix_spawnattr_dump(void)
        posix_spawnattr_t st_attr;
 
        ret_chk = posix_spawnattr_init(&st_attr);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_dump  : posix_spawnattr_init FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawnattr_init", ret_chk, OK);
 
        ret_chk = posix_spawnattr_setschedpolicy(&st_attr, SCHED_RR);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_dump  : posix_spawnattr_setschedpolicy FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawnattr_setschedpolicy", ret_chk, OK);
 
        ret_chk = task_spawn(&pid, "spawn_dump", function_name_spawn, NULL, &st_attr, (char *const *)NULL, (char *const *)NULL);
        sleep(SEC_4);
-
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawnattr_dump : task_spawn FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("task_spawn", ret_chk, OK);
 
        posix_spawnattr_dump(&st_attr);
-       printf("tc_libc_spawn_posix_spawnattr_dump PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -425,26 +289,13 @@ static void tc_libc_spawn_posix_spawn_file_actions_init(void)
        int ret_chk = ERROR;
 
        ret_chk = posix_spawn_file_actions_init(&st_fileactions);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawn_file_actions_init : posix_spawn_file_actions_init FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       if (st_fileactions != NULL) {
-               printf("tc_libc_spawn_posix_spawn_file_actions_init FAIL: st_fileactions is not NULL  \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawn_file_actions_init", ret_chk, OK);
+       TC_ASSERT_EQ("posix_spawn_file_actions_init", st_fileactions, NULL);
 
        ret_chk = posix_spawn_file_actions_destroy(&st_fileactions);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawn_file_actions_init : posix_spawn_file_actions_destroy FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_spawn_posix_spawn_file_actions_init PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("posix_spawn_file_actions_destroy", ret_chk, OK);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -465,41 +316,21 @@ static void tc_libc_spawn_posix_spawn_file_actions_addopenclose(void)
        int ret_chk = ERROR;
 
        ret_chk = posix_spawnattr_init(&st_attr);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawn_file_actions_addopenclose  : posix_spawnattr_init FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawnattr_init", ret_chk, OK);
 
        ret_chk = posix_spawn_file_actions_init(&st_fileactions);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawn_file_actions_addopenclose : posix_spawn_file_actions_init FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawn_file_actions_init", ret_chk, OK);
 
        ret_chk = posix_spawn_file_actions_addopen(&st_fileactions, 0, szfilepath, O_RDONLY, 0644);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawn_file_actions_addopenclose : posix_spawn_file_actions_addopen FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawn_file_actions_addopen", ret_chk, OK);
 
        ret_chk = posix_spawn_file_actions_addclose(&st_fileactions, 0);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawn_file_actions_addopenclose : posix_spawn_file_actions_addclose FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawn_file_actions_addclose", ret_chk, OK);
 
        ret_chk = posix_spawn_file_actions_destroy(&st_fileactions);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawn_file_actions_addopenclose : posix_spawn_file_actions_destroy FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_spawn_posix_spawn_file_actions_addopenclose PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("posix_spawn_file_actions_destroy", ret_chk, OK);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -518,38 +349,17 @@ static void tc_libc_spawn_posix_spawn_file_actions_destroy(void)
        int ret_chk = ERROR;
 
        ret_chk = posix_spawn_file_actions_init(&st_fileactions);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawn_file_actions_destroy : posix_spawn_file_actions_init FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawn_file_actions_init", ret_chk, OK);
 
        ret_chk = posix_spawn_file_actions_addopen(&st_fileactions, 1, szfilepath, O_WRONLY, 0644);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawn_file_actions_destroy : posix_spawn_file_actions_addopen FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       if (st_fileactions == NULL) {
-               printf("tc_libc_spawn_posix_spawn_file_actions_destroy FAIL:st_fileactions is NULL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawn_file_actions_addopen", ret_chk, OK);
+       TC_ASSERT_NOT_NULL("posix_spawn_file_actions_addopen", st_fileactions);
+
        ret_chk = posix_spawn_file_actions_destroy(&st_fileactions);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawn_file_actions_destroy : posix_spawn_file_actions_destroy FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       if (st_fileactions != NULL) {
-               printf("tc_libc_spawn_posix_spawn_file_actions_destroy FAIL:st_fileactions is not NULL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_spawn_posix_spawn_file_actions_destroy PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("posix_spawn_file_actions_destroy", ret_chk, OK);
+       TC_ASSERT_EQ("posix_spawn_file_actions_destroy", st_fileactions, NULL);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -568,29 +378,19 @@ static void tc_libc_spawn_posix_spawn_file_actions_dump(void)
        int ret_chk = ERROR;
 
        ret_chk = posix_spawn_file_actions_init(&st_fileactions);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawn_file_actions_dump : posix_spawn_file_actions_init FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawn_file_actions_init", ret_chk, OK);
 
        ret_chk = posix_spawn_file_actions_addopen(&st_fileactions, 1, szfilepath, O_WRONLY, 0644);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawn_file_actions_dump : posix_spawn_file_actions_addopen FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawn_file_actions_addopen", ret_chk, OK);
+
        /* posix_spawn_file_actions_dump returns (void) */
+
        posix_spawn_file_actions_dump(&st_fileactions);
 
        ret_chk = posix_spawn_file_actions_destroy(&st_fileactions);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_posix_spawn_file_actions_dump : posix_spawn_file_actions_destroy FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_spawn_posix_spawn_file_actions_dump PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("posix_spawn_file_actions_destroy", ret_chk, OK);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -613,18 +413,10 @@ static void tc_libc_spawn_add_file_action(void)
        int ret_chk = ERROR;
 
        ret_chk = posix_spawn_file_actions_init(&st_fileactions);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_add_file_action : posix_spawn_file_actions_init FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawn_file_actions_init", ret_chk, OK);
 
        ret_chk = posix_spawn_file_actions_addopen(&st_fileactions, 1, szfilepath, O_WRONLY, 0644);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_add_file_action : posix_spawn_file_actions_addopen FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("posix_spawn_file_actions_addopen", ret_chk, OK);
 
        length = strlen(szfilepath);
        alloc_num = SIZEOF_OPEN_FILE_ACTION_S(length);
@@ -632,41 +424,24 @@ static void tc_libc_spawn_add_file_action(void)
        /* Allocate the action list entry of this size */
 
        entry1 = (struct spawn_open_file_action_s *)zalloc(alloc_num);
-       if (!entry1) {
-               printf("tc_libc_spawn_add_file_action : lib_zalloc for entry1 FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("zalloc", entry1);
 
        /* And add it to the file action list */
 
        add_file_action(st_fileactions, (struct spawn_general_file_action_s *)entry1);
 
        entry2 = (struct spawn_open_file_action_s *)zalloc(alloc_num);
-       if (!entry2) {
-               printf("tc_libc_spawn_add_file_action : lib_zalloc for entry2 FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("zalloc", entry2);
 
        /* And add it to the file action list */
-       add_file_action(st_fileactions, (struct spawn_general_file_action_s *)entry2);
 
-       if (entry1->flink != (struct spawn_general_file_action_s *)entry2) {
-               printf("tc_libc_spawn_add_file_action : entry1->flink is not equal to entry2 FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       add_file_action(st_fileactions, (struct spawn_general_file_action_s *)entry2);
+       TC_ASSERT_EQ("add_file_action", entry1->flink, (struct spawn_general_file_action_s *)entry2);
 
        ret_chk = posix_spawn_file_actions_destroy(&st_fileactions);
-       if (ret_chk != OK) {
-               printf("tc_libc_spawn_add_file_action : posix_spawn_file_actions_destroy FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       printf("tc_libc_spawn_add_file_action PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("posix_spawn_file_actions_destroy", ret_chk, OK);
+
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index c4d7cf3..21d1a55 100644 (file)
 #include <sys/types.h>
 #include "tc_internal.h"
 
-#define BUFF_SIZE 32
+#define BUFF_SIZE 128
+
+const char *printable_chars = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
 
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
 /**
-* @fn                   :asprintf_func
-* @description          :Function for tc_libc_stdio_asprintf
-* @return               :int
-*/
-static int asprintf_func(const char *format, ...)
-{
-       int ret_chk;
-       char *buffer;
-       const char *pname = "Example";
-       va_list args;
-       va_start(args, format);
-       ret_chk = avsprintf(&buffer, format, args);
-       va_end(args);
-
-       if (buffer == NULL) {
-               printf("tc_libc_stdio_avsprintf FAIL\n");
-               return ERROR;
-       }
-       if (ret_chk != strlen(pname)) {
-               printf("tc_libc_stdio_avsprintf FAIL\n");
-               free(buffer);
-               return ERROR;
-       }
-       if (strcmp(pname, buffer) != 0) {
-               printf("tc_libc_stdio_avsprintf FAIL, Error No: %d\n", errno);
-               free(buffer);
-               return ERROR;
-       }
-
-       free(buffer);
-       return OK;
-}
-
-/**
-* @fn                   :vfprintf_func
-* @description          :Function for tc_libc_stdio_vfprintf
-* @return               :int
-*/
-static int vfprintf_func(const char *format, ...)
-{
-       int ret_chk;
-       const char *pstr = "tc_libc_stdio_vfprintf";
-       va_list args;
-       va_start(args, format);
-       ret_chk = vfprintf(stdout, format, args);
-       va_end(args);
-
-       if (ret_chk != strlen(pstr)) {
-               printf(" FAIL\n");
-               return ERROR;
-       }
-
-       return OK;
-}
-
-/**
-* @fn                   :avsprintf_func
-* @description          :Function for tc_libc_stdio_avsprintf
-* @return               :int
-*/
-static int avsprintf_func(const char *format, ...)
-{
-       int ret_chk;
-       char *buffer;
-       const char *pname = "Example";
-       va_list args;
-       va_start(args, format);
-       ret_chk = avsprintf(&buffer, format, args);
-       va_end(args);
-
-       if (buffer == NULL) {
-               printf("tc_libc_stdio_avsprintf FAIL\n");
-               return ERROR;
-       }
-       if (ret_chk != strlen(pname)) {
-               printf("tc_libc_stdio_avsprintf FAIL\n");
-               free(buffer);
-               return ERROR;
-       }
-       if (strcmp(pname, buffer) != 0) {
-               printf("tc_libc_stdio_avsprintf FAIL, Error No: %d\n", errno);
-               free(buffer);
-               return ERROR;
-       }
-
-       free(buffer);
-       return OK;
-}
-
-/**
-* @fn                   :vsscanf_func
-* @description          :function for tc_libc_stdio_vsscanf_vsprintf
-* @return               :NA
-*/
-static void vsscanf_func(const char *str, const char *format, ...)
-{
-       va_list args;
-       va_start(args, format);
-       vsscanf(str, format, args);
-       va_end(args);
-}
-
-/**
-* @fn                   :vsprintf_func
-* @description          :function for tc_libc_stdio_vsscanf_vsprintf
-* @return               :int
-*/
-static int vsprintf_func(const char *format, ...)
-{
-       int ret_chk = ERROR;
-       char buffer[BUFF_SIZE];
-       char *pname = "test";
-       va_list args;
-       va_start(args, format);
-       ret_chk = vsprintf(buffer, format, args);
-       va_end(args);
-       if (ret_chk != strlen(pname)) {
-               printf("tc_libc_stdio_vsscanf_vsprintf vsprintf FAIL");
-               return ERROR;
-       }
-       if (strncmp(pname, buffer, strlen(pname)) != OK) {
-               printf("tc_libc_stdio_vsscanf_vsprintf sprintf FAIL");
-               return ERROR;
-       }
-       return OK;
-}
-
-/**
-* @fn                   :vprintf_func
-* @description          :Function for tc_libc_stdio_vprintf
-* @return               :int
-*/
-static int vprintf_func(const char *format, ...)
-{
-       int val;
-       va_list args;
-       va_start(args, format);
-       val = vprintf(format, args);
-       va_end(args);
-
-       return val;
-}
-
-/**
-* @fn                   :vsnprintf_func
-* @description          :Function for tc_libc_stdio_vsnprintf
-* @return               :int
-*/
-static int vsnprintf_func(const char *format, ...)
-{
-       char buffer[BUFF_SIZE];
-       va_list args;
-       va_start(args, format);
-       vsnprintf(buffer, BUFF_SIZE, format, args);
-       va_end(args);
-
-       return strlen(buffer);
-}
-
-/**
 * @fn                   :tc_libc_stdio_flush
 * @brief                :The fflush() function flushes the output buffer
 * @scenario             :The fflush() function flushes the output buffer of a stream.
@@ -210,21 +52,27 @@ static int vsnprintf_func(const char *format, ...)
 */
 static void tc_libc_stdio_flush(void)
 {
-       int ret_chk = ERROR;
-       char *str1 = "tc_libc_stdio_flush ";
-       char *str2 = "PASS\n";
+       int ret_chk;
+
+       /* Without fflush, stream output will printed when buffer meet '\n'.
+        * So, stream output will printed after 3 sec */
+
+       printf("fflush test : without fflush\n");
+       fprintf(stdout, "%s", "You can see this line after 3 sec");
+       sleep(3);
+       printf("\n");
+
+       /* Using fflush, stream output will printed when fflush is called.
+        * So, stream output will printed right now */
 
-       fprintf(stdout, str1);
-       fprintf(stdout, str2);
+       printf("fflush test : using fflush\n");
+       fprintf(stdout, "%s", "You can see this line right now");
        ret_chk = fflush(stdout);
-       /* Flushes the output buffer of stream, cannot be checked for scenario TC, as output is flushed on screen
-          flused output is checked manually on screen */
-       if (ret_chk != OK) {
-               printf("tc_libc_stdio_fflush FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       total_pass++;
+       TC_ASSERT_EQ("fflush", ret_chk, OK);
+       sleep(3);
+       printf("\n");
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -236,19 +84,26 @@ static void tc_libc_stdio_flush(void)
 * Postconditions        :none
 * @return               :void
 */
-static void tc_libc_stdio_avsprintf(void)
+static void tc_libc_stdio_avsprintf(const char *format, ...)
 {
-       int ret_chk = ERROR;
-       const char *pname = "Example";
-       ret_chk = avsprintf_func("%s", pname);
-
-       if (ret_chk != OK) {
-               printf("tc_libc_stdio_avsprintf FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_stdio_avsprintf PASS\n");
-       total_pass++;
+       int ret_chk;
+       char *buffer;
+       va_list args;
+       va_start(args, format);
+       ret_chk = avsprintf(&buffer, format, args);
+       va_end(args);
+       TC_ASSERT_NOT_NULL("avsprintf", buffer);
+       TC_ASSERT_EQ_CLEANUP("avsprintf",
+                                                ret_chk, strlen(printable_chars),
+                                                get_errno(),
+                                                TC_FREE_MEMORY(buffer));
+       TC_ASSERT_EQ_CLEANUP("avsprintf",
+                                                strcmp(printable_chars, buffer), 0,
+                                                get_errno(),
+                                                TC_FREE_MEMORY(buffer));
+
+       TC_FREE_MEMORY(buffer);
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -262,25 +117,14 @@ static void tc_libc_stdio_avsprintf(void)
 */
 static void tc_libc_stdio_snprintf(void)
 {
-       int ret_chk = ERROR;
-       char *pname = "Example";
-       char buff[BUFF_SIZE];
-
-       ret_chk = snprintf(buff, BUFF_SIZE, "%s", pname);
-       if (ret_chk != strlen(pname)) {
-               printf("tc_libc_stdio_snprintf FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       int ret_chk;
+       char buffer[BUFF_SIZE];
 
-       if (strncmp(pname, buff, strlen(pname)) != OK) {
-               printf("tc_libc_stdio_snprintf FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = snprintf(buffer, BUFF_SIZE, "%s", printable_chars);
+       TC_ASSERT_EQ("snprintf", ret_chk, strlen(printable_chars));
+       TC_ASSERT_EQ("snprintf", strncmp(printable_chars, buffer, strlen(printable_chars)), 0);
 
-       printf("tc_libc_stdio_snprintf PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -299,35 +143,35 @@ static void tc_libc_stdio_snprintf(void)
 */
 static void tc_libc_stdio_sscanf_sprintf(void)
 {
-       int ret_chk = ERROR;
-       char *pname = "test";
+       int ret_chk;
        char char_arr[BUFF_SIZE], sz_pptr[BUFF_SIZE];
 
-       ret_chk = sscanf(pname, "%s", char_arr);
-       if (ret_chk == OK) {
-               printf("tc_libc_stdio_sscanf_sprintf sscanf FAIL");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (strncmp(pname, char_arr, strlen(pname)) != OK) {
-               printf("tc_libc_stdio_sscanf_sprintf sscanf FAIL");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = sscanf(printable_chars, "%s", char_arr);
+       TC_ASSERT_EQ("sscanf", ret_chk, 1);
+       TC_ASSERT_EQ("sscanf", strncmp(printable_chars, char_arr, strlen(printable_chars)), -1);
 
-       ret_chk = sprintf(sz_pptr, "%s", pname);
-       if (ret_chk != strlen(pname)) {
-               printf("tc_libc_stdio_sscanf_sprintf sprintf FAIL");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (strncmp(pname, sz_pptr, strlen(pname)) != OK) {
-               printf("tc_libc_stdio_sscanf_sprintf sprintf FAIL");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_stdio_sscanf_sprintf PASS\n");
-       total_pass++;
+       ret_chk = sscanf(printable_chars + 1, "%s", char_arr);
+       TC_ASSERT_EQ("sscanf", ret_chk, 1);
+       TC_ASSERT_EQ("sscanf", strncmp(printable_chars + 1, char_arr, strlen(printable_chars + 1)), 0);
+
+       ret_chk = sprintf(sz_pptr, "%s", printable_chars);
+       TC_ASSERT_EQ("sprintf", ret_chk, strlen(printable_chars));
+       TC_ASSERT_EQ("sprintf", strncmp(printable_chars, sz_pptr, strlen(printable_chars)), 0);
+
+       TC_SUCCESS_RESULT();
+}
+
+/**
+* @fn                   :vsscanf_func
+* @description          :function for tc_libc_stdio_vsscanf_vsprintf
+* @return               :NA
+*/
+static void vsscanf_func(const char *str, const char *format, ...)
+{
+       va_list args;
+       va_start(args, format);
+       vsscanf(str, format, args);
+       va_end(args);
 }
 
 /**
@@ -345,28 +189,25 @@ static void tc_libc_stdio_sscanf_sprintf(void)
 * Postconditions        :none
 * @return               :void
 */
-static void tc_libc_stdio_vsscanf_vsprintf(void)
+static void tc_libc_stdio_vsscanf_vsprintf(const char *format, ...)
 {
-       int ret_chk = ERROR;
-       char *pname = "test";
-       char char_arr[BUFF_SIZE];
-
-       vsscanf_func(pname, "%s", char_arr);
-       if (strncmp(pname, char_arr, strlen(pname)) != OK) {
-               printf("tc_libc_stdio_vsscanf_vsprintf vsscanf FAIL");
-               total_fail++;
-               RETURN_ERR;
-       }
+       int ret_chk;
+       char buffer[BUFF_SIZE];
+       va_list args;
 
-       ret_chk = vsprintf_func("%s", pname);
-       if (ret_chk != OK) {
-               printf("tc_libc_stdio_vsscanf_vsprintf vsprintf FAIL");
-               total_fail++;
-               RETURN_ERR;
-       }
+       vsscanf_func(printable_chars, "%s", buffer);
+       TC_ASSERT_EQ("vsscanf", strncmp(printable_chars, buffer, strlen(printable_chars)), -1);
+
+       vsscanf_func(printable_chars + 1, "%s", buffer);
+       TC_ASSERT_EQ("vsscanf", strncmp(printable_chars + 1, buffer, strlen(printable_chars + 1)), 0);
 
-       printf("tc_libc_stdio_vsscanf_vsprintf PASS\n");
-       total_pass++;
+       va_start(args, format);
+       ret_chk = vsprintf(buffer, format, args);
+       va_end(args);
+       TC_ASSERT_EQ("vsprintf", ret_chk, strlen(printable_chars));
+       TC_ASSERT_EQ("vsprintf", strncmp(printable_chars, buffer, strlen(printable_chars)), 0);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -380,20 +221,17 @@ static void tc_libc_stdio_vsscanf_vsprintf(void)
 * Postconditions        :none
 * @return               :void
 */
-static void tc_libc_stdio_vprintf(void)
+static void tc_libc_stdio_vprintf(const char *format, ...)
 {
-       int ret_chk = ERROR;
-       char *pname = "tc_";
-
-       ret_chk = vprintf_func("%s", pname);
-       if (ret_chk != strlen(pname)) {
-               printf("tc_libc_stdio_vprintf FAIL");
-               total_fail++;
-               RETURN_ERR;
-       }
+       int ret_chk;
+       va_list args;
 
-       printf("libc_stdio_vprintf PASS\n");
-       total_pass++;
+       va_start(args, format);
+       ret_chk = vprintf(format, args);
+       va_end(args);
+       TC_ASSERT_EQ("vprintf", ret_chk, strlen(printable_chars));
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -408,20 +246,18 @@ static void tc_libc_stdio_vprintf(void)
 * Postconditions        :none
 * @return               :void
 */
-static void tc_libc_stdio_vsnprintf(void)
+static void tc_libc_stdio_vsnprintf(const char *format, ...)
 {
-       int ret_chk = ERROR;
-       char *pname = "Example";
-
-       ret_chk = vsnprintf_func("%s", pname);
-       if (ret_chk != strlen(pname)) {
-               printf("tc_libc_stdio_vsnprintf FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       int ret_chk;
+       char buffer[BUFF_SIZE];
+       va_list args;
+
+       va_start(args, format);
+       ret_chk = vsnprintf(buffer, BUFF_SIZE, format, args);
+       va_end(args);
+       TC_ASSERT_EQ("vsnprintf", ret_chk, strlen(printable_chars));
 
-       printf("tc_libc_stdio_vsnprintf PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -438,18 +274,20 @@ static void tc_libc_stdio_vsnprintf(void)
 */
 static void tc_libc_stdio_puts(void)
 {
-       int ret_chk = ERROR;
+       int ret_chk;
        int ret_length;
-       char *str_ptr = "tc_libc_stdio_puts PASS";
-       ret_length = strlen(str_ptr) + 1;       /* appends a newline character ('\n'). */
-       ret_chk = puts(str_ptr);
-       /* scenario testcase is covered by checking the return value, which must be equal to characters written to standard output */
-       if (ret_chk != ret_length) {
-               printf("tc_libc_stdio_puts FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       total_pass++;
+
+       /* appends a newline character ('\n'). */
+
+       ret_length = strlen(printable_chars) + 1;
+
+       /* scenario testcase is covered by checking the return value,
+        * which must be equal to characters written to standard output */
+
+       ret_chk = puts(printable_chars);
+       TC_ASSERT_EQ("puts", ret_chk, ret_length);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -469,15 +307,11 @@ static void tc_libc_stdio_perror(void)
        set_errno(ENODATA);
 #ifdef CONFIG_LIBC_STRERROR
        test_msg = strerror(get_errno());
-       if (strncmp(test_msg, result_msg, strlen(result_msg)) != 0) {
-               total_fail++;
-               printf("tc_libc_stdio_perror FAIL\n");
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("strerror", strncmp(test_msg, result_msg, strlen(result_msg)), 0);
 #endif
        perror("Perror Test : Err Msg - No data available");
-       total_pass++;
-       printf("tc_libc_stdio_perror PASS\n");
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -491,16 +325,10 @@ static void tc_libc_stdio_perror(void)
 static void tc_libc_stdio_printf(void)
 {
        int ret_chk;
-       const char *str = "tc_libc_stdio_printf";
+       ret_chk = printf("%s", printable_chars);
+       TC_ASSERT_EQ("printf", ret_chk, strlen(printable_chars));
 
-       ret_chk = printf("%s", str);
-       if (ret_chk != strlen(str)) {
-               printf(" FAIL %d %d\n", strlen(str), ret_chk);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf(" PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -511,19 +339,17 @@ static void tc_libc_stdio_printf(void)
 * Postconditions        :none
 * @return               :void
 */
-static void tc_libc_stdio_vfprintf(void)
+static void tc_libc_stdio_vfprintf(const char *format, ...)
 {
-       int ret_chk = ERROR;
-       const char *pstr = "tc_libc_stdio_vfprintf";
+       int ret_chk;
+       va_list args;
 
-       ret_chk = vfprintf_func("%s", pstr);
-       if (ret_chk != OK) {
-               total_fail++;
-               RETURN_ERR;
-       }
+       va_start(args, format);
+       ret_chk = vfprintf(stdout, format, args);
+       va_end(args);
+       TC_ASSERT_EQ("vfprintf", ret_chk, strlen(printable_chars));
 
-       printf(" PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -535,19 +361,27 @@ static void tc_libc_stdio_vfprintf(void)
 * Postconditions        :none
 * @return               :void
 */
-static void tc_libc_stdio_asprintf(void)
+static void tc_libc_stdio_asprintf(const char *format, ...)
 {
-       int ret_chk = ERROR;
-       const char *pname = "Example";
-       ret_chk = asprintf_func("%s", pname);
-
-       if (ret_chk != OK) {
-               printf("tc_libc_stdio_asprintf FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_stdio_asprintf PASS\n");
-       total_pass++;
+       int ret_chk;
+       char *buffer;
+       va_list args;
+
+       va_start(args, format);
+       ret_chk = avsprintf(&buffer, format, args);
+       va_end(args);
+       TC_ASSERT_NOT_NULL("asprintf", buffer);
+       TC_ASSERT_EQ_CLEANUP("asprintf",
+                                                ret_chk, strlen(printable_chars),
+                                                get_errno(),
+                                                TC_FREE_MEMORY(buffer));
+       TC_ASSERT_EQ_CLEANUP("asprintf",
+                                                strcmp(printable_chars, buffer), 0,
+                                                get_errno(),
+                                                TC_FREE_MEMORY(buffer));
+
+       TC_FREE_MEMORY(buffer);
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -561,17 +395,17 @@ static void tc_libc_stdio_asprintf(void)
 */
 static void tc_libc_stdio_putchar(void)
 {
-       int ret;
+       int ret_chk;
+       int c;
 
-       ret = putchar('t');
-       if (ret < 0) {
-               printf("tc_libc_stdio_putchar FAIL%d\n");
-               total_fail++;
-               RETURN_ERR;
+       /* 32( ) to 126(~) is printable ASCII code */
+
+       for (c = 32; c <= 126; c++) {
+               ret_chk = putchar((char)c);
+               TC_ASSERT_EQ("putchar", ret_chk, c);
        }
 
-       printf("c_libc_stdio_putchar PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
@@ -581,18 +415,19 @@ static void tc_libc_stdio_putchar(void)
 int libc_stdio_main(void)
 {
        tc_libc_stdio_flush();
-       tc_libc_stdio_avsprintf();
+       tc_libc_stdio_avsprintf("%s", printable_chars);
        tc_libc_stdio_snprintf();
        tc_libc_stdio_sscanf_sprintf();
-       tc_libc_stdio_vsscanf_vsprintf();
+       tc_libc_stdio_vsscanf_vsprintf("%s", printable_chars);
        tc_libc_stdio_puts();
-       tc_libc_stdio_vprintf();
-       tc_libc_stdio_vsnprintf();
+       tc_libc_stdio_vprintf("%s", printable_chars);
+       tc_libc_stdio_vsnprintf("%s", printable_chars);
        tc_libc_stdio_perror();
        tc_libc_stdio_printf();
-       tc_libc_stdio_vfprintf();
-       tc_libc_stdio_asprintf();
+       tc_libc_stdio_vfprintf("%s", printable_chars);
+       tc_libc_stdio_asprintf("%s", printable_chars);
        tc_libc_stdio_putchar();
 
        return 0;
 }
+
index b750230..0488963 100644 (file)
@@ -63,50 +63,50 @@ static int compare(const void *a, const void *b)
 */
 static void tc_libc_stdlib_abs_labs_llabs(void)
 {
-       int val1 = NVAL1;
-       int val2 = -NVAL2;
-       int ret_chk1;
-       int ret_chk2;
-       long int lval1 = LVAL1;
-       long int lval2 = -LVAL2;
-       long int lret_chk1;
-       long int lret_chk2;
-       long long int llval1 = LLVAL1;
-       long long int llval2 = -LLVAL2;
-       long long int llret_chk1;
-       long long int llret_chk2;
-
-       /* val1 is a positive number, ret_chk1 should be positive */
-       ret_chk1 = abs(val1);
-       /* val2 is a negative number, ret_chk2 should be positive */
-       ret_chk2 = abs(val2);
-       if (ret_chk1 != NVAL1 || ret_chk2 != NVAL2) {
-               printf("tc_libc_stdlib_abs FAIL Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       int val;
+       int ret_chk;
+       long int lval;
+       long int lret_chk;
+       long long int llval;
+       long long int llret_chk;
 
-       /* lval1 is a positive number, lret_chk1 should be positive */
-       lret_chk1 = labs(lval1);
-       /* lval2 is a negative number, lret_chk2 should be positive */
-       lret_chk2 = labs(lval2);
-       if (lret_chk1 != LVAL1 || lret_chk2 != LVAL2) {
-               printf("tc_libc_stdlib_labs FAIL Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       /* val is a positive number, ret_chk should be positive */
 
-       /* llVal1 is a positive number, llret_chk1 should be positive */
-       llret_chk1 = llabs(llval1);
-       /* llVal2 is a negative number, llret_chk2 should be positive */
-       llret_chk2 = llabs(llval2);
-       if (llret_chk1 != LLVAL1 || llret_chk2 != LLVAL2) {
-               printf("tc_libc_stdlib_llabs FAIL Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_stdlib_abs_labs_llabs PASS\n");
-       total_pass++;
+       val = NVAL1;
+       ret_chk = abs(val);
+       TC_ASSERT_EQ("abs", ret_chk, NVAL1);
+
+       /* val is a negative number, ret_chk should be positive */
+
+       val = -NVAL2;
+       ret_chk = abs(val);
+       TC_ASSERT_EQ("abs", ret_chk, NVAL2);
+
+       /* lval is a positive number, lret_chk should be positive */
+
+       lval = LVAL1;
+       lret_chk = labs(lval);
+       TC_ASSERT_EQ("labs", lret_chk, LVAL1);
+
+       /* lval is a negative number, lret_chk should be positive */
+
+       lval = -LVAL2;
+       lret_chk = labs(lval);
+       TC_ASSERT_EQ("labs", lret_chk, LVAL2);
+
+       /* llVal is a positive number, llret_chk should be positive */
+
+       llval = LLVAL1;
+       llret_chk = llabs(llval);
+       TC_ASSERT_EQ("llabs", llret_chk, LLVAL1);
+
+       /* llVal is a negative number, llret_chk should be positive */
+
+       llval = -LLVAL2;
+       llret_chk = llabs(llval);
+       TC_ASSERT_EQ("llabs", llret_chk, LLVAL2);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -122,13 +122,9 @@ static void tc_libc_stdlib_imaxabs(void)
 {
        intmax_t val = -NVAL1;
        intmax_t ret_chk = imaxabs(val);
-       if (ret_chk != NVAL1) {
-               printf("tc_libc_stdlib_imaxabs FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_stdlib_imaxabs PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("imaxabs", ret_chk, NVAL1);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -144,33 +140,26 @@ static void tc_libc_stdlib_imaxabs(void)
 static void tc_libc_stdlib_itoa(void)
 {
        /* ITOA_VAL = 12 */
+
        int val = ITOA_VAL;
        char buffer[BUFF_SIZE];
 
        /* conversion in decimal */
+
        itoa(val, buffer, DECIMAL);
-       if (strcmp(buffer, "12") != OK) {
-               printf("tc_libc_stdlib_itoa FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("itoa", strcmp(buffer, "12"), 0);
+
        /* conversion in hexadecimal */
+
        itoa(val, buffer, HEXADECIMAL);
-       if (strcmp(buffer, "c") != OK) {
-               printf("tc_libc_stdlib_itoa FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("itoa", strcmp(buffer, "c"), 0);
+
        /* conversion in binary */
+
        itoa(val, buffer, BINARY);
-       if (strcmp(buffer, "1100") != OK) {
-               printf("tc_libc_stdlib_itoa FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("itoa", strcmp(buffer, "1100"), 0);
 
-       printf("tc_libc_stdlib_itoa PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -192,15 +181,11 @@ static void tc_libc_stdlib_qsort(void)
        qsort(value_arr, arr_length, sizeof(int), compare);
        for (data_idx = 0; data_idx < arr_length; data_idx++) {
                if (data_idx != arr_length - 1) {
-                       if (value_arr[data_idx] > value_arr[data_idx + 1]) {
-                               printf("tc_libc_stdlib_qsort FAIL\n");
-                               total_fail++;
-                               RETURN_ERR;
-                       }
+                       TC_ASSERT_LEQ("qsort", value_arr[data_idx], value_arr[data_idx + 1]);
                }
        }
-       printf("tc_libc_stdlib_qsort PASS\n");
-       total_pass++;
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -214,20 +199,21 @@ static void tc_libc_stdlib_qsort(void)
 */
 static void tc_libc_stdlib_rand(void)
 {
-       int ret_chk1 = ERROR;
-       int ret_chk2 = ERROR;
-       int ret_chk3 = ERROR;
-       ret_chk1 = rand();
-       ret_chk2 = rand();
-       ret_chk3 = rand();
-       if ((ret_chk1 < 0 || ret_chk1 > MAX_RAND) || (ret_chk2 < 0 || ret_chk2 > MAX_RAND) || (ret_chk3 < 0 || ret_chk3 > MAX_RAND)) {
-               printf("tc_libc_stdlib_rand FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       int ret_chk = ERROR;
+
+       ret_chk = rand();
+       TC_ASSERT_GEQ("rand", ret_chk, 0);
+       TC_ASSERT_LT("rand", ret_chk, MAX_RAND);
+
+       ret_chk = rand();
+       TC_ASSERT_GEQ("rand", ret_chk, 0);
+       TC_ASSERT_LT("rand", ret_chk, MAX_RAND);
+
+       ret_chk = rand();
+       TC_ASSERT_GEQ("rand", ret_chk, 0);
+       TC_ASSERT_LT("rand", ret_chk, MAX_RAND);
 
-       printf("tc_libc_stdlib_rand PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -245,25 +231,29 @@ static void tc_libc_stdlib_strtol(void)
        /* random string used for conversion */
        char str_lnum[] = "2001 60c0c0 -1101110100110100100000 0x6fffff";
        char *end_ptr;
-       long int li1;
-       long int li2;
-       long int li3;
-       long int li4;
-       /* li1 = 2001 for string 2001 in decimal */
-       li1 = strtol(str_lnum, &end_ptr, DECIMAL);
-       /* li2 = 6340800 for string 60c0c0 in hexadecimal */
-       li2 = strtol(end_ptr, &end_ptr, HEXADECIMAL);
-       /* li3 = -3624224 for string -1101110100110100100000 in binary */
-       li3 = strtol(end_ptr, &end_ptr, BINARY);
-       /* li4 = 7340031 for string 0x6fffff with base value 0 */
-       li4 = strtol(end_ptr, NULL, 0);
-       if (li1 != 2001 || li2 != 6340800 || li3 != -3624224 || li4 != 7340031) {
-               printf("tc_libc_stdlib_strtol FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_stdlib_strtol PASS\n");
-       total_pass++;
+       long int ret_chk;
+
+       /* ret_chk = 2001 for string 2001 in decimal */
+
+       ret_chk = strtol(str_lnum, &end_ptr, DECIMAL);
+       TC_ASSERT_EQ("strtol", ret_chk, 2001);
+
+       /* ret_chk = 6340800 for string 60c0c0 in hexadecimal */
+
+       ret_chk = strtol(end_ptr, &end_ptr, HEXADECIMAL);
+       TC_ASSERT_EQ("strtol", ret_chk, 6340800);
+
+       /* ret_chk = -3624224 for string -1101110100110100100000 in binary */
+
+       ret_chk = strtol(end_ptr, &end_ptr, BINARY);
+       TC_ASSERT_EQ("strtol", ret_chk, -3624224);
+
+       /* ret_chk = 7340031 for string 0x6fffff with base value 0 */
+
+       ret_chk = strtol(end_ptr, NULL, 0);
+       TC_ASSERT_EQ("strtol", ret_chk, 7340031);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -279,26 +269,29 @@ static void tc_libc_stdlib_strtoll(void)
 {
        char str_llnum[] = "1856892505 17b00a12b -01100011010110000010001101100 0x6fffff";
        char *end_ptr;
-       long long int lli1;
-       long long int lli2;
-       long long int lli3;
-       long long int lli4;
-
-       /* li1 = 1856892505 for string 1856892505 in decimal */
-       lli1 = strtoll(str_llnum, &end_ptr, DECIMAL);
-       /* lli2 = 6358606123 for string 17b00a12b in hexadecimal */
-       lli2 = strtoll(end_ptr, &end_ptr, HEXADECIMAL);
-       /* lli3 = -208340076 for string -01100011010110000010001101100 in binary */
-       lli3 = strtoll(end_ptr, &end_ptr, BINARY);
-       /* lli4 = 7340031 for string 0x6fffff with base 0 */
-       lli4 = strtoll(end_ptr, NULL, 0);
-       if (lli1 != 1856892505 || lli2 != 6358606123 || lli3 != -208340076 || lli4 != 7340031) {
-               printf("tc_libc_stdlib_strtoll FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_stdlib_strtoll PASS\n");
-       total_pass++;
+       long long int ret_chk;
+
+       /* ret_chk = 1856892505 for string 1856892505 in decimal */
+
+       ret_chk = strtoll(str_llnum, &end_ptr, DECIMAL);
+       TC_ASSERT_EQ("strtoll", ret_chk, 1856892505);
+
+       /* ret_chk = 6358606123 for string 17b00a12b in hexadecimal */
+
+       ret_chk = strtoll(end_ptr, &end_ptr, HEXADECIMAL);
+       TC_ASSERT_EQ("strtoll", ret_chk, 6358606123);
+
+       /* ret_chk = -208340076 for string -01100011010110000010001101100 in binary */
+
+       ret_chk = strtoll(end_ptr, &end_ptr, BINARY);
+       TC_ASSERT_EQ("strtoll", ret_chk, -208340076);
+
+       /* ret_chk = 7340031 for string 0x6fffff with base 0 */
+
+       ret_chk = strtoll(end_ptr, NULL, 0);
+       TC_ASSERT_EQ("strtoll", ret_chk, 7340031);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -315,26 +308,29 @@ static void tc_libc_stdlib_strtoul(void)
 {
        char str_ulnum[] = "201 60 1100 0x6f";
        char *end_ptr;
-       unsigned long int uli1;
-       unsigned long int uli2;
-       unsigned long int uli3;
-       unsigned long int uli4;
-
-       /* uli1 = 201 for string 201 in decimal */
-       uli1 = strtoul(str_ulnum, &end_ptr, DECIMAL);
-       /* uli2 = 96 for string 60 in hexadecimal */
-       uli2 = strtoul(end_ptr, &end_ptr, HEXADECIMAL);
-       /* uli3 = 12 for string 1100 in binary */
-       uli3 = strtoul(end_ptr, &end_ptr, BINARY);
-       /* uli4 = 111 for string 0x6f with base 0 */
-       uli4 = strtoul(end_ptr, NULL, 0);
-       if (uli1 != 201 || uli2 != 96 || uli3 != 12 || uli4 != 111) {
-               printf("tc_libc_stdlib_strtoul FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_stdlib_strtoul PASS\n");
-       total_pass++;
+       unsigned long int ret_chk;
+
+       /* ret_chk = 201 for string 201 in decimal */
+
+       ret_chk = strtoul(str_ulnum, &end_ptr, DECIMAL);
+       TC_ASSERT_EQ("strtoul", ret_chk, 201);
+
+       /* ret_chk = 96 for string 60 in hexadecimal */
+
+       ret_chk = strtoul(end_ptr, &end_ptr, HEXADECIMAL);
+       TC_ASSERT_EQ("strtoul", ret_chk, 96);
+
+       /* ret_chk = 12 for string 1100 in binary */
+
+       ret_chk = strtoul(end_ptr, &end_ptr, BINARY);
+       TC_ASSERT_EQ("strtoul", ret_chk, 12);
+
+       /* ret_chk = 111 for string 0x6f with base 0 */
+
+       ret_chk = strtoul(end_ptr, NULL, 0);
+       TC_ASSERT_EQ("strtoul", ret_chk, 111);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -350,93 +346,77 @@ static void tc_libc_stdlib_strtoull(void)
 {
        char str_ullnum[] = "250068492 7b06af00 1100011011110101010001100000 0x6fffff";
        char *end_ptr;
-       unsigned long long int ulli1;
-       unsigned long long int ulli2;
-       unsigned long long int ulli3;
-       unsigned long long int ulli4;
-
-       /* ulli1 = 250068492 for string 250068492 in decimal */
-       ulli1 = strtoull(str_ullnum, &end_ptr, DECIMAL);
-       /* ulli2 = 2064035584 for string 7b06af00 in hexadecimal */
-       ulli2 = strtoull(end_ptr, &end_ptr, HEXADECIMAL);
-       /* ulli3 = 208622688 for string 1100011011110101010001100000 in binary */
-       ulli3 = strtoull(end_ptr, &end_ptr, BINARY);
-       /* ulli4 = 7340031 for string 0x6fffff with base 0 */
-       ulli4 = strtoull(end_ptr, NULL, 0);
-       if (ulli1 != 250068492 || ulli2 != 2064035584 || ulli3 != 208622688 || ulli4 != 7340031) {
-               printf("tc_libc_stdlib_strtoull FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_stdlib_strtoull PASS\n");
-       total_pass++;
+       unsigned long long int ret_chk;
+
+       /* ret_chk = 250068492 for string 250068492 in decimal */
+
+       ret_chk = strtoull(str_ullnum, &end_ptr, DECIMAL);
+       TC_ASSERT_EQ("strtoull", ret_chk, 250068492);
+
+       /* ret_chk = 2064035584 for string 7b06af00 in hexadecimal */
+
+       ret_chk = strtoull(end_ptr, &end_ptr, HEXADECIMAL);
+       TC_ASSERT_EQ("strtoull", ret_chk, 2064035584);
+
+       /* ret_chk = 208622688 for string 1100011011110101010001100000 in binary */
+
+       ret_chk = strtoull(end_ptr, &end_ptr, BINARY);
+       TC_ASSERT_EQ("strtoull", ret_chk, 208622688);
+
+       /* ret_chk = 7340031 for string 0x6fffff with base 0 */
+
+       ret_chk = strtoull(end_ptr, NULL, 0);
+       TC_ASSERT_EQ("strtoull", ret_chk, 7340031);
+
+       TC_SUCCESS_RESULT();
 }
 
 static void tc_libc_stdlib_strtod(void)
 {
        char target[100] = "1234.56abcd";
        char *pos = NULL;
-       double value = 0;
+       double ret_chk = 0;
 
-       value = strtod(target, &pos);
-       if (value != 1234.56) {
-               total_fail++;
-               printf("tc_libc_stdlib_strtod FAIL : not matched %d %s\n", value, pos);
-               RETURN_ERR;
-       }
-       total_pass++;
-       printf("tc_libc_stdlib_strtod PASS\n");
+       ret_chk = strtod(target, &pos);
+       TC_ASSERT_EQ("atoi", ret_chk, 1234.56);
+
+       TC_SUCCESS_RESULT();
 }
 
 static void tc_libc_stdlib_atoi(void)
 {
        /* random string used for conversion */
        char str_lnum[] = "2016";
-       int target;
-       /* target = 2001 for string 2001 in decimal */
-       target = atoi(str_lnum);
-       if (target != 2016) {
-               total_fail++;
-               printf("tc_libc_stdlib_atoi FAIL\n");
-               RETURN_ERR;
-       }
+       int ret_chk;
+       /* ret_chk = 2001 for string 2001 in decimal */
+       ret_chk = atoi(str_lnum);
+       TC_ASSERT_EQ("atoi", ret_chk, 2016);
 
-       printf("tc_libc_stdlib_atoi PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 static void tc_libc_stdlib_atol(void)
 {
        /* random string used for conversion */
        char str_lnum[] = "20162015";
-       long int target;
+       long int ret_chk;
 
-       target = atol(str_lnum);
-       if (target != 20162015) {
-               total_fail++;
-               printf("tc_libc_stdlib_atol FAIL\n");
-               RETURN_ERR;
-       }
+       ret_chk = atol(str_lnum);
+       TC_ASSERT_EQ("atol", ret_chk, 20162015);
 
-       printf("tc_libc_stdlib_atol PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 static void tc_libc_stdlib_atoll(void)
 {
        /* random string used for conversion */
        char str_lnum[] = "201620152014";
-       long long int target;
+       long long int ret_chk;
 
-       target = atoll(str_lnum);
-       if (target != 201620152014) {
-               total_fail++;
-               printf("tc_libc_stdlib_atoll FAIL\n");
-               RETURN_ERR;
-       }
+       ret_chk = atoll(str_lnum);
+       TC_ASSERT_EQ("atoll", ret_chk, 201620152014);
 
-       printf("tc_libc_stdlib_atoll PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 static void tc_libc_stdlib_srand(void)
@@ -457,30 +437,21 @@ static void tc_libc_stdlib_srand(void)
        }
 
        for (result_iter = 0; result_iter < 3; result_iter++) {
-               if (first_result[result_iter] != second_result[result_iter]) {
-                       total_fail++;
-                       printf("tc_libc_stdlib_srand FAIL : not matched\n");
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("srand", first_result[result_iter], second_result[result_iter]);
        }
 
-       printf("tc_libc_stdlib_srand PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 static void tc_libc_stdlib_atof(void)
 {
        char target[100] = "1234.56abcd";
-       double value = 0;
+       double ret_chk = 0;
 
-       value = atof(target);
-       if (value != 1234.56) {
-               total_fail++;
-               printf("tc_libc_stdlib_atof FAIL\n");
-               RETURN_ERR;
-       }
-       total_pass++;
-       printf("tc_libc_stdlib_atof PASS\n");
+       ret_chk = atof(target);
+       TC_ASSERT_EQ("atof", ret_chk, 1234.56);
+
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index 92820e2..5cee80c 100644 (file)
@@ -55,19 +55,11 @@ static void tc_libc_string_memcpy(void)
        char *res_ptr = NULL;
 
        res_ptr = (char *)memcpy(sz_dest, sz_src, BUFF_SIZE);
-       if (res_ptr == NULL || strncmp(sz_dest, res_ptr, BUFF_SIZE) != OK) {
-               printf("tc_libc_string_memcpy FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("memcpy", res_ptr);
+       TC_ASSERT_EQ("memcpy", strncmp(sz_dest, res_ptr, BUFF_SIZE), 0);
+       TC_ASSERT_EQ("memcpy", strncmp(sz_dest, sz_src, BUFF_SIZE), 0);
 
-       if (strncmp(sz_dest, sz_src, BUFF_SIZE) != OK) {
-               printf("tc_libc_string_memcpy FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_memcpy PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -86,19 +78,11 @@ static void tc_libc_string_memset(void)
        char *res_ptr = NULL;
 
        res_ptr = (char *)memset(buffer, 'a', BUFF_SIZE - 1);
-       if (res_ptr == NULL || strncmp(res_ptr, ctarget, BUFF_SIZE) != OK) {
-               printf("tc_libc_string_memset return ERROR\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("memset", res_ptr);
+       TC_ASSERT_EQ("memset", strncmp(res_ptr, ctarget, BUFF_SIZE), 0);
+       TC_ASSERT_EQ("memset", strncmp(ctarget, buffer, BUFF_SIZE), 0);
 
-       if (strncmp(ctarget, buffer, BUFF_SIZE) != OK) {
-               printf("tc_libc_string_memset compare FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_memset PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -117,18 +101,10 @@ static void tc_libc_string_memchr(void)
        char *res_ptr = NULL;
 
        res_ptr = (char *)memchr(buffer, 's', BUFF_SIZE);
-       if (res_ptr == NULL) {
-               printf("tc_libc_string_memchr FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if ((*res_ptr) != 's') {
-               printf("tc_libc_string_strchr FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_memchr PASS\n");
-       total_pass++;
+       TC_ASSERT_NOT_NULL("memchr", res_ptr);
+       TC_ASSERT_EQ("memchr", *res_ptr, 's');
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -151,25 +127,15 @@ static void tc_libc_string_memcmp(void)
        char buffer4[BUFF_SIZE] = "tesa";
 
        ret_chk = memcmp(buffer1, buffer2, BUFF_SIZE);
-       if (ret_chk != OK) {
-               printf("tc_libc_string_memcmp FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("memcmp", ret_chk, 0);
+
        ret_chk = memcmp(buffer1, buffer3, BUFF_SIZE);
-       if (!(ret_chk < 0)) {
-               printf("tc_libc_string_memcmp FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("memcmp", ret_chk, -1);
+
        ret_chk = memcmp(buffer1, buffer4, BUFF_SIZE);
-       if (!(ret_chk > 0)) {
-               printf("tc_libc_string_memcmp FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_memcmp PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("memcmp", ret_chk, 1);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -188,18 +154,11 @@ static void tc_libc_string_memmove(void)
        char *res_ptr = NULL;
 
        res_ptr = (char *)memmove(buffer1, buffer2, sizeof(buffer1));
-       if (res_ptr == NULL || strncmp(res_ptr, buffer2, BUFF_SIZE) != OK) {
-               printf("tc_libc_string_memmove FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (strncmp(buffer1, buffer2, BUFF_SIZE) != OK) {
-               printf("tc_libc_string_memmove FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_memmove PASS\n");
-       total_pass++;
+       TC_ASSERT_NOT_NULL("memmove", res_ptr);
+       TC_ASSERT_EQ("memmove", strncmp(res_ptr, buffer2, BUFF_SIZE), 0);
+       TC_ASSERT_EQ("memmove", strncmp(buffer1, buffer2, BUFF_SIZE), 0);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -219,19 +178,11 @@ static void tc_libc_string_stpcpy(void)
        char *res_ptr = NULL;
 
        res_ptr = stpcpy(dest_arr, src_buf);
-       if (res_ptr == NULL || *(res_ptr - 1) != 'd') {
-               printf("tc_libc_string_stpcpy FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("stpcpy", res_ptr);
+       TC_ASSERT_EQ("stpcpy", *(res_ptr - 1), 'd');
+       TC_ASSERT_EQ("stpcpy", strncmp(dest_arr, src, BUFF_SIZE), 0);
 
-       if (strncmp(dest_arr, src, BUFF_SIZE) != OK) {
-               printf("tc_libc_string_stpcpy FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_stpcpy PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -252,25 +203,15 @@ static void tc_libc_string_strcasecmp(void)
        char buffer4[BUFF_SIZE] = "tesa";
 
        ret_chk = strcasecmp(buffer1, buffer2);
-       if (ret_chk != OK) {
-               printf("tc_libc_string_strcasecmp FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("strcasecmp", ret_chk, 0);
+
        ret_chk = strcasecmp(buffer1, buffer3);
-       if (!(ret_chk < 0)) {
-               printf("tc_libc_string_strcasecmp FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_LT("strcasecmp", ret_chk, 0);
+
        ret_chk = strcasecmp(buffer1, buffer4);
-       if (!(ret_chk > 0)) {
-               printf("tc_libc_string_strcasecmp FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_strcasecmp PASS\n");
-       total_pass++;
+       TC_ASSERT_GT("strcasecmp", ret_chk, 0);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -290,18 +231,11 @@ static void tc_libc_string_strcat(void)
        char *res_ptr = NULL;
 
        res_ptr = strcat(dest_arr, src);
-       if (res_ptr == NULL || strncmp(res_ptr, final_arr, BUFF_SIZE_10) != 0) {
-               printf("tc_libc_string_strcat FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (strncmp(dest_arr, final_arr, BUFF_SIZE_10) != 0) {
-               printf("tc_libc_string_strcat FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_strcat PASS\n");
-       total_pass++;
+       TC_ASSERT_NOT_NULL("strcat", res_ptr);
+       TC_ASSERT_EQ("strcat", strncmp(res_ptr, final_arr, BUFF_SIZE_10), 0);
+       TC_ASSERT_EQ("strcat", strncmp(dest_arr, final_arr, BUFF_SIZE_10), 0);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -319,24 +253,13 @@ static void tc_libc_string_strchr(void)
        char *res_ptr = NULL;
 
        res_ptr = strchr(dest_arr, 'z');
-       if (res_ptr != NULL) {
-               printf("tc_libc_string_strchr FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("strchr", res_ptr, NULL);
+
        res_ptr = strchr(dest_arr, 's');
-       if (res_ptr == NULL) {
-               printf("tc_libc_string_strchr FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if ((*res_ptr) != 's') {
-               printf("tc_libc_string_strchr FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_strchr PASS\n");
-       total_pass++;
+       TC_ASSERT_NOT_NULL("strchr", res_ptr);
+       TC_ASSERT_EQ("strchr", *res_ptr, 's');
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -358,25 +281,15 @@ static void tc_libc_string_strcmp(void)
        char buffer4[BUFF_SIZE] = "tesa";
 
        ret_chk = strcmp(buffer1, buffer2);
-       if (ret_chk != OK) {
-               printf("tc_libc_string_strcmp FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("strcmp", ret_chk, 0);
+
        ret_chk = strcmp(buffer1, buffer3);
-       if (!(ret_chk < 0)) {
-               printf("tc_libc_string_strcmp FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_LT("strcmp", ret_chk, 0);
+
        ret_chk = strcmp(buffer1, buffer4);
-       if (!(ret_chk > 0)) {
-               printf("tc_libc_string_strcmp FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_strcmp PASS\n");
-       total_pass++;
+       TC_ASSERT_GT("strcmp", ret_chk, 0);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -395,18 +308,11 @@ static void tc_libc_string_strcpy(void)
        char *res_ptr = NULL;
 
        res_ptr = strcpy(dest_arr, src);
-       if (res_ptr == NULL || strncmp(res_ptr, src, BUFF_SIZE) != 0) {
-               printf("tc_libc_string_strcpy FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (strncmp(dest_arr, src, BUFF_SIZE) != 0) {
-               printf("tc_libc_string_strcpy FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_strcpy PASS\n");
-       total_pass++;
+       TC_ASSERT_NOT_NULL("strcpy", res_ptr);
+       TC_ASSERT_EQ("strcpy", strncmp(res_ptr, src, BUFF_SIZE), 0);
+       TC_ASSERT_EQ("strcpy", strncmp(dest_arr, src, BUFF_SIZE), 0);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -427,21 +333,16 @@ static void tc_libc_string_strcspn(void)
        int ret_chk = 0, pos_a = 3, lenDest = 4;
        /* "tesa" has "a" which is the only character that is in "abcd", strcspn will return characters read
           in "tesa" before reaching "a", so return value will be 3 in this case */
+
        ret_chk = strcspn(dest_arr, src1);
-       if (ret_chk != pos_a) {
-               printf("tc_libc_string_strcspn FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("strcspn", ret_chk, pos_a);
+
        /* src2 has no charater that matches with any character of dest_arr */
+
        ret_chk = strcspn(dest_arr, src2);
-       if (ret_chk != lenDest) {
-               printf("tc_libc_string_strcspn FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_strcspn PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("strcspn", ret_chk, lenDest);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -461,20 +362,14 @@ static void tc_libc_string_strdup(void)
        char src[BUFF_SIZE] = "test";
 
        dest_arr = strdup(src);
-       if (dest_arr == NULL) {
-               printf("tc_libc_string_strdup FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (strncmp(dest_arr, src, BUFF_SIZE) != OK) {
-               free(dest_arr);
-               printf("tc_libc_string_strdup FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       free(dest_arr);
-       printf("tc_libc_string_strdup PASS\n");
-       total_pass++;
+       TC_ASSERT_NOT_NULL("strdup", dest_arr);
+       TC_ASSERT_EQ_CLEANUP("strdup",
+                                                strncmp(dest_arr, src, BUFF_SIZE), OK,
+                                                get_errno(),
+                                                TC_FREE_MEMORY(dest_arr));
+
+       TC_FREE_MEMORY(dest_arr);
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -494,18 +389,10 @@ static void tc_libc_string_strerror(void)
 
        /* EFAULT is defined as 14 which gives Bad address in strerror */
        dest_arr = (char *)strerror(EFAULT);
-       if (dest_arr == NULL) {
-               printf("tc_libc_string_strerror NULL FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (strncmp(dest_arr, src, BUFF_SIZE_12) != 0) {
-               printf("tc_libc_string_strerror CMP FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_strerror PASS\n");
-       total_pass++;
+       TC_ASSERT_NOT_NULL("strerror", dest_arr);
+       TC_ASSERT_EQ("strerror", strncmp(dest_arr, src, BUFF_SIZE_12), 0);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -523,13 +410,9 @@ static void tc_libc_string_strlen(void)
        int ret_chk = ERROR;
 
        ret_chk = strlen(src);
-       if (ret_chk != BUFF_SIZE - 1) {
-               printf("tc_libc_string_strlen FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_strlen PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("strlen", ret_chk, BUFF_SIZE - 1);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -550,25 +433,15 @@ static void tc_libc_string_strncasecmp(void)
        char buffer4[BUFF_SIZE] = "tesa";
 
        ret_chk = strncasecmp(buffer1, buffer2, BUFF_SIZE);
-       if (ret_chk != OK) {
-               printf("tc_libc_string_strncasecmp FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("strncasecmp", ret_chk, 0);
+
        ret_chk = strncasecmp(buffer1, buffer3, BUFF_SIZE);
-       if (!(ret_chk < 0)) {
-               printf("tc_libc_string_strncasecmp FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_LT("strncasecmp", ret_chk, 0);
+
        ret_chk = strncasecmp(buffer1, buffer4, BUFF_SIZE);
-       if (!(ret_chk > 0)) {
-               printf("tc_libc_string_strncasecmp FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_strncasecmp PASS\n");
-       total_pass++;
+       TC_ASSERT_GT("strncasecmp", ret_chk, 0);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -590,19 +463,11 @@ static void tc_libc_string_strncat(void)
        char *res_ptr = NULL;
 
        res_ptr = strncat(dest_arr, src, BUFF_SIZE);
-       if (res_ptr == NULL || strncmp(res_ptr, final_arr, BUFF_SIZE_10) != OK) {
-               printf("tc_libc_string_strncat FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("strncat", res_ptr);
+       TC_ASSERT_EQ("strncat", strncmp(res_ptr, final_arr, BUFF_SIZE_10), 0);
+       TC_ASSERT_EQ("strncat", strncmp(dest_arr, final_arr, BUFF_SIZE_10), 0);
 
-       if (strncmp(dest_arr, final_arr, BUFF_SIZE_10) != OK) {
-               printf("tc_libc_string_strncat FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_strncat PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -623,25 +488,15 @@ static void tc_libc_string_strncmp(void)
        char buffer4[BUFF_SIZE] = "tesa";
 
        ret_chk = strncmp(buffer1, buffer2, BUFF_SIZE);
-       if (ret_chk != OK) {
-               printf("tc_libc_string_strncmp FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("strncmp", ret_chk, 0);
+
        ret_chk = strncmp(buffer1, buffer3, BUFF_SIZE);
-       if (!(ret_chk < 0)) {
-               printf("tc_libc_string_strncmp FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_LT("strncmp", ret_chk, 0);
+
        ret_chk = strncmp(buffer1, buffer4, BUFF_SIZE);
-       if (!(ret_chk > 0)) {
-               printf("tc_libc_string_strncmp FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_strncmp PASS\n");
-       total_pass++;
+       TC_ASSERT_GT("strncmp", ret_chk, 0);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -660,18 +515,11 @@ static void tc_libc_string_strncpy(void)
        char *res_ptr = NULL;
 
        res_ptr = strncpy(dest_arr, src, BUFF_SIZE);
-       if (res_ptr == NULL || strncmp(res_ptr, src, BUFF_SIZE) != OK) {
-               printf("tc_libc_string_strncpy FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (strncmp(dest_arr, src, BUFF_SIZE) != OK) {
-               printf("tc_libc_string_strncpy FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_strncpy PASS\n");
-       total_pass++;
+       TC_ASSERT_NOT_NULL("strncpy", res_ptr);
+       TC_ASSERT_EQ("strncpy", strncmp(res_ptr, src, BUFF_SIZE), 0);
+       TC_ASSERT_EQ("strncpy", strncmp(dest_arr, src, BUFF_SIZE), 0);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -691,20 +539,14 @@ static void tc_libc_string_strndup(void)
        char src[BUFF_SIZE] = "test";
 
        dest_arr = strndup(src, BUFF_SIZE);
-       if (dest_arr == NULL) {
-               printf("tc_libc_string_strndup FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (strncmp(dest_arr, src, BUFF_SIZE) != OK) {
-               free(dest_arr);
-               printf("tc_libc_string_strndup FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       free(dest_arr);
-       printf("tc_libc_string_strndup PASS\n");
-       total_pass++;
+       TC_ASSERT_NOT_NULL("strndup", dest_arr);
+       TC_ASSERT_EQ_CLEANUP("strndup",
+                                                strncmp(dest_arr, src, BUFF_SIZE), 0,
+                                                get_errno(),
+                                                TC_FREE_MEMORY(dest_arr));
+
+       TC_FREE_MEMORY(dest_arr);
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -725,19 +567,12 @@ static void tc_libc_string_strnlen(void)
        int ret_chk = 0;
 
        ret_chk = strnlen(src1, BUFF_SIZE);
-       if (ret_chk != BUFF_SIZE - 1) {
-               printf("tc_libc_string_strnlen FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("strnlen", ret_chk, BUFF_SIZE - 1);
+
        ret_chk = strnlen(src2, BUFF_SIZE);
-       if (ret_chk != BUFF_SIZE) {
-               printf("tc_libc_string_strnlen FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_strnlen PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("strnlen", ret_chk, BUFF_SIZE);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -760,24 +595,14 @@ static void tc_libc_string_strpbrk(void)
        char *res_ptrstr = "mple";
 
        res_ptr = strpbrk(dest_arr, cbuf);
-       if (res_ptr == NULL || strncmp(res_ptr, res_ptrstr, BUFF_SIZE_10) != OK) {
-               printf("tc_libc_string_strpbrk FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if ((*res_ptr) != 'm') {
-               printf("tc_libc_string_strpbrk FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("strpbrk", res_ptr);
+       TC_ASSERT_EQ("strpbrk", strncmp(res_ptr, res_ptrstr, BUFF_SIZE_10), 0);
+       TC_ASSERT_EQ("strpbrk", *res_ptr, 'm');
+
        res_ptr = strpbrk(dest_arr, cStr);
-       if (res_ptr != NULL) {
-               printf("tc_libc_string_strpbrk FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_strpbrk PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("strpbrk", res_ptr, NULL);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -797,23 +622,11 @@ static void tc_libc_string_strrchr(void)
        char *res_ptrstr = "es";
 
        res_ptr = strrchr(dest_arr, 'e');
-       if (res_ptr == NULL) {
-               printf("tc_libc_string_strrchr FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (res_ptr == NULL || strncmp(res_ptr, res_ptrstr, BUFF_SIZE) != OK) {
-               printf("tc_libc_string_strrchr FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if ((*res_ptr) != 'e') {
-               printf("tc_libc_string_strrchr FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_strrchr PASS\n");
-       total_pass++;
+       TC_ASSERT_NOT_NULL("strrchr", res_ptr);
+       TC_ASSERT_EQ("strrchr", strncmp(res_ptr, res_ptrstr, BUFF_SIZE), 0);
+       TC_ASSERT_EQ("strrchr", *res_ptr, 'e');
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -837,27 +650,15 @@ static void tc_libc_string_strspn(void)
        char *cbuf = "me";
 
        ret_chk = strspn(cbuf, dest_arr1);
-       if (ret_chk != 2) {
-               printf("tc_libc_string_strspn FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("strspn", ret_chk, 2);
 
        ret_chk = strspn(cbuf, dest_arr2);
-       if (ret_chk != OK) {
-               printf("tc_libc_string_strspn FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("strspn", ret_chk, 0);
 
        ret_chk = strspn(cbuf, dest_arr3);
-       if (ret_chk != 1) {
-               printf("tc_libc_string_strspn FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_string_strspn PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("strspn", ret_chk, 1);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -877,14 +678,10 @@ static void tc_libc_string_strstr(void)
        char *psz = "str";
 
        res_ptr = strstr(dest_arr, psz);
-       if (res_ptr == NULL || strncmp(res_ptr, dest_arr, BUFF_SIZE_10) != OK) {
-               printf("tc_libc_string_strstr FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("strstr", res_ptr);
+       TC_ASSERT_EQ("strspn", strncmp(res_ptr, dest_arr, BUFF_SIZE_10), 0);
 
-       printf("tc_libc_string_strstr PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -906,23 +703,15 @@ static void tc_libc_string_strtok(void)
        int arr_idx = 0;
        char *res_ptr = NULL;
        res_ptr = strtok(szbuffer, " ");
-       if (res_ptr == NULL) {
-               printf("tc_libc_string_strtok FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("strtok", res_ptr);
 
        while (res_ptr != NULL) {
-               if (strncmp(res_ptr, dest_arr[arr_idx], BUFF_SIZE_10) != OK) {
-                       printf("tc_libc_string_strtok FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("strtok", strncmp(res_ptr, dest_arr[arr_idx], BUFF_SIZE_10), 0);
                arr_idx++;
                res_ptr = strtok(NULL, " ");
        }
-       printf("tc_libc_string_strtok PASS\n");
-       total_pass++;
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -947,28 +736,17 @@ static void tc_libc_string_strtok_r(void)
        char *psz_save;
 
        res_ptr = strtok_r(cbuf, " ", &psz_save);
-       if (res_ptr == NULL || psz_save == NULL) {
-               printf("tc_libc_string_strtok_r FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("strtok_r", res_ptr);
+       TC_ASSERT_NOT_NULL("strtok_r", psz_save);
 
        while (res_ptr != NULL) {
-               if (strncmp(res_ptr, dest_arr[arr_idx], BUFF_SIZE_10) != OK) {
-                       printf("tc_libc_string_strtok_r FAIL,dest_arr and res_ptr didnot match \n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
-               if (strncmp(psz_save, psz_save_dest[arr_idx], BUFF_SIZE_10) != OK) {
-                       printf("tc_libc_string_strtok_r FAIL, psz_save_dest and psz_save didnot match\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("strtok_r", strncmp(res_ptr, dest_arr[arr_idx], BUFF_SIZE_10), 0);
+               TC_ASSERT_EQ("strtok_r", strncmp(psz_save, psz_save_dest[arr_idx], BUFF_SIZE_10), 0);
                arr_idx++;
                res_ptr = strtok_r(NULL, " ", &psz_save);
        }
-       printf("tc_libc_string_strtok_r PASS\n");
-       total_pass++;
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -990,14 +768,10 @@ static void tc_libc_string_strcasestr(void)
        char *psz = "str";
 
        res_ptr = strcasestr(dest_arr, psz);
-       if (res_ptr == NULL || strncmp(res_ptr, dest_arr, BUFF_SIZE_10) != OK) {
-               printf("tc_libc_string_strcasestr FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("strcasestr", res_ptr);
+       TC_ASSERT_EQ("strcasestr", strncmp(res_ptr, dest_arr, BUFF_SIZE_10), 0);
 
-       printf("tc_libc_string_strcasestr PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 static void tc_libc_string_memccpy(void)
@@ -1005,24 +779,15 @@ static void tc_libc_string_memccpy(void)
        char *test1_src = "abcdefghijkl";
        char some_str[50];
        char test_result[50] = "abcdefg";
-       char *ptr;
+       char *res_ptr;
 
        memset(some_str, 0, sizeof(some_str));
 
-       ptr = (char *)memccpy(some_str, test1_src, 'g', strlen(test1_src));
-       if (!ptr) {
-               printf("tc_libc_string_memccpy FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (strcmp(some_str, test_result) != 0) {
-               printf("tc_libc_string_memccpy FAIL : not matched %s\n", some_str);
-               total_fail++;
-               RETURN_ERR;
-       }
+       res_ptr = (char *)memccpy(some_str, test1_src, 'g', strlen(test1_src));
+       TC_ASSERT_NOT_NULL("memccpy", res_ptr);
+       TC_ASSERT_EQ("memccpy", strcmp(some_str, test_result), 0);
 
-       total_pass++;
-       printf("tc_libc_string_memccpy PASS\n");
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -1041,30 +806,16 @@ static void tc_libc_string_strlcpy(void)
        char str_dest[BUFF_SIZE_10] = "abcdefghi";
        char str_src[BUFF_SIZE_10] = "jklmnopqr";
 
-       cpy_len = strlcpy(str_dest, str_src, BUFF_SIZE_10 / 2);
-       /* check that the return val is the total length of src */
-       if (cpy_len != strlen(str_src)) {
-               printf("tc_libc_string_strlcpy FAIL : not matched the length\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       /* check that NUL-terminating */
-       if (str_dest[(BUFF_SIZE_10 / 2) - 1] != '\0') {
-               printf("tc_libc_string_strlcpy FAIL : not NUL-terminated\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       /* 1. check that the return val is the total length of src
+        * 2. check that NUL-terminating
+        * 3. check that copied string is correct */
 
-       /* check that copied string is correct */
-       if (strncmp(str_dest, str_src, (BUFF_SIZE_10 / 2) - 1) != 0) {
-               printf("tc_libc_string_strlcpy FAIL : not copied well\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       cpy_len = strlcpy(str_dest, str_src, BUFF_SIZE_10 / 2);
+       TC_ASSERT_EQ("strlcpy", cpy_len, strlen(str_src));
+       TC_ASSERT_EQ("strlcpy", str_dest[(BUFF_SIZE_10 / 2) - 1], '\0');
+       TC_ASSERT_EQ("strlcpy", strncmp(str_dest, str_src, (BUFF_SIZE_10 / 2) - 1), 0);
 
-       printf("tc_libc_string_strlcpy PASS \n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index dd8e5b2..d3192e9 100644 (file)
@@ -20,6 +20,7 @@
 
 /// @brief Test Case Example for Syslog API
 #include <tinyara/config.h>
+#include <unistd.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
@@ -29,6 +30,7 @@
 
 #define PRIORITY_NUM 8
 #define MAX_SYSLOG_MSG 32
+#define USEC_100 100
 
 int g_prioidx[PRIORITY_NUM] = { LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG };
 const char *g_priostr[PRIORITY_NUM] = { "Emergency", "Alert", "Critical", "Error", "Warning", "Notice", "Information", "Debug" };
@@ -49,31 +51,25 @@ static void tc_libc_syslog_setlogmask(void)
        int oldmask, newmask, mask_chk;
        setlogmask(LOG_ALL);
 
-       //The initial value of logmask is LOG_ALL, 0xff
+       /* The initial value of logmask is LOG_ALL, 0xff */
+
        oldmask = LOG_ALL;
        newmask = LOG_MASK(LOG_WARNING);
        mask_chk = -1;
 
-       //It sets the logmask and returns the previous mask.
+       /* It sets the logmask and returns the previous mask. */
+
        mask_chk = setlogmask(newmask);
-       if (oldmask != mask_chk) {
-               printf("tc_syslog_setlogmask FAIL, %d, %d\n", oldmask, mask_chk);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("setlogmask", oldmask, mask_chk);
 
        oldmask = newmask;
        newmask = LOG_UPTO(LOG_INFO);
 
        mask_chk = setlogmask(newmask);
-       if (oldmask != mask_chk) {
-               printf("tc_syslog_setlogmask FAIL, %d, %d\n", oldmask, mask_chk);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("setlogmask", oldmask, mask_chk);
        setlogmask(LOG_ALL);
-       printf("tc_libc_syslog_setlogmask PASS\n");
-       total_pass++;
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -87,21 +83,17 @@ static void tc_libc_syslog_setlogmask(void)
  */
 static void tc_libc_syslog_syslog(void)
 {
+       int ret_chk;
        int i;
-       int ret;
 
        for (i = 0; i < PRIORITY_NUM; i++) {
                sprintf(g_syslogmsg, "%s message\n", g_priostr[i]);
-               ret = syslog(g_prioidx[i], g_syslogmsg);
-               if (ret != strlen(g_syslogmsg)) {
-                       printf("tc_libc_syslog_syslog FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               usleep(USEC_100);
+               ret_chk = syslog(g_prioidx[i], g_syslogmsg);
+               TC_ASSERT_EQ("syslog", ret_chk, strlen(g_syslogmsg));
        }
 
-       printf("tc_libc_syslog_syslog PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -132,20 +124,17 @@ static int vsyslogFunc(int priority, FAR const char *msg, ...)
  */
 static void tc_libc_syslog_vsyslog(void)
 {
+       int ret_chk;
        int i;
-       int ret;
 
        for (i = 0; i < PRIORITY_NUM; i++) {
                sprintf(g_syslogmsg, "%s message\n", g_priostr[i]);
-               ret = vsyslogFunc(g_prioidx[i], g_syslogmsg);
-               if (ret != strlen(g_syslogmsg)) {
-                       printf("tc_libc_syslog_vsyslog FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               usleep(USEC_100);
+               ret_chk = vsyslogFunc(g_prioidx[i], g_syslogmsg);
+               TC_ASSERT_EQ("vsyslog", ret_chk, strlen(g_syslogmsg));
        }
-       printf("tc_libc_syslog_vsyslog PASS\n");
-       total_pass++;
+
+       TC_SUCCESS_RESULT();
 }
 
 #if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_SYSLOG)
@@ -160,20 +149,17 @@ static void tc_libc_syslog_vsyslog(void)
  */
 static void tc_libc_syslog_lowsyslog(void)
 {
+       int ret_chk;
        int i;
-       int ret;
 
        for (i = 0; i < PRIORITY_NUM; i++) {
                sprintf(g_syslogmsg, "%s message\n", g_priostr[i]);
-               ret = lowsyslog(g_prioidx[i], g_syslogmsg);
-               if (ret != strlen(g_syslogmsg)) {
-                       printf("tc_libc_syslog_lowsyslog FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               usleep(USEC_100);
+               ret_chk = lowsyslog(g_prioidx[i], g_syslogmsg);
+               TC_ASSERT_EQ("lowsyslog", ret_chk, strlen(g_syslogmsg));
        }
-       printf("tc_libc_syslog_lowsyslog PASS\n");
-       total_pass++;
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -204,20 +190,17 @@ static int lowvsyslogFunc(int priority, FAR const char *msg, ...)
  */
 static void tc_libc_syslog_lowvsyslog(void)
 {
+       int ret_chk;
        int i;
-       int ret;
 
        for (i = 0; i < PRIORITY_NUM; i++) {
                sprintf(g_syslogmsg, "%s message\n", g_priostr[i]);
-               ret = lowvsyslogFunc(g_prioidx[i], g_syslogmsg);
-               if (ret != strlen(g_syslogmsg)) {
-                       printf("tc_libc_syslog_lowvsyslog FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               usleep(USEC_100);
+               ret_chk = lowvsyslogFunc(g_prioidx[i], g_syslogmsg);
+               TC_ASSERT_EQ("lowvsyslog", ret_chk, strlen(g_syslogmsg));
        }
-       printf("tc_libc_syslog_lowvsyslog PASS\n");
-       total_pass++;
+
+       TC_SUCCESS_RESULT();
 }
 
 #endif
index 9299385..69704aa 100644 (file)
@@ -69,14 +69,12 @@ static void tc_libc_timer_clock_calendar2utc(void)
 
        time1 = clock_calendar2utc(year, month, day1);
        time2 = clock_calendar2utc(year, month, day2);
+
        /* difference in time values should equal to exact number of seconds in 1 day */
-       if ((time2 - time1) != 1) {
-               printf("tc_libc_timer_clock_calendar2utc FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_timer_clock_calendar2utc PASS\n");
-       total_pass++;
+
+       TC_ASSERT_EQ("clock_calendar2utc", time2 - time1, 1);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -98,29 +96,23 @@ static void tc_libc_timer_gmtime_r(void)
        struct tm *st_localtime;
 
        time(&test_time);
+
        /* calculate current date */
+
        st_localtime = localtime(&test_time);
        today = st_localtime->tm_mday;
        year = st_localtime->tm_year;
-       st_rettime = gmtime_r(&test_time, &st_time);
-       if (st_rettime == NULL) {
-               printf("tc_libc_timer_gmtime_r FAIL, st_rettime is null\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+
        /* verifying the structures returned and filled by comparing their parameters */
-       if (st_rettime->tm_year != st_time.tm_year || st_rettime->tm_mon != st_time.tm_mon) {
-               printf("tc_libc_timer_gmtime_r FAIL, st_rettime and st_time mismatch \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (year != st_time.tm_year || today != st_time.tm_mday) {
-               printf("tc_libc_timer_gmtime_r FAIL, year and day mismatch \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_timer_gmtime_r PASS\n");
-       total_pass++;
+
+       st_rettime = gmtime_r(&test_time, &st_time);
+       TC_ASSERT_NOT_NULL("gmtime_r", st_rettime);
+       TC_ASSERT_EQ("gmtime_r", st_rettime->tm_year, st_time.tm_year);
+       TC_ASSERT_EQ("gmtime_r", st_rettime->tm_mon, st_time.tm_mon);
+       TC_ASSERT_EQ("gmtime_r", year, st_time.tm_year);
+       TC_ASSERT_EQ("gmtime_r", today, st_time.tm_mday);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -139,59 +131,35 @@ static void tc_libc_timer_gmtime(void)
        struct tm *st_localtime = NULL;
        time_t time1;
        time_t time2;
+
        ret_chk = time(&time1);
-       if (ret_chk == (time_t)ERROR) {
-               printf("tc_libc_timer_gmtime FAIL, time(&time1) is error\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("time", ret_chk, (time_t)ERROR);
 
        st_rettime = gmtime(&time1);
-       if (st_rettime == NULL) {
-               printf("tc_libc_timer_gmtime FAIL, st_rettime for time1 is null\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("gmtime", st_rettime);
+
        st_localtime = localtime(&time1);
-       if (st_localtime == NULL) {
-               printf("tc_libc_timer_localtime FAIL, st_localtime should point to tm structure \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (st_rettime->tm_year != st_localtime->tm_year || st_rettime->tm_mon != st_localtime->tm_mon) {
-               printf("tc_libc_timer_gmtime FAIL, localtime and gmtime mismatch \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("localtime", st_localtime);
+       TC_ASSERT_EQ("localtime", st_rettime->tm_year, st_localtime->tm_year);
+       TC_ASSERT_EQ("localtime", st_rettime->tm_mon, st_localtime->tm_mon);
+
        sleep(SEC_5);
 
        ret_chk = time(&time2);
-       if (ret_chk == (time_t)ERROR) {
-               printf("tc_libc_timer_gmtime FAIL, time(&time2) is error\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("time", ret_chk, (time_t)ERROR);
+
+       /* verifying the returned structure's parameter, year should not be negative, month range is 0-11 */
+
        st_rettime = gmtime(&time2);
-       if (st_rettime == NULL) {
-               printf("tc_libc_timer_gmtime FAIL, st_rettime for time2 is null\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("gmtime", st_rettime);
+       TC_ASSERT_GEQ("gtime", st_rettime->tm_year, 0);
+       TC_ASSERT_GEQ("gtime", st_rettime->tm_mon, 0);
+       TC_ASSERT_LT("gtime", st_rettime->tm_mon, 12);
 
        ret_chk = (long long int)(time2) - (long long int)(time1);
-       /* verifying the returned structure's parameter, year should not be negative, month range is 0-11 */
-       if (st_rettime->tm_year <= 0 || st_rettime->tm_mon < 0 || st_rettime->tm_mon > 11) {
-               printf("tc_libc_timer_gmtime FAIL, st_rettime and st_time mismatch \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (ret_chk < SEC_5) {
-               printf("tc_libc_timer_gmtime FAIL, gmtime not getting correct time \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_timer_gmtime PASS\n");
-       total_pass++;
+       TC_ASSERT_GEQ("gtime", ret_chk, SEC_5);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -207,25 +175,20 @@ static void tc_libc_timer_clock_isleapyear(void)
 {
        int ret_chk = ERROR;
        int year;
-       year = ISLEAPYEAR;
+
        /* Entered year is a leap year */
+
+       year = ISLEAPYEAR;
        ret_chk = clock_isleapyear(year);
-       if (ret_chk != 1) {
-               printf("tc_libc_timer_clock_isleapyear FAIL, should return a leap year \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("clock_isleapyear", ret_chk, 1);
 
-       year = ISNOTLEAPYEAR;
        /*Entered year is not a leap year */
+
+       year = ISNOTLEAPYEAR;
        ret_chk = clock_isleapyear(year);
-       if (ret_chk != OK) {
-               printf("tc_libc_timer_clock_isleapyear FAIL, should not return a leap year \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_timer_clock_isleapyear PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("clock_isleapyear", ret_chk, 0);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -244,29 +207,18 @@ static void tc_libc_timer_localtime(void)
 {
        time_t test_time;
        struct tm *st_rettime = NULL;
-       time(&test_time);
-
        struct tm *st_gmtime = NULL;
+
+       time(&test_time);
        st_gmtime = gmtime(&test_time);
-       if (st_gmtime == NULL) {
-               printf("tc_libc_timer_gmtime FAIL, st_rettime for time1 is null\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("gmtime", st_gmtime);
+
        st_rettime = localtime(&test_time);
-       if (st_rettime == NULL) {
-               printf("tc_libc_timer_localtime FAIL, st_rettime should point to tm structure \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (st_rettime->tm_year != st_gmtime->tm_year || st_rettime->tm_mon != st_gmtime->tm_mon) {
-               printf("tc_libc_timer_localtime FAIL, localtime and gmtime mismatch \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("localtime", st_gmtime);
+       TC_ASSERT_EQ("localtime", st_rettime->tm_year, st_gmtime->tm_year);
+       TC_ASSERT_EQ("localtime", st_rettime->tm_mon, st_gmtime->tm_mon);
 
-       printf("tc_libc_timer_localtime PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -290,27 +242,20 @@ static void tc_libc_timer_localtime_r(void)
 
        test_time = time(&test_time);
 
-       gmtime_r(&test_time, &st_gettime);      /* get time through gmtime_r */
-       st_rettime = localtime_r(&test_time, &st_time);
-       if (st_rettime == NULL) {
-               printf("tc_libc_timer_localtime_r FAIL, st_rettime should point to tm structure \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       /* get time through gmtime_r */
+
+       gmtime_r(&test_time, &st_gettime);
+
        /* verifying the structures "returned and filled" by comparing their parameters */
-       if (st_rettime->tm_year != st_time.tm_year || st_rettime->tm_mon != st_time.tm_mon) {
-               printf("tc_libc_timer_localtime_r FAIL, st_rettime and st_time mismatch \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (st_gettime.tm_year != st_time.tm_year || st_gettime.tm_mon != st_time.tm_mon) {
-               printf("tc_libc_timer_localtime_r FAIL, st_rettime and st_gettime mismatch \n");
-               total_fail++;
-               RETURN_ERR;
-       }
 
-       printf("tc_libc_timer_localtime_r PASS\n");
-       total_pass++;
+       st_rettime = localtime_r(&test_time, &st_time);
+       TC_ASSERT_NOT_NULL("localtime_r", st_rettime);
+       TC_ASSERT_EQ("localtime_r", st_rettime->tm_year, st_time.tm_year);
+       TC_ASSERT_EQ("localtime_r", st_rettime->tm_mon, st_time.tm_mon);
+       TC_ASSERT_EQ("localtime_r", st_gettime.tm_year, st_time.tm_year);
+       TC_ASSERT_EQ("localtime_r", st_gettime.tm_mon, st_time.tm_mon);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -331,26 +276,20 @@ static void tc_libc_timer_mktime(void)
        int after5days;
        struct tm *st_time;
        time_t test_time;
+
        time(&test_time);
        /* calculate current date */
        st_time = localtime(&test_time);
        today = st_time->tm_mday;
-       st_time->tm_mday = st_time->tm_mday + SEC_5;
+       st_time->tm_mday = st_time->tm_mday + 5;
 
        ret_chk = mktime(st_time);
+       TC_ASSERT_NEQ("mktime", ret_chk, ERROR);
+
        after5days = st_time->tm_mday;
-       if (ret_chk == ERROR) {
-               printf("tc_libc_timer_mktime FAIL, mktime API fails, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (today + SEC_5 != after5days) {
-               printf("tc_libc_timer_mktime FAIL, fails to update struct tm st_time, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_timer_mktime PASS \n");
-       total_pass++;
+       TC_ASSERT_EQ("mktime", today + 5, after5days);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -372,24 +311,19 @@ static void tc_libc_timer_strftime(void)
        time(&test_time);
        st_time = localtime(&test_time);
 
-       /* Verifying year and month filled in time structure */
+       /* Verifying year and month filled in time structure.
+        * time structure has month in range 0-11,
+        * so tm_mon + 1 represents actual month number */
+
        strftime(buffer, BUFF_SIZE, "%m", st_time);
-       /* time structure has month in range 0-11, so tm_mon + 1 represents actual month number */
-       if (atoi(buffer) != (st_time->tm_mon + 1)) {
-               printf("tc_libc_timer_strftime FAIL, month val mismatch \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       strftime(buffer, BUFF_SIZE, "%Y", st_time);
+       TC_ASSERT_EQ("strftime", atoi(buffer), st_time->tm_mon + 1);
+
        /* st_time->tm_year represents year relative to YEAR_BASE */
-       if (atoi(buffer) != (st_time->tm_year + YEAR_BASE)) {
-               printf("tc_libc_timer_strftime FAIL, year val mismatch \n");
-               total_fail++;
-               RETURN_ERR;
-       }
 
-       printf("tc_libc_timer_strftime PASS\n");
-       total_pass++;
+       strftime(buffer, BUFF_SIZE, "%Y", st_time);
+       TC_ASSERT_EQ("strftime", atoi(buffer), st_time->tm_year + YEAR_BASE);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -410,21 +344,16 @@ static void tc_libc_timer_time(void)
        struct tm st_gmtime;
 
        ret_time = time(&get_time);
-       gmtime_r(&get_time, &st_gmtime);        /* get time through gmtime_r */
-       localtime_r(&get_time, &st_localtime);  /* get time through localtime_r */
+       TC_ASSERT_NEQ("time", ret_time, (time_t)ERROR);
 
-       if (ret_time <= 0) {
-               printf("tc_libc_timer_time FAIL, ret_time value is negative, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (st_gmtime.tm_year != st_localtime.tm_year || st_gmtime.tm_mon != st_localtime.tm_mon) {
-               printf("tc_libc_timer_time FAIL, st_localtime and st_gmtime mismatch \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_timer_time PASS \n");
-       total_pass++;
+       /* get time through gmtime_r, localtime_r */
+
+       gmtime_r(&get_time, &st_gmtime);
+       localtime_r(&get_time, &st_localtime);
+       TC_ASSERT_EQ("time", st_gmtime.tm_year, st_localtime.tm_year);
+       TC_ASSERT_EQ("time", st_gmtime.tm_mon, st_localtime.tm_mon);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -445,29 +374,22 @@ static void tc_libc_timer_clock_daysbeforemonth(void)
        int notleapyear_days[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
 
        /* test with not leapyear */
+
        for (month_iter = 1; month_iter < 12; month_iter++) {
                prev_month = clock_daysbeforemonth(month_iter, FALSE);
                cur_month = clock_daysbeforemonth(month_iter+1, FALSE);
-               if (cur_month-prev_month != notleapyear_days[month_iter]) {
-                       printf("tc_libc_timer_clock_daysbeforemonth FAIL : not matched \n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("clock_daysbeforemonth", cur_month-prev_month, notleapyear_days[month_iter]);
        }
 
        /* test with leapyear */
+
        for (month_iter = 1; month_iter < 12; month_iter++) {
                prev_month = clock_daysbeforemonth(month_iter, TRUE);
                cur_month = clock_daysbeforemonth(month_iter+1, TRUE);
-               if (cur_month-prev_month != leapyear_days[month_iter]) {
-                       printf("!tc_libc_timer_clock_daysbeforemonth FAIL : not matched \n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("clock_daysbeforemonth", cur_month-prev_month, leapyear_days[month_iter]);
        }
 
-       printf("tc_libc_timer_clock_daysbeforemonth PASS \n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index 258607b..3351219 100644 (file)
@@ -85,19 +85,12 @@ static void tc_libc_unistd_chdir_getcwd(void)
        int ret_chk;
 
        ret_chk = chdir(directory);
-       if (ret_chk != OK) {
-               printf("tc_libc_unistd_chdir_getcwd FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("chdir", ret_chk, OK);
+
        cwd = getcwd(buff, BUFFSIZE);
-       if (strcmp(directory, cwd) != OK) {
-               printf("tc_libc_unistd_chdir_getcwd FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_unistd_chdir_getcwd PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("getcwd", strcmp(directory, cwd), 0);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -130,13 +123,10 @@ static void tc_libc_unistd_getopt(void)
                default:
                        break;
                }
-       if (flag_a != 1 || flag_b != 1) {
-               printf("tc_libc_unistd_getopt FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_unistd_getopt PASS \n");
-       total_pass++;
+       TC_ASSERT_EQ("getopt", flag_a, 1);
+       TC_ASSERT_EQ("getopt", flag_b, 1);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -158,19 +148,12 @@ static void tc_libc_unistd_sleep(void)
        clock_gettime(CLOCK_REALTIME, &st_init_time);
 
        ret_chk = sleep(SEC_3);
-       if (ret_chk != OK) {
-               printf("tc_libc_unistd_sleep FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sleep", ret_chk, 0);
+
        clock_gettime(CLOCK_REALTIME, &st_final_time);
-       if ((st_final_time.tv_sec - st_init_time.tv_sec) != SEC_3) {
-               printf("tc_libc_unistd_sleep FAIL st_final_time: %lld, st_init_time: %lld \n", st_final_time.tv_sec, st_init_time.tv_sec);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_unistd_sleep PASS \n");
-       total_pass++;
+       TC_ASSERT_EQ("sleep", st_final_time.tv_sec - st_init_time.tv_sec, SEC_3);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -190,19 +173,12 @@ static void tc_libc_unistd_usleep(void)
 
        clock_gettime(CLOCK_REALTIME, &st_init_time);
        ret_chk = usleep(USLEEP_INTERVAL);
-       if (ret_chk != OK) {
-               printf("tc_libc_unistd_chdir FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("usleep", ret_chk, 0);
+
        clock_gettime(CLOCK_REALTIME, &st_final_time);
-       if ((st_final_time.tv_sec - st_init_time.tv_sec) != SEC_3) {
-               printf("tc_libc_unistd_usleep FAIL, st_final_time: %lld, st_init_time: %lld \n", st_final_time.tv_sec, st_init_time.tv_sec);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_libc_unistd_usleep PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("usleep", st_final_time.tv_sec - st_init_time.tv_sec, SEC_3);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -216,42 +192,26 @@ static void tc_libc_unistd_usleep(void)
 */
 static void tc_libc_unistd_pipe(void)
 {
+       int ret_chk;
        int pid[2];
 
-       if (pipe(pipe_fd) < 0) {
-               printf("tc_libc_unistd_pipe FAIL: pipe error\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       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);
-       if (pid[0] < 0) {
-               printf("tc_libc_unistd_pipe FAIL: tx task creation fail\n");
-               total_fail++;
-               goto close_pipe;
-       }
+       TC_ASSERT_GEQ_CLEANUP("task_create", pid[0], 0, get_errno(), goto cleanup_pipe);
 
        pid[1] = task_create("rx", 99, 1024, pipe_rx_func, NULL);
-       if (pid[1] < 0) {
-               printf("tc_libc_unistd_pipe FAIL: rx task creation fail\n");
-               total_fail++;
-               goto close_pipe;
-       }
+       TC_ASSERT_GEQ_CLEANUP("task_create", pid[1], 0, get_errno(), goto cleanup_pipe);
 
        sem_wait(&pipe_sem);
 
-       if (pipe_tc_chk == ERROR) {
-               printf("tc_libc_unistd_pipe FAIL: tx-rx data not matched\n");
-               total_fail++;
-               goto close_pipe;
-       }
-
-       printf("tc_libc_unistd_pipe PASS\n");
-       total_pass++;
+       TC_ASSERT_NEQ_CLEANUP("pipe", pipe_tc_chk, ERROR, get_errno(), goto cleanup_pipe);
 
-close_pipe:
+       TC_SUCCESS_RESULT();
 
+cleanup_pipe:
        close(pipe_fd[0]);
        close(pipe_fd[1]);
 }
index aef4cf1..015e215 100644 (file)
@@ -433,18 +433,10 @@ static void tc_mqueue_mq_open_close_send_receive(void)
        /* Start the sending thread at higher priority */
 
        status = pthread_attr_init(&attr);
-       if (status != OK) {
-               printf("tc_mqueue_mq_open_close_send_receive FAIL : pthread_attr_init failed, status=%d\n", status);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_attr_init", status, OK);
 
        status = pthread_attr_setstacksize(&attr, STACKSIZE);
-       if (status != OK) {
-               printf("tc_mqueue_mq_open_close_send_receive FAIL : pthread_attr_setstacksize failed, status=%d\n", status);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_attr_setstacksize", status, OK);
 
        prio_min = sched_get_priority_min(SCHED_FIFO);
        prio_max = sched_get_priority_max(SCHED_FIFO);
@@ -452,56 +444,28 @@ static void tc_mqueue_mq_open_close_send_receive(void)
 
        sparam.sched_priority = prio_mid;
        status = pthread_attr_setschedparam(&attr, &sparam);
-       if (status != OK) {
-               printf("tc_mqueue_mq_open_close_send_receive FAIL : pthread_attr_setschedparam failed, status=%d\n", status);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_attr_setschedparam", status, OK);
 
        status = pthread_create(&receiver, &attr, receiver_thread, NULL);
-       if (status != OK) {
-               printf("tc_mqueue_mq_open_close_send_receive FAIL : pthread_create failed, status=%d\n", status);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_create", status, OK);
 
        /* Start the sending thread at lower priority */
 
        status = pthread_attr_init(&attr);
-       if (status != OK) {
-               printf("tc_mqueue_mq_open_close_send_receive FAIL : pthread_attr_init failed, status=%d\n", status);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_attr_init", status, OK);
 
        status = pthread_attr_setstacksize(&attr, STACKSIZE);
-       if (status != OK) {
-               printf("tc_mqueue_mq_open_close_send_receive FAIL : pthread_attr_setstacksize failed, status=%d\n", status);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_attr_setstacksize", status, OK);
 
        sparam.sched_priority = (prio_min + prio_mid) / 2;
        status = pthread_attr_setschedparam(&attr, &sparam);
-       if (status != OK) {
-               printf("tc_mqueue_mq_open_close_send_receive FAIL : pthread_attr_setschedparam failed, status=%d\n", status);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_attr_setschedparam", status, OK);
 
        status = pthread_create(&sender, &attr, sender_thread, NULL);
-       if (status != OK) {
-               printf("tc_mqueue_mq_open_close_send_receive FAIL : pthread_create failed, status=%d\n", status);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_create", status, OK);
 
        pthread_join(sender, &result);
-       if (result != (void *)0) {
-               printf("tc_mqueue_mq_open_close_send_receive FAIL : ERROR sender thread exited with %d errors\n", (int)result);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_join", result, (void *)0);
 #ifndef CONFIG_DISABLE_SIGNALS
        /* Wake up the receiver thread with a signal */
 
@@ -527,12 +491,7 @@ static void tc_mqueue_mq_open_close_send_receive(void)
         */
 
        pthread_join(receiver, &result);
-       if (result != expected) {
-               printf("tc_mqueue_mq_open_close_send_receive FAIL : ERROR receiver thread should have exited with %p\n", expected);
-               tckndbg(" ERROR Instead exited with nerrors=%d\n", (int)result);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_join", result, expected);
 
        /* Message queues are global resources and persist for the life the the
         * task group.  The message queue opened by the sender_thread must be closed
@@ -541,41 +500,19 @@ static void tc_mqueue_mq_open_close_send_receive(void)
         */
 
        if (result == PTHREAD_CANCELED && g_recv_mqfd) {
-               if (mq_close(g_recv_mqfd) < 0) {
-                       printf("tc_mqueue_mq_open_close_send_receive FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_GEQ("mq_close", mq_close(g_recv_mqfd), 0);
        } else if (result != PTHREAD_CANCELED && g_recv_mqfd) {
-               printf("tc_mqueue_mq_open_close_send_receive FAIL : ERROR send mqd_t left open\n");
-               if (mq_close(g_recv_mqfd) < 0) {
-                       printf("tc_mqueue_mq_close FAIL\n");
-               }
-               total_fail++;
-               RETURN_ERR;
+               TC_ASSERT_EQ("mq_close", mq_close(g_recv_mqfd), 0);
+               TC_ASSERT("pthread_join", false);
        }
 
        /* Make sure that the receive queue is closed as well */
-
-       if (g_send_mqfd) {
-               printf("tc_mqueue_mq_open_close_send_receive FAIL : receiver mqd_t left open\n");
-               if (mq_close(g_send_mqfd) < 0) {
-                       printf("tc_mqueue_mq_open_close_send_receive FAIL : sender_thread ERROR mq_close failed\n");
-               }
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT("mq_close", !g_send_mqfd);
 
        /* Destroy the message queue */
+       TC_ASSERT_GEQ("mq_unlink", mq_unlink("mqueue"), 0);
 
-       if (mq_unlink("mqueue") < 0) {
-               printf("tc_mqueue_mq_open_close_send_receive FAIL: mq_unlink FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       total_pass++;
-       printf("tc_mqueue_mq_open_close_send_receive PASS\n");
+       TC_SUCCESS_RESULT();
 }
 
 static void tc_libc_mqueue_mq_setattr_getattr(void)
@@ -585,44 +522,29 @@ static void tc_libc_mqueue_mq_setattr_getattr(void)
        struct mq_attr nmqstat;
 
        mqdes = mq_open("mqsetget", O_CREAT | O_RDWR, 0666, 0);
-       if (mqdes == (mqd_t)-1) {
-               printf("tc_libc_mqueue_mq_setattr_getattr FAIL : mq_open fail\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("mq_open", mqdes, (mqd_t)-1);
+
        memset(&mqstat, 0, sizeof(mqstat));
        memset(&nmqstat, 0, sizeof(mqstat));
 
-       if (mq_getattr(mqdes, &mqstat) == ERROR) {
-               printf("tc_libc_mqueue_mq_setattr_getattr FAIL : mq_getattr fail\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("mq_getattr", mq_getattr(mqdes, &mqstat), ERROR);
+
        mqstat.mq_maxmsg = mqstat.mq_maxmsg + 1;
        mqstat.mq_msgsize = mqstat.mq_msgsize + 1;
        mqstat.mq_curmsgs = mqstat.mq_curmsgs + 1;
 
-       if (mq_setattr(mqdes, &mqstat, NULL) != OK) {
-               printf("tc_libc_mqueue_mq_setattr_getattr FAIL : mq_setattr fail\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (mq_getattr(mqdes, &nmqstat) == ERROR) {
-               printf("tc_libc_mqueue_mq_setattr_getattr FAIL : mq_getattr fail\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if ((nmqstat.mq_maxmsg == mqstat.mq_maxmsg) || (nmqstat.mq_msgsize == mqstat.mq_msgsize) || (nmqstat.mq_curmsgs == mqstat.mq_curmsgs)) {
-               printf("tc_libc_mqueue_mq_setattr_getattr FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("mq_setattr", mq_setattr(mqdes, &mqstat, NULL), OK);
+
+       TC_ASSERT_NEQ("mq_getattr", mq_getattr(mqdes, &nmqstat), ERROR);
+
+       TC_ASSERT_NEQ("mq_setattr_getattr", nmqstat.mq_maxmsg, mqstat.mq_maxmsg);
+       TC_ASSERT_NEQ("mq_setattr_getattr", nmqstat.mq_msgsize, mqstat.mq_msgsize);
+       TC_ASSERT_NEQ("mq_setattr_getattr", nmqstat.mq_curmsgs, mqstat.mq_curmsgs);
 
        mq_close(mqdes);
        mq_unlink("mqsetget");
 
-       total_pass++;
-       printf("tc_libc_mqueue_mq_setattr_getattr PASS\n");
+       TC_SUCCESS_RESULT();
 }
 
 static void tc_libc_mqueue_mq_notify(void)
@@ -634,44 +556,31 @@ static void tc_libc_mqueue_mq_notify(void)
        unsigned int prio = 1;
 
        mqdes = mq_open("noti_queue", O_CREAT | O_RDWR, 0666, 0);
-       if (mqdes == (mqd_t)-1) {
-               printf("tc_libc_mqueue_mq_notify FAIL : mq_open\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("mq_open", mqdes, (mqd_t)-1);
 
        notification.sigev_notify = SIGEV_SIGNAL;
        notification.sigev_signo = SIGUSR1;
        sa.sa_handler = mq_notify_handler;
        sa.sa_flags = 0;
        sigaction(SIGUSR1, &sa, NULL);
-       if (mq_notify(mqdes, &notification) != OK) {
-               printf("tc_libc_mqueue_mq_notify FAIL : mq_notify\n");
-               total_fail++;
-               mq_close(mqdes);
-               mq_unlink("noti_queue");
-               RETURN_ERR;
+
+       TC_ASSERT_EQ_CLEANUP("mq_notify", mq_notify(mqdes, &notification), OK, get_errno(), {
+               goto cleanup;
        }
-       if (mq_send(mqdes, s_msg_ptr, 15, prio) == ERROR) {
-               printf("tc_libc_mqueue_mq_notify FAIL : mq_send %d\n", errno);
-               total_fail++;
-               mq_close(mqdes);
-               mq_unlink("noti_queue");
-               RETURN_ERR;
+                                               );
+
+       TC_ASSERT_NEQ_CLEANUP("mq_send", mq_send(mqdes, s_msg_ptr, 15, prio), ERROR, get_errno(), {
+               goto cleanup;
        }
+                                                );
+
        sleep(1);
-       if (!enter_notify_handler) {
-               printf("tc_libc_mqueue_mq_notify FAIL\n");
-               total_fail++;
-               mq_close(mqdes);
-               mq_unlink("noti_queue");
-               RETURN_ERR;
-       } else {
-               printf("tc_libc_mqueue_mq_notify PASS\n");
-               total_pass++;
-               mq_close(mqdes);
-               mq_unlink("noti_queue");
-       }
+       TC_ASSERT("mq_notify", enter_notify_handler);
+
+       TC_SUCCESS_RESULT();
+cleanup:
+       mq_close(mqdes);
+       mq_unlink("noti_queue");
 }
 
 static void tc_libc_mqueue_mq_timedsend_timedreceive(void)
@@ -680,19 +589,12 @@ static void tc_libc_mqueue_mq_timedsend_timedreceive(void)
 
        timedsend_check = timedreceive_check = 0;
        ret_chk = timedsend_test();
-       if (ret_chk != OK) {
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("timedsend_test", ret_chk, OK);
 
        ret_chk = timedreceive_test();
-       if (ret_chk != OK) {
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("timedreceive_test", ret_chk, OK);
 
-       total_pass++;
-       printf("tc_libc_mqueue_mq_timedsend_timedreceive PASS\n");
+       TC_SUCCESS_RESULT();
 }
 
 static void tc_libc_mqueue_mq_unlink(void)
@@ -701,30 +603,23 @@ static void tc_libc_mqueue_mq_unlink(void)
        mqd_t mqdes;
 
        mqdes = mq_open("mqunlink", O_CREAT | O_RDWR, 0666, 0);
-       if (mqdes == (mqd_t)-1) {
-               printf("tc_libc_mqueue_mq_setattr_getattr FAIL : mq_open fail\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("mq_open", mqdes, (mqd_t)-1);
 
        ret = mq_unlink("mqunlink");
-       if (ret != OK) {
-               printf("tc_mqueue_mq_unlink FAIL\n");
-               total_fail++;
+       TC_ASSERT_EQ_CLEANUP("mq_unlink", ret, OK, get_errno(), {
                mq_close(mqdes);
-               RETURN_ERR;
-       }
+       });
+
        ret = mq_unlink("mqunlink");
-       if (ret != ERROR || errno != ENOENT) {
-               printf("tc_mqueue_mq_unlink FAIL2\n");
-               total_fail++;
+       TC_ASSERT_EQ_CLEANUP("mq_unlink", ret, ERROR, get_errno(), {
                mq_close(mqdes);
-               RETURN_ERR;
-       }
+       });
+       TC_ASSERT_EQ_CLEANUP("mq_unlink", errno, ENOENT, get_errno(), {
+               mq_close(mqdes);
+       });
 
-       total_pass++;
        mq_close(mqdes);
-       printf("tc_mqueue_mq_unlink PASS\n");
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index 866ce66..75a4603 100644 (file)
@@ -38,6 +38,7 @@
 #define SEC_3                   3
 #define SEC_5                   5
 #define SEC_8                   8
+#define VAL_ONE                 1
 #define VAL_TWO                 2
 #define VAL_THREE               3
 #define PTHREAD_CNT             4
@@ -54,7 +55,7 @@ pthread_t g_thread1;
 pthread_t g_thread2;
 pthread_t thread[PTHREAD_CNT];
 
-pthread_mutex_t g_mutex;
+pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
 pthread_cond_t g_cond;
 pthread_once_t g_once = PTHREAD_ONCE_INIT;
 pthread_key_t g_tlskey;
@@ -74,11 +75,7 @@ static pthread_cond_t cond;
 static int g_mutex_cnt = 0;
 static int isemaphore;
 
-int g_cond_sig_chk = 0;
-bool g_chk_err = false;
-bool g_sig_chk = false;
-pthread_cond_t g_cond_signal;
-pthread_mutex_t g_mutex_cond_signal = PTHREAD_MUTEX_INITIALIZER;
+int g_cond_sig_val = 0;
 
 static bool g_sig_handle = false;
 
@@ -417,40 +414,40 @@ static void *thread_yield_callback(void *arg)
 static void *thread_waiter(void *parameter)
 {
        struct timespec ts;
-       int ret;
+       int ret_chk;
 
        pthread_setname_np(0, "thread_waiter");
        /* Take the mutex */
        g_bpthreadcallback = true;
-       ret = pthread_mutex_lock(&g_mutex_timedwait);
-       if (ret != OK) {
-               printf("thread_waiter: ERROR pthread_mutex_lock failed, ret=%d\n", ret);
+       ret_chk = pthread_mutex_lock(&g_mutex_timedwait);
+       if (ret_chk != OK) {
+               printf("thread_waiter: ERROR pthread_mutex_lock failed, ret_chk=%d\n", ret_chk);
        }
 
-       ret = clock_gettime(CLOCK_REALTIME, &ts);
-       if (ret != OK) {
+       ret_chk = clock_gettime(CLOCK_REALTIME, &ts);
+       if (ret_chk != OK) {
                printf("thread_waiter: ERROR clock_gettime failed\n");
        }
        ts.tv_sec += SEC_5;
 
        /* The wait -- no-one is ever going to awaken us */
 
-       ret = pthread_cond_timedwait(&cond, &g_mutex_timedwait, &ts);
-       if (ret != OK) {
-               if (ret != ETIMEDOUT) {
+       ret_chk = pthread_cond_timedwait(&cond, &g_mutex_timedwait, &ts);
+       if (ret_chk != OK) {
+               if (ret_chk != ETIMEDOUT) {
                        g_bpthreadcallback = false;
-                       printf("thread_waiter: ERROR pthread_cond_timedwait failed, ret=%d\n", ret);
+                       printf("thread_waiter: ERROR pthread_cond_timedwait failed, ret_chk=%d\n", ret_chk);
                }
        } else {
                g_bpthreadcallback = false;
-               printf("thread_waiter: ERROR pthread_cond_timedwait returned without timeout, ret=%d\n", ret);
+               printf("thread_waiter: ERROR pthread_cond_timedwait returned without timeout, ret_chk=%d\n", ret_chk);
        }
 
        /* Release the mutex */
-       ret = pthread_mutex_unlock(&g_mutex_timedwait);
-       if (ret != OK) {
+       ret_chk = pthread_mutex_unlock(&g_mutex_timedwait);
+       if (ret_chk != OK) {
                g_bpthreadcallback = false;
-               printf("thread_waiter: ERROR pthread_mutex_unlock failed, ret=%d\n", ret);
+               printf("thread_waiter: ERROR pthread_mutex_unlock failed, ret_chk=%d\n", ret_chk);
        }
 
        pthread_exit((pthread_addr_t)0x12345678);
@@ -470,7 +467,6 @@ void *thread_mutex(void *arg)
        if (ret_chk != OK) {
                g_bpthreadcallback = false;
                printf("tc_pthread_pthread_mutex_lock_unlock_trylock  FAIL  Error No: %d\n", errno);
-               total_fail++;
                return NULL;
        }
 
@@ -487,7 +483,6 @@ void *thread_mutex(void *arg)
        if (ret_chk != OK) {
                g_bpthreadcallback = false;
                printf("tc_pthread_pthread_mutex_lock_unlock_trylock  FAIL  Error No: %d\n", errno);
-               total_fail++;
                goto err;
        }
 
@@ -505,43 +500,30 @@ void *thread_cond_signal(void *parm)
 {
        int ret_chk;
 
-       while (!g_chk_err) {
-               /* Usually worker threads will loop on these operations */
-               ret_chk = pthread_mutex_lock(&g_mutex_cond_signal);
-               if (ret_chk != OK) {
-                       printf("pthread_mutex_lock FAIL \n");
-                       g_chk_err = true;
-                       goto err;
-               }
+       /* Wait mutex */
+       ret_chk = pthread_mutex_lock(&g_mutex);
+       if (ret_chk != OK) {
+               g_cond_sig_val = ERROR;
+               goto err;
+       }
 
-               while (!g_cond_sig_chk) {
-                       g_sig_chk = true;
-                       /* printf("Thread blocked\n"); */
-                       ret_chk = pthread_cond_wait(&g_cond_signal, &g_mutex_cond_signal);
-                       if (g_sig_chk == true) {
-                               printf(" g_sig_chk should be false \n");
-                               g_chk_err = true;
-                               goto err;
-                       }
-                       if (ret_chk != OK) {
-                               printf("pthread_cond_wait FAIL \n");
-                               g_chk_err = true;
-                               goto err;
-                       }
-               }
-               /* printf("Thread awake, finish work!\n"); */
+       g_cond_sig_val = VAL_TWO;
 
-               g_cond_sig_chk = 0;
+       /* Wait pthread_cond_signal */
+       ret_chk = pthread_cond_wait(&g_cond, &g_mutex);
+       if (ret_chk != OK) {
+               g_cond_sig_val = ERROR;
+               goto err;
+       }
 
-               ret_chk = pthread_mutex_unlock(&g_mutex_cond_signal);
-               if (ret_chk != OK) {
-                       printf("pthread_mutex_unlock FAIL \n");
-                       g_chk_err = true;
-                       goto err;
-               }
+       g_cond_sig_val = VAL_THREE;
+
+       ret_chk = pthread_mutex_unlock(&g_mutex);
+       if (ret_chk != OK) {
+               g_cond_sig_val = ERROR;
+               goto err;
        }
 err:
-       pthread_exit(NULL);
        return NULL;
 }
 
@@ -563,49 +545,39 @@ err:
 */
 static void tc_pthread_pthread_barrier_init_destroy_wait(void)
 {
+       int ret_chk;
        int ithread = PTHREAD_CNT;
-       int iret = ERROR;
        int ithreadid;
        g_barrier_count_in = 0;
        g_barrier_count_out = 0;
        g_barrier_count_spare = 0;
 
        pthread_t rgthreads[ithread];
-       iret = pthread_barrier_init(&g_pthread_barrier, 0, ithread);
-       if (iret != OK) {
-               printf("[%s] pthread_barrier_init FAIL \n", __func__);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_barrier_init(&g_pthread_barrier, 0, ithread);
+       TC_ASSERT_EQ("pthread_barrier_init", ret_chk, OK);
 
-       for (ithreadid = 0; ithreadid < ithread; ithreadid++)
-               iret = pthread_create(&rgthreads[ithreadid], NULL, task_barrier, (void *)ithreadid);
+       for (ithreadid = 0; ithreadid < ithread; ithreadid++) {
+               ret_chk = pthread_create(&rgthreads[ithreadid], NULL, task_barrier, (void *)ithreadid);
+       }
 
-       if (iret != OK) {
+       if (ret_chk != OK) {
                printf("[%s] pthread_create FAIL \n", __func__);
        }
        for (ithreadid = 0; ithreadid < ithread; ithreadid++) {
-               iret = pthread_join(rgthreads[ithreadid], 0);
-               if (iret != OK) {
+               ret_chk = pthread_join(rgthreads[ithreadid], 0);
+               if (ret_chk != OK) {
                        printf("[%s] pthread_join FAIL \n", __func__);
                }
        }
 
-       iret = pthread_barrier_destroy(&g_pthread_barrier);
-       if (iret != OK) {
-               printf("[%s] pthread_barrier_init FAIL \n", __func__);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_barrier_destroy(&g_pthread_barrier);
+       TC_ASSERT_EQ("pthread_barrier_destroy", ret_chk, OK);
 
-       if (g_barrier_count_spare != OK || g_barrier_count_in != ithread || g_barrier_count_out != ithread) {
-               printf("[%s] pthread_barrier_init FAIL \n", __func__);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_barrier_init_destroy_wait", g_barrier_count_spare, OK);
+       TC_ASSERT_EQ("pthread_barrier_init_destroy_wait", g_barrier_count_in, ithread);
+       TC_ASSERT_EQ("pthread_barrier_init_destroy_wait", g_barrier_count_out, ithread);
 
-       printf("tc_pthread_pthread_barrier_init_destroy_wait PASS \n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -621,40 +593,24 @@ static void tc_pthread_pthread_barrier_init_destroy_wait(void)
 */
 static void tc_pthread_pthread_create_exit_join(void)
 {
-
+       int ret_chk;
        pthread_t pthread;
        void *p_value = 0;
        isemaphore = ERROR;
-       int iret = ERROR;
 
-       iret = pthread_create(&pthread, NULL, task_exit, NULL);
-       if (iret != OK) {
-               printf("[%s] pthread_create FAIL \n", __func__);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_create(&pthread, NULL, task_exit, NULL);
+       TC_ASSERT_EQ("pthread create", ret_chk, OK);
 
        /* To make sure thread is created before we join it */
        while (isemaphore == INTHREAD) {
                sleep(SEC_1);
        }
 
-       iret = pthread_join(pthread, &p_value);
-       if (iret != OK) {
-               printf("[%s] pthread_join FAIL \n", __func__);
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       if (p_value != RETURN_PTHREAD_JOIN) {
-               printf("[%s] pthread_join FAIL : did not return pthread_exit() value\n", __func__);
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       printf("tc_pthread_pthread_create_exit_join PASS \n");
-       total_pass++;
+       ret_chk = pthread_join(pthread, &p_value);
+       TC_ASSERT_EQ("pthread_join", ret_chk, OK);
+       TC_ASSERT_EQ("pthread_join", p_value, RETURN_PTHREAD_JOIN);
 
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -670,27 +626,23 @@ static void tc_pthread_pthread_create_exit_join(void)
 */
 static void tc_pthread_pthread_kill(void)
 {
-       int status = OK;
+       int ret_chk;
        g_bpthreadcallback = false;
 
-       status = pthread_create(&g_thread1, NULL, thread_kill_func_callback, NULL);
-       if (status != OK) {
+       ret_chk = pthread_create(&g_thread1, NULL, thread_kill_func_callback, NULL);
+       if (ret_chk != OK) {
                tckndbg("ERROR pthread_create FAIL\n");
                pthread_detach(g_thread1);
        }
        sleep(SEC_2);
 
-       status = pthread_kill(g_thread1, SIGUSR1);
+       ret_chk = pthread_kill(g_thread1, SIGUSR1);
        sleep(SEC_1);
-       if (status != OK || !g_bpthreadcallback) {
-               pthread_detach(g_thread1);
-               printf("tc_pthread_pthread_kill FAIL\n");
-               total_fail++;
-       } else {
-               pthread_join(g_thread1, NULL);
-       }
-       printf("tc_pthread_pthread_kill PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ_CLEANUP("pthread_kill", ret_chk, OK, get_errno(), pthread_detach(g_thread1));
+       TC_ASSERT_EQ_CLEANUP("pthread_kill", g_bpthreadcallback, true, get_errno(), pthread_detach(g_thread1));
+       pthread_join(g_thread1, NULL);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -704,42 +656,22 @@ static void tc_pthread_pthread_kill(void)
 */
 static void tc_pthread_pthread_cond_broadcast(void)
 {
-       pthread_t rgthread[PTHREAD_CNT];
-       int iret = 0;
+       int ret_chk;
        int ipthread_id = 0;
+       pthread_t rgthread[PTHREAD_CNT];
        g_barrier_count_in = 0;
        g_barrier_count_out = 0;
        g_cnt = 0;
 
-       iret = pthread_mutex_init(&g_mutex, NULL);
-       if (iret != OK) {
-               printf("[%s]pthread_mutex_init FAIL,error : %d\n", __func__, iret);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_mutex_init(&g_mutex, NULL);
+       TC_ASSERT_EQ("pthread_mutex_init", ret_chk, OK);
 
-       iret = pthread_cond_init(&g_cond, NULL);
-       if (iret != OK) {
-               printf("[%s]pthread_cond_init FAIL,error : %d\n", __func__, iret);
-               pthread_mutex_destroy(&g_mutex);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_cond_init(&g_cond, NULL);
+       TC_ASSERT_EQ_CLEANUP("pthread_cond_init", ret_chk, OK, get_errno(), pthread_mutex_destroy(&g_mutex));
 
        for (ipthread_id = 0; ipthread_id < PTHREAD_CNT; ipthread_id++) {
-               iret = pthread_create(&rgthread[ipthread_id], NULL, pthread_wait_callback, NULL);
-               if (iret != OK) {
-                       printf("[%s] pthread_create :  %d FAIL\n", __func__, ipthread_id);
-                       int iindex;
-                       for (iindex = 0; iindex < ipthread_id; iindex++) {
-                               pthread_cancel(rgthread[iindex]);
-                               pthread_join(rgthread[iindex], NULL);
-                       }
-                       pthread_cond_destroy(&g_cond);
-                       pthread_mutex_destroy(&g_mutex);
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               ret_chk = pthread_create(&rgthread[ipthread_id], NULL, pthread_wait_callback, NULL);
+               TC_ASSERT_EQ_CLEANUP("pthread_create", ret_chk, OK, get_errno(), goto cleanup_cond);
        }
 
        /* To check all thread block conditional lock */
@@ -748,84 +680,40 @@ static void tc_pthread_pthread_cond_broadcast(void)
        }
 
        /* To make sure all waiter are currently block on pthread_cond_wait */
-       iret = pthread_mutex_lock(&g_mutex);
-       if (iret != OK) {
-               printf("[%s]pthread_mutex_lock FAIL,error : %d\n", __func__, iret);
-               total_fail++;
-               pthread_cond_broadcast(&g_cond);
-               for (ipthread_id = 0; ipthread_id < PTHREAD_CNT; ++ipthread_id) {
-                       pthread_cancel(rgthread[ipthread_id]);
-                       pthread_join(rgthread[ipthread_id], NULL);
-               }
-               pthread_cond_destroy(&g_cond);
-               pthread_mutex_destroy(&g_mutex);
-               RETURN_ERR;
-       }
+       ret_chk = pthread_mutex_lock(&g_mutex);
+       TC_ASSERT_EQ_CLEANUP("pthread_mutex_lock", ret_chk, OK, get_errno(), goto cleanup_mutex);
 
-       iret = pthread_mutex_unlock(&g_mutex);
-       if (iret != OK) {
-               pthread_cond_broadcast(&g_cond);
-               printf("[%s]pthread_mutex_unlock FAIL,error : %d\n", __func__, iret);
-               total_fail++;
-               for (ipthread_id = 0; ipthread_id < PTHREAD_CNT; ++ipthread_id) {
-                       pthread_cancel(rgthread[ipthread_id]);
-                       pthread_join(rgthread[ipthread_id], NULL);
-               }
-               pthread_cond_destroy(&g_cond);
-               pthread_mutex_destroy(&g_mutex);
-               RETURN_ERR;
-       }
+       ret_chk = pthread_mutex_unlock(&g_mutex);
+       TC_ASSERT_EQ_CLEANUP("pthread_mutex_unlock", ret_chk, OK, get_errno(), goto cleanup_mutex);
 
-       iret = pthread_cond_broadcast(&g_cond);
-       if (iret != OK) {
-               printf("[%s] pthread_cond_broadcast FAIL, error no: %d\n", iret);
-               total_fail++;
-               for (ipthread_id = 0; ipthread_id < PTHREAD_CNT; ++ipthread_id) {
-                       pthread_cancel(rgthread[ipthread_id]);
-                       pthread_join(rgthread[ipthread_id], NULL);
-               }
-               pthread_cond_destroy(&g_cond);
-               pthread_mutex_destroy(&g_mutex);
-               RETURN_ERR;
-       }
+       ret_chk = pthread_cond_broadcast(&g_cond);
+       TC_ASSERT_EQ_CLEANUP("pthread_cond_broadcast", ret_chk, OK, get_errno(), goto cleanup_cond);
 
        sleep(SEC_1);
-
-       if (g_barrier_count_out < PTHREAD_CNT) {
-               printf("[%s]pthread_cond_broadcast FAIL, unable to release lock for all thread \n", __func__);
-               for (ipthread_id = 0; ipthread_id < PTHREAD_CNT; ++ipthread_id) {
-                       pthread_cancel(rgthread[ipthread_id]);
-                       pthread_join(rgthread[ipthread_id], NULL);
-               }
-               pthread_cond_destroy(&g_cond);
-               pthread_mutex_destroy(&g_mutex);
-               RETURN_ERR;
-       }
+       TC_ASSERT_GEQ_CLEANUP("pthread_cond_broadcast", g_barrier_count_out, PTHREAD_CNT, get_errno(), goto cleanup_cond);
 
        /* Wait till terminate all thread */
        for (ipthread_id = 0; ipthread_id < PTHREAD_CNT; ipthread_id++) {
-               iret = pthread_join(rgthread[ipthread_id], NULL);
-               if (iret != OK) {
-                       printf("[%s]pthread_join FAIL,error : %d\n", __func__, iret);
-               }
+               ret_chk = pthread_join(rgthread[ipthread_id], NULL);
+               TC_ASSERT_EQ_CLEANUP("pthread_join", ret_chk, OK, get_errno(), goto cleanup_cond);
        }
 
-       iret = pthread_cond_destroy(&g_cond);
-       if (iret != OK) {
-               printf("[%s]pthread_cond_destroy FAIL,error : %d\n", __func__, iret);
-               pthread_mutex_destroy(&g_mutex);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_cond_destroy(&g_cond);
+       TC_ASSERT_EQ_CLEANUP("pthread_cond_destroy", ret_chk, OK, ret_chk, pthread_mutex_destroy(&g_mutex));
 
-       iret = pthread_mutex_destroy(&g_mutex);
-       if (iret != OK) {
-               printf("[%s]pthread_mutex_destroy FAIL,error : %d\n", __func__, iret);
-               total_fail++;
-               RETURN_ERR;
+       ret_chk = pthread_mutex_destroy(&g_mutex);
+       TC_ASSERT_EQ("pthread_mutex_destroy", ret_chk, OK);
+
+       TC_SUCCESS_RESULT();
+cleanup_mutex:
+       pthread_cond_broadcast(&g_cond);
+cleanup_cond:
+       for (ipthread_id = 0; ipthread_id < PTHREAD_CNT; ++ipthread_id) {
+               pthread_cancel(rgthread[ipthread_id]);
+               pthread_join(rgthread[ipthread_id], NULL);
        }
-       printf("tc_pthread_pthread_cond_broadcast PASS\n");
-       total_pass++;
+       pthread_cond_destroy(&g_cond);
+       pthread_mutex_destroy(&g_mutex);
 }
 
 /**
@@ -841,53 +729,31 @@ static void tc_pthread_pthread_cond_broadcast(void)
 */
 static void tc_pthread_pthread_cond_init_destroy(void)
 {
-       int ret_chk = ERROR;
+       int ret_chk;
        pthread_condattr_t attr;
        pthread_cond_t cond_nullparam;
        pthread_cond_t cond_attrparam;
 
        ret_chk = pthread_condattr_init(&attr);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_cond_init_destroy: TC FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_condattr_init", ret_chk, OK);
+
        /* parameters of pthread_cond_init are of opaque data type hence parameter check not possible */
        ret_chk = pthread_cond_init(&cond_nullparam, NULL);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_cond_init_destroy: TC FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_cond_init", ret_chk, OK);
 
        ret_chk = pthread_cond_init(&cond_attrparam, &attr);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_cond_init_destroy: TC FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_cond_init", ret_chk, OK);
 
        ret_chk = pthread_cond_destroy(&cond_nullparam);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_cond_init_destroy: TC FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_cond_destroy", ret_chk, OK);
+
        ret_chk = pthread_cond_destroy(&cond_attrparam);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_cond_init_destroy: TC FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_cond_destroy", ret_chk, OK);
 
        ret_chk = pthread_condattr_destroy(&attr);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_cond_init_destroy: TC FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_pthread_pthread_cond_init_destroy PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("pthread_condattr_destroy", ret_chk, OK);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -904,7 +770,7 @@ static void tc_pthread_pthread_cond_init_destroy(void)
 */
 static void tc_pthread_pthread_set_get_schedparam(void)
 {
-       int ret_chk = 0;
+       int ret_chk;
        struct sched_param st_setparam;
        struct sched_param st_getparam;
        int getpolicy;
@@ -915,48 +781,23 @@ static void tc_pthread_pthread_set_get_schedparam(void)
        st_setparam.sched_priority = SCHED_PRIORITY;
 
        ret_chk = pthread_create(&g_thread1, NULL, threadfunc_sched, NULL);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_set_get_schedparam: pthread_create FAIL, Error No: %d\n", errno);
-               pthread_detach(g_thread1);
-               total_fail++;
-               RETURN_ERR;
-       }
-
+       TC_ASSERT_EQ_CLEANUP("pthread_create", ret_chk, OK, errno, pthread_detach(g_thread1));
        sleep(SEC_2);
 
        ret_chk = pthread_setschedparam(g_thread1, setpolicy, &st_setparam);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_set_get_schedparam: pthread_setschedparam FAIL, Error No: %d\n", errno);
-               pthread_detach(g_thread1);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ_CLEANUP("pthread_setschedparam", ret_chk, OK, errno, pthread_detach(g_thread1));
 
        sleep(SEC_1);
 
        ret_chk = pthread_getschedparam(g_thread1, &getpolicy, &st_getparam);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_set_get_schedparam: pthread_setschedparam FAIL, Error No: %d\n", errno);
-               pthread_detach(g_thread1);
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (getpolicy != setpolicy || st_getparam.sched_priority != st_setparam.sched_priority) {
-               printf("tc_pthread_pthread_set_get_schedparam: FAIL, Values Mismatch\n");
-               pthread_detach(g_thread1);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ_CLEANUP("pthread_getschedparam", ret_chk, OK, errno, pthread_detach(g_thread1));
+       TC_ASSERT_EQ_CLEANUP("pthread_getschedparam", getpolicy, setpolicy, errno, pthread_detach(g_thread1));
+       TC_ASSERT_EQ_CLEANUP("pthread_getschedparam", st_getparam.sched_priority, st_setparam.sched_priority, errno, pthread_detach(g_thread1));
 
        ret_chk = pthread_join(g_thread1, NULL);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_set_get_schedparam: pthread_join FAIL, Error No: %d\n", errno);
-               pthread_detach(g_thread1);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_pthread_pthread_set_get_schedparam PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ_CLEANUP("pthread_join", ret_chk, OK, errno, pthread_detach(g_thread1));
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -973,44 +814,29 @@ static void tc_pthread_pthread_set_get_schedparam(void)
 */
 static void tc_pthread_pthread_key_create_set_getspecific(void)
 {
-       int ret_chk = 0;
+       int ret_chk;
        g_bpthreadcallback = false;
        g_tlskey = 0;
 
        /* Cannot create keys more than PTHREAD_KEYS_MAX, Not able to delete key */
        ret_chk = pthread_key_create(&g_tlskey, NULL);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_key_create_set_getspecific FAIL : pthread_key_create FAIL\n Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_key_create", ret_chk, OK);
 
        sleep(SEC_2);
 
        ret_chk = pthread_create(&g_thread1, NULL, func_set_get_callback, NULL);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_key_create_set_getspecific FAIL : pthread_create FAIL\n Error No: %d\n", errno);
+       TC_ASSERT_EQ_CLEANUP("pthread_create", ret_chk, OK, errno, {
                pthread_detach(g_thread1);
-               total_fail++;
-               RETURN_ERR;
-       }
+       });
 
        ret_chk = pthread_join(g_thread1, NULL);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_key_create_set_getspecific FAIL : pthread_create FAIL\n Error No: %d\n", errno);
+       TC_ASSERT_EQ_CLEANUP("pthread_join", ret_chk, OK, errno, {
                pthread_detach(g_thread1);
-               total_fail++;
-               RETURN_ERR;
-       }
+       });
 
-       if (g_bpthreadcallback != true) {
-               printf("tc_pthread_pthread_key_create_set_getspecific: g_bpthreadcallback FAIL\n ");
-               pthread_detach(g_thread1);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_pthread_pthread_key_create_set_getspecific PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("pthread_join", g_bpthreadcallback, true);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -1028,44 +854,28 @@ static void tc_pthread_pthread_key_create_set_getspecific(void)
 */
 static void tc_pthread_pthread_cancel_setcancelstate(void)
 {
-       int ret_chk = 0;
+       int ret_chk;
        g_bpthreadcallback = false;
 
        ret_chk = pthread_create(&g_thread1, NULL, cancel_state_func, NULL);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_cancel_setcancelstate PTHREAD CREATE_EXIT FAIL, Error No: %d\n", errno);
+       TC_ASSERT_EQ_CLEANUP("pthread_create", ret_chk, OK, errno, {
                pthread_detach(g_thread1);
-               total_fail++;
-               RETURN_ERR;
-       }
+       });
 
        sleep(SEC_1);
        /* this cancel request goes to pending if cancel is disabled */
        ret_chk = pthread_cancel(g_thread1);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_cancel_setcancelstate pthread_cancel FAIL, Error No: %d\n", errno);
+       TC_ASSERT_EQ_CLEANUP("pthread_cancel", ret_chk, OK, errno, {
                pthread_detach(g_thread1);
-               total_fail++;
-               RETURN_ERR;
-       }
+       });
 
        sleep(SEC_3);
-
-       if (g_bpthreadcallback == false) {
-               printf("tc_pthread_pthread_cancel_setcancelstate FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT("pthread_cancel", g_bpthreadcallback);
 
        ret_chk = pthread_detach(g_thread1);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_cancel_setcancelstate pthread_detach FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_detach", ret_chk, OK);
 
-       printf("tc_pthread_pthread_cancel_setcancelstate PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -1080,39 +890,24 @@ static void tc_pthread_pthread_cancel_setcancelstate(void)
 #if !defined(CONFIG_BUILD_PROTECTED)
 static void tc_pthread_pthread_take_give_semaphore(void)
 {
-       int ret_chk = 0;
+       int ret_chk;
        int get_value;
        sem_t sem;
        sem_init(&sem, 0, VAL_THREE);
 
        ret_chk = pthread_takesemaphore(&sem);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_takesemaphore: Error No %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_takesemaphore", ret_chk, OK);
+
        sem_getvalue(&sem, &get_value);
-       if (get_value != VAL_TWO) {
-               printf("tc_pthread_pthread_takesemaphore: Value Mismatch Error No %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sem_getvalue", get_value, VAL_TWO);
 
        ret_chk = pthread_givesemaphore(&sem);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_givesemaphore: Error No %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_givesemaphore", ret_chk, OK);
 
        sem_getvalue(&sem, &get_value);
-       if (get_value != VAL_THREE) {
-               printf("tc_pthread_pthread_takesemaphore: Value Mismatch Error No %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_pthread_pthread_take_give_semaphore PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("sem_getvalue", get_value, VAL_THREE);
+
+       TC_SUCCESS_RESULT();
 }
 #endif
 /**
@@ -1126,76 +921,47 @@ static void tc_pthread_pthread_take_give_semaphore(void)
  */
 static void tc_pthread_pthread_timed_wait(void)
 {
+       int ret_chk;
        pthread_t waiter;
        pthread_attr_t attr;
        struct sched_param sparam;
        void *result;
        int prio_max;
-       int ret;
 
        /* Initialize the mutex */
        g_bpthreadcallback = false;
-       ret = pthread_mutex_init(&g_mutex_timedwait, NULL);
-       if (ret != OK) {
-               printf("tc_pthread_pthread_timed_wait FAIL: ERROR pthread_mutex_init failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_mutex_init(&g_mutex_timedwait, NULL);
+       TC_ASSERT_EQ("pthread_mutex_init", ret_chk, OK);
 
        /* Initialize the condition variable */
 
-       ret = pthread_cond_init(&cond, NULL);
-       if (ret != OK) {
-               printf("tc_pthread_pthread_timed_wait FAIL: ERROR pthread_condinit failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_cond_init(&cond, NULL);
+       TC_ASSERT_EQ("pthread_cond_init", ret_chk, OK);
 
        /* Start the waiter thread at higher priority */
 
-       ret = pthread_attr_init(&attr);
-       if (ret != OK) {
-               printf("tc_pthread_pthread_timed_wait FAIL: pthread_attr_init failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_attr_init(&attr);
+       TC_ASSERT_EQ("pthread_attr_init", ret_chk, OK);
 
        prio_max = sched_get_priority_max(SCHED_FIFO);
-       ret = sched_getparam(getpid(), &sparam);
-       if (ret != OK) {
+       ret_chk = sched_getparam(getpid(), &sparam);
+       if (ret_chk != OK) {
                sparam.sched_priority = PTHREAD_DEFAULT_PRIORITY;
        }
 
        sparam.sched_priority = (prio_max + sparam.sched_priority) / 2;
-       ret = pthread_attr_setschedparam(&attr, &sparam);
-       if (ret != OK) {
-               printf("tc_pthread_pthread_timed_wait FAIL: pthread_attr_setschedparam failed, ret=%d\n", ret);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_attr_setschedparam(&attr, &sparam);
+       TC_ASSERT_EQ("pthread_attr_setschedparam", ret_chk, OK);
 
-       ret = pthread_create(&waiter, &attr, thread_waiter, NULL);
-       if (ret != OK) {
-               printf("tc_pthread_pthread_timed_wait FAIL: pthread_create failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_create(&waiter, &attr, thread_waiter, NULL);
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
 
-       if (g_bpthreadcallback == false) {
-               printf("tc_pthread_pthread_timed_wait FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT("pthread_create", g_bpthreadcallback);
 
-       ret = pthread_join(waiter, &result);
-       if (ret != OK) {
-               printf("tc_pthread_pthread_timed_wait FAIL: ERROR pthread_join failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_join(waiter, &result);
+       TC_ASSERT_EQ("pthread_join", ret_chk, OK);
 
-       printf("tc_pthread_pthread_timed_wait PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -1216,27 +982,20 @@ static void tc_pthread_pthread_timed_wait(void)
 #if !defined(CONFIG_BUILD_PROTECTED)
 static void tc_pthread_pthread_findjoininfo_destroyjoin(void)
 {
-       int ret_chk = ERROR;
+       int ret_chk;
        g_bpthreadcallback = false;
 
        ret_chk = pthread_create(&g_thread1, NULL, findjoininfo_callback, NULL);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_findjoininfo_destroyjoin fail\n");
+       TC_ASSERT_EQ_CLEANUP("pthread_create", ret_chk, OK, errno, {
                pthread_detach(g_thread1);
-               total_fail++;
-               RETURN_ERR;
-       }
+       });
 
        pthread_join(g_thread1, NULL);
-
-       if (g_bpthreadcallback == false) {
-               printf("tc_pthread_pthread_findjoininfo_destroyjoin g_bpthreadcallback fail\n");
+       TC_ASSERT_EQ_CLEANUP("pthread_join", g_bpthreadcallback, true, errno, {
                pthread_detach(g_thread1);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_pthread_pthread_findjoininfo_destroyjoin PASS \n");
-       total_pass++;
+       });
+
+       TC_SUCCESS_RESULT();
 }
 #endif
 /**
@@ -1252,46 +1011,29 @@ static void tc_pthread_pthread_findjoininfo_destroyjoin(void)
 */
 static void tc_pthread_pthread_mutex_lock_unlock_trylock(void)
 {
-       int ret_chk = ERROR;
+       int ret_chk;
        pthread_mutexattr_t attr;
        pthread_mutexattr_init(&attr);
        pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
 
        pthread_mutex_init(&g_mutex, NULL);
        ret_chk = pthread_mutex_lock(&g_mutex);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_mutex_lock_unlock_trylock PTHREAD_MUTEX_DEFAULT FAIL  Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_mutex_lock", ret_chk, OK);
 
        ret_chk = pthread_mutex_trylock(&g_mutex);
-       if (ret_chk != EBUSY) {
+       TC_ASSERT_EQ_CLEANUP("pthread_mutex_trylock", ret_chk, EBUSY, errno, {
                pthread_mutex_unlock(&g_mutex);
-               printf("tc_pthread_pthread_mutex_lock_unlock_trylock PTHREAD_MUTEX_DEFAULT FAIL  Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       });
 
        ret_chk = pthread_mutex_unlock(&g_mutex);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_mutex_lock_unlock_trylock PTHREAD_MUTEX_DEFAULT FAIL  Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_mutex_unlock", ret_chk, OK);
 
        ret_chk = pthread_mutex_trylock(&g_mutex);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_mutex_lock_unlock_trylock PTHREAD_MUTEX_DEFAULT FAIL  Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_mutex_trylock", ret_chk, OK);
+
        ret_chk = pthread_mutex_unlock(&g_mutex);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_mutex_lock_unlock_trylock PTHREAD_MUTEX_DEFAULT FAIL  Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_mutex_unlock", ret_chk, OK);
+
        pthread_mutex_destroy(&g_mutex);
 
        sleep(SEC_2);
@@ -1300,61 +1042,36 @@ static void tc_pthread_pthread_mutex_lock_unlock_trylock(void)
        pthread_mutex_init(&g_mutex, &attr);
 
        ret_chk = pthread_mutex_lock(&g_mutex);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_mutex_lock_unlock_trylock PTHREAD_MUTEX_RECURSIVE FAIL  Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_mutex_lock", ret_chk, OK);
 
        ret_chk = pthread_mutex_lock(&g_mutex);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_mutex_lock_unlock_trylock PTHREAD_MUTEX_RECURSIVE FAIL  Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_mutex_lock", ret_chk, OK);
 
        ret_chk = pthread_mutex_unlock(&g_mutex);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_mutex_lock_unlock_trylock PTHREAD_MUTEX_RECURSIVE FAIL  Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_mutex_unlock", ret_chk, OK);
+
        ret_chk = pthread_mutex_unlock(&g_mutex);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_mutex_lock_unlock_trylock PTHREAD_MUTEX_RECURSIVE FAIL  Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_mutex_unlock", ret_chk, OK);
 
        /* mutex_lock mutex_unlock check through multi threads */
        g_mutex_cnt = 0;
        ret_chk = pthread_mutex_init(&g_mutex, NULL);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_mutex_lock_unlock_trylock FAIL: mutex init failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_mutex_init", ret_chk, OK);
 
        ret_chk = pthread_create(&g_thread1, NULL, &thread_mutex, NULL);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_mutex_lock_unlock_trylock FAIL: pthread_create failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
+
        ret_chk = pthread_create(&g_thread2, NULL, &thread_mutex, NULL);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_mutex_lock_unlock_trylock FAIL: pthread_create failed\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
 
        pthread_join(g_thread1, NULL);
        pthread_join(g_thread2, NULL);
 
+       TC_ASSERT("pthread_mutex_lock_unlock", g_bpthreadcallback);
+
        pthread_mutex_destroy(&g_mutex);
 
-       printf("tc_pthread_pthread_mutex_lock_unlock_trylock PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -1379,39 +1096,23 @@ static void tc_pthread_pthread_mutex_init_destroy(void)
        pthread_mutexattr_settype(&attr, nType);
 
        ret_chk = pthread_mutex_init(&mMutex, &attr);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_mutex_init FAIL  Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_mutex_init", ret_chk, OK);
 
        ret_chk = pthread_mutex_lock(&mMutex);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_mutex_init FAIL  Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_mutex_lock", ret_chk, OK);
 
        pthread_mutex_unlock(&mMutex);
 
        ret_chk = pthread_mutex_destroy(&mMutex);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_mutex_destroy FAIL  Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_mutex_destroy", ret_chk, OK);
+
        pthread_mutexattr_destroy(&attr);
 
        /* if Mutex is destoryed, then sem of mutex will be set to 1. */
-       if (mMutex.sem.semcount != 1) {
-               printf("tc_pthread_pthread_mutex_destroy trylock FAIL Error No: %d %d\n", ret_chk, errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_mutexattr_destroy", mMutex.sem.semcount, 1);
 
-       printf("tc_pthread_pthread_mutex_init_destroy PASS\n");
-       total_pass++;
        pthread_mutex_destroy(&mMutex);
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -1429,26 +1130,18 @@ static void tc_pthread_pthread_once(void)
 {
        int ret_chk = ERROR;
        ret_chk = pthread_once(&g_once, &run_once);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_once FAIL : pthread_create FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
+
        sleep(SEC_1);
+
        ret_chk = pthread_once(&g_once, &run_once);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_once FAIL : pthread_create FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_once", ret_chk, OK);
+
        sleep(SEC_1);
-       if (g_bpthreadcallback != true) {
-               printf("tc_pthread_pthread_once FAIL : pthread_create FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_pthread_pthread_once PASS\n");
-       total_pass++;
+
+       TC_ASSERT("pthread_once", g_bpthreadcallback);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -1469,48 +1162,26 @@ static void tc_pthread_pthread_yield(void)
        g_bpthreadcallback = false;
 
        ret_chk = pthread_create(&g_thread1, NULL, thread_yield_callback, NULL);
-       if (ret_chk != OK) {
-               printf("tc_pthread_yield FAIL : pthread_create FAIL!\n");
-               pthread_detach(g_thread1);
-       }
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
+
        sleep(SEC_1);
-       if (g_bpthreadcallback == false) {
-               printf("tc_pthread_pthread_yield FAIL\n");
-               pthread_detach(g_thread1);
-               total_fail++;
-               RETURN_ERR;
-       }
+
+       TC_ASSERT_EQ_CLEANUP("pthread_yield", g_bpthreadcallback, true, get_errno(), {pthread_detach(g_thread1);});
+
        ret_chk = pthread_create(&g_thread2, NULL, thread_yield_callback, NULL);
-       if (ret_chk != OK) {
-               printf("tc_pthread_yield FAIL : pthread_create FAIL!\n");
-               pthread_detach(g_thread2);
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (g_bpthreadcallback == false) {
-               printf("tc_pthread_pthread_yield FAIL\n");
-               pthread_detach(g_thread2);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ_CLEANUP("pthread_create", ret_chk, OK, get_errno(), {pthread_detach(g_thread2);});
+       TC_ASSERT_EQ_CLEANUP("pthread_create", g_bpthreadcallback, true, get_errno(), {pthread_detach(g_thread2);});
+
        /* wait for threads to exit */
        sleep(SEC_5);
 
        ret_chk = pthread_join(g_thread1, NULL);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_yield FAIL, pthread_join FAIL: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_join", ret_chk, OK);
+
        ret_chk = pthread_join(g_thread2, NULL);
-       if (ret_chk != OK) {
-               printf("tc_pthread_pthread_yield FAIL, pthread_join FAIL: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_join", ret_chk, OK);
 
-       printf("tc_pthread_pthread_yield PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -1525,117 +1196,70 @@ static void tc_pthread_pthread_yield(void)
 */
 static void tc_pthread_pthread_cond_signal_wait(void)
 {
-       pthread_t pthread_1;
-       pthread_t pthread_2;
-       pthread_cond_init(&g_cond_signal, NULL);
-       g_sig_chk = false;
-       g_chk_err = false;
-       int iret = ERROR;
-       int indexloop = 0;
+       pthread_t pthread_waiter;
+       int ret_chk = ERROR;
+       g_cond_sig_val = VAL_ONE;
 
-       iret = pthread_create(&pthread_1, NULL, thread_cond_signal, NULL);
-       if (iret != OK) {
-               printf("[%s] tc_pthread_pthread_cond_signal_wait FAIL \n", __func__);
-               total_fail++;
-               RETURN_ERR;
-       }
-       iret = pthread_create(&pthread_2, NULL, thread_cond_signal, NULL);
-       if (iret != OK) {
-               printf("[%s] tc_pthread_pthread_cond_signal_wait FAIL \n", __func__);
-               total_fail++;
-               RETURN_ERR;
-       }
-       sleep(SEC_3);
+       ret_chk = pthread_mutex_init(&g_mutex, NULL);
+       TC_ASSERT_EQ("pthread_mutex_init", ret_chk, OK);
 
-       for (indexloop = 0; indexloop < VAL_THREE; ++indexloop) {
-               /* printf("Wake up a worker, work to do...\n"); */
-               if (g_sig_chk == false) {
-                       printf("[%s] tc_pthread_pthread_cond_signal_wait FAIL \n", __func__);
-                       total_fail++;
-                       RETURN_ERR;
-               }
-               iret = pthread_mutex_lock(&g_mutex_cond_signal);
-               if (iret != OK) {
-                       printf("[%s] tc_pthread_pthread_cond_signal_wait FAIL \n", __func__);
-                       total_fail++;
-                       RETURN_ERR;
-               }
+       ret_chk = pthread_cond_init(&g_cond, NULL);
+       TC_ASSERT_EQ("pthread_cond_init", ret_chk, OK);
 
-               if (g_cond_sig_chk) {
-                       tckndbg("Work already present, likely threads are busy\n");
-               }
-               g_cond_sig_chk = 1;
-               g_sig_chk = false;
-               iret = pthread_cond_signal(&g_cond_signal);
-               if (iret != OK) {
-                       pthread_mutex_unlock(&g_mutex_cond_signal);
-                       printf("[%s] tc_pthread_pthread_cond_signal_wait FAIL \n", __func__);
-                       total_fail++;
-                       RETURN_ERR;
-               }
+       ret_chk = pthread_mutex_lock(&g_mutex);
+       TC_ASSERT_EQ("pthread_mutex_lock", ret_chk, OK);
 
-               iret = pthread_mutex_unlock(&g_mutex_cond_signal);
-               if (iret != OK) {
-                       printf("[%s] tc_pthread_pthread_cond_signal_wait FAIL \n", __func__);
-                       total_fail++;
-                       RETURN_ERR;
-               }
-               sleep(SEC_3);
-       }
+       ret_chk = pthread_create(&pthread_waiter, NULL, thread_cond_signal, NULL);
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
 
-       if (g_chk_err == true) {
-               printf("[%s] tc_pthread_pthread_cond_signal_wait FAIL, g_chk_err is true \n", __func__);
-               total_fail++;
-               RETURN_ERR;
-       }
-       g_chk_err = true;
-       pthread_cancel(pthread_1);
-       pthread_cancel(pthread_2);
-       pthread_join(pthread_1, NULL);
-       pthread_join(pthread_2, NULL);
-       printf("tc_pthread_pthread_cond_signal_wait PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("pthread_mutex_lock", g_cond_sig_val, VAL_ONE);
+
+       ret_chk = pthread_mutex_unlock(&g_mutex);
+       TC_ASSERT_EQ("pthread_mutex_unlock", ret_chk, OK);
+
+       sleep(SEC_1);
+
+       TC_ASSERT_EQ("pthread_cond_signal_wait", g_cond_sig_val, VAL_TWO);
+
+       ret_chk = pthread_cond_signal(&g_cond);
+       TC_ASSERT_EQ("pthread_cond_signal", ret_chk, OK);
+
+       sleep(SEC_1);
+
+       TC_ASSERT_EQ("pthread_cond_signal", g_cond_sig_val, VAL_THREE);
+
+       pthread_cancel(pthread_waiter);
+       pthread_join(pthread_waiter, NULL);
+
+       TC_SUCCESS_RESULT();
 }
 
 static void tc_pthread_pthread_detach(void)
 {
+       int ret_chk;
        pthread_t new_th;
-       int ret;
 
        /* Create the thread */
-       if (pthread_create(&new_th, NULL, do_nothing_thread, NULL) != 0) {
-               printf("tc_pthread_pthread_detach FAIL : pthread_create\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_create(&new_th, NULL, do_nothing_thread, NULL);
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
 
        /* Wait 'till the thread returns.
         * The thread could have ended by the time we try to join, so
         * don't worry about it, just so long as other errors don't
         * occur. The point is to make sure the thread has ended execution. */
-       if (pthread_join(new_th, NULL) == EDEADLK) {
-               printf("tc_pthread_pthread_detach FAIL : pthread_join\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_join(new_th, NULL);
+       TC_ASSERT_NEQ("pthread_join", ret_chk, EDEADLK);
 
        /* Detach the non-existant thread. */
-       ret = pthread_detach(new_th);
+       ret_chk = pthread_detach(new_th);
+       TC_ASSERT_NEQ("pthread_detach", ret_chk, OK);
 
-       /* Check return value of pthread_detach() */
-       if (ret == OK) {
-               printf("tc_pthread_pthread_detach FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       total_pass++;
-       printf("tc_pthread_pthread_detach PASS\n");
+       TC_SUCCESS_RESULT();
 }
 
 static void tc_pthread_pthread_sigmask(void)
 {
-       int ret_chk = ERROR;
+       int ret_chk;
        pid_t pid = getpid();
 
        sigset_t st_newmask;
@@ -1653,205 +1277,123 @@ static void tc_pthread_pthread_sigmask(void)
        memset(&st_act, 0, sizeof(st_act));
        st_act.sa_handler = sigmask_handler;
 
-       if (sigaction(SIGQUIT, &st_act, &st_oact)) {
-               printf("tc_pthread_pthread_sigmask FAIL : sigaction error\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = sigaction(SIGQUIT, &st_act, &st_oact);
+       TC_ASSERT_EQ("signaction", ret_chk, OK);
+
        sigemptyset(&st_newmask);
        sigaddset(&st_newmask, SIGQUIT);
 
        ret_chk = pthread_sigmask(SIG_BLOCK, &st_newmask, &st_oldmask);
-       if (ret_chk < 0) {
-               printf("tc_pthread_pthread_sigmask FAIL SIG_BLOCK error\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_GEQ("pthread_sigmask", ret_chk, 0);
 
        nanosleep(&st_timespec, NULL);
 
        kill(pid, SIGQUIT);
        /* to call the handler function for verifying the sigpromask */
        ret_chk = pthread_sigmask(SIG_SETMASK, &st_oldmask, NULL);
-       if (ret_chk < 0) {
-               printf("tc_pthread_pthread_sigmask FAIL SIG_SETMASK error\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_GEQ("pthread_sigmask", ret_chk, 0);
 
        st_timespec.tv_sec = 1;
 
        nanosleep(&st_timespec, NULL);
 
        ret_chk = pthread_sigmask(SIG_UNBLOCK, &st_oldmask, NULL);
-       if (ret_chk < 0) {
-               printf("tc_pthread_pthread_sigmask FAIL SIG_UNBLOCK error\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_GEQ("pthread_sigmask", ret_chk, 0);
 
        ret_chk = sigpending(&st_pendmask);
-       if (ret_chk < 0) {
-               printf("tc_pthread_pthread_sigmask FAIL sigpending error\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_GEQ("sigpending", ret_chk, 0);
 
        nanosleep(&st_timespec, NULL);
+       TC_ASSERT("pthread_sigmask", g_sig_handle);
 
-       if (!g_sig_handle) {
-               printf("tc_pthread_pthread_sigmask FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = sigaction(SIGQUIT, &st_oact, NULL);
+       TC_ASSERT_EQ("signaction", ret_chk, OK);
 
-       if (sigaction(SIGQUIT, &st_oact, NULL)) {
-               printf("tc_pthread_pthread_sigmask FAIL sigaction error\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_pthread_pthread_sigmask PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 static void tc_pthread_pthread_self(void)
 {
+       int ret_chk;
        pthread_t tcb_pid;
-       if (pthread_create(&tcb_pid, NULL, self_test_thread, NULL) != 0) {
-               printf("tc_pthread_pthread_self FAIL : pthread_create\n");
-               total_fail++;
-               RETURN_ERR;
-       }
 
-       if (self_pid != tcb_pid) {
-               printf("tc_pthread_pthread_self FAIL : pids are not matched %d %d\n", tcb_pid, self_pid);
-               total_fail++;
-               RETURN_ERR;
-       } else {
-               total_pass++;
-               printf("tc_pthread_pthread_self PASS\n");
-       }
+       ret_chk = pthread_create(&tcb_pid, NULL, self_test_thread, NULL);
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
 
        pthread_join(tcb_pid, NULL);
+       TC_ASSERT_EQ("pthread_self", self_pid, tcb_pid);
+
+       TC_SUCCESS_RESULT();
 }
 
 static void tc_pthread_pthread_equal(void)
 {
+       int ret_chk;
        pthread_t first_th;
        pthread_t second_th;
        bool check_same;
 
-       if (pthread_create(&first_th, NULL, do_nothing_thread, NULL) != 0) {
-               printf("tc_pthread_pthread_equal FAIL : pthread_create\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_create(&first_th, NULL, do_nothing_thread, NULL);
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
 
-       if (pthread_create(&second_th, NULL, do_nothing_thread, NULL) != 0) {
-               printf("tc_pthread_pthread_equal FAIL : pthread_create\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_create(&second_th, NULL, do_nothing_thread, NULL);
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
 
        pthread_join(first_th, NULL);
        pthread_join(second_th, NULL);
 
        check_same = pthread_equal(first_th, second_th);
-       if (check_same != FALSE) {
-               total_fail++;
-               printf("tc_pthread_pthread_equal FAIL\n");
-               RETURN_ERR;
-       } else {
-               total_pass++;
-               printf("tc_pthread_pthread_equal PASS\n");
-       }
+       TC_ASSERT_EQ("pthread_equal", check_same, false);
+
+       TC_SUCCESS_RESULT();
 }
 
 #if !defined(CONFIG_BUILD_PROTECTED)
 static void tc_pthread_pthread_setschedprio(void)
 {
-       int ret;
+       int ret_chk;
        pthread_t set_th;
        uint8_t set_prio = 101;
 
-       if (pthread_create(&set_th, NULL, setschedprio_test_thread, NULL) != 0) {
-               printf("tc_pthread_pthread_setschedprio FAIL : pthread_create\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_create(&set_th, NULL, setschedprio_test_thread, NULL);
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
+
        /* change set_th PID's priority to set_prio */
-       ret = pthread_setschedprio(set_th, set_prio);
-       if (ret != OK) {
-               printf("tc_pthread_pthread_setschedprio FAIL : setschedprio, returned value = %d\n", ret);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_setschedprio(set_th, set_prio);
+       TC_ASSERT_EQ("pthread_setschedprio", ret_chk, OK);
 
-       ret = pthread_join(set_th, NULL);
-       if (ret != OK) {
-               printf("tc_pthread_pthread_setschedprio FAIL : pthread_join, returned value = %d\n", ret);
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (check_prio != set_prio) {
-               printf("tc_pthread_pthread_setschedprio FAIL : not matched - SETPID = %d, GETPID = %d\n", set_prio, check_prio);
-               total_fail++;
-               RETURN_ERR;
-       } else {
-               total_pass++;
-               printf("tc_pthread_pthread_setschedprio PASS\n");
-       }
+       ret_chk = pthread_join(set_th, NULL);
+       TC_ASSERT_EQ("pthread_join", ret_chk, OK);
+       TC_ASSERT_EQ("pthread_setschedprio", check_prio, set_prio);
+
+       TC_SUCCESS_RESULT();
 }
 #endif
 
 static void tc_pthread_pthread_setgetname_np(void)
 {
-       int ret;
+       int ret_chk;
        pthread_t name_th;
        char *thread_name = "NameThread";
        char get_name[32];
 
-       ret = pthread_create(&name_th, NULL, setgetname_thread, NULL);
-       if (ret != OK) {
-               printf("tc_pthread_pthread_setgetname_np FAIL : pthread_create\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_create(&name_th, NULL, setgetname_thread, NULL);
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
 
-       ret = pthread_setname_np(name_th, "NameThread");
-       if (ret != OK) {
-               printf("tc_pthread_pthread_setgetname_np FAIL : pthread_setname_np\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_setname_np(name_th, "NameThread");
+       TC_ASSERT_EQ("pthread_setname_np", ret_chk, OK);
 
-       ret = pthread_getname_np(name_th, get_name);
-       if (ret != OK) {
-               printf("tc_pthread_pthread_setgetname_np FAIL : pthread_getname_np, errno : %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_getname_np(name_th, get_name);
+       TC_ASSERT_EQ("pthread_getname_np", ret_chk, OK);
+       TC_ASSERT_EQ("pthread_getname_np", strcmp(get_name, thread_name), 0);
 
-       if (strcmp(get_name, thread_name) != 0) {
-               printf("tc_pthread_pthread_setgetname_np FAIL : not matched between set and get name\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = pthread_cancel(name_th);
+       TC_ASSERT_EQ("pthread_cancel", ret_chk, OK);
 
-       ret = pthread_cancel(name_th);
-       if (ret != OK) {
-               printf("tc_pthread_pthread_setgetname_np FAIL : pthread_cancel, returned value = %d\n", ret);
-               total_fail++;
-               RETURN_ERR;
-       }
-       ret = pthread_join(name_th, NULL);
-       if (ret != OK) {
-               printf("tc_pthread_pthread_setgetname_np FAIL : pthread_join, returned value = %d\n", ret);
-               total_fail++;
-               RETURN_ERR;
-       }
-       total_pass++;
-       printf("tc_pthread_pthread_setgetname_np PASS\n");
+       ret_chk = pthread_join(name_th, NULL);
+       TC_ASSERT_EQ("pthread_join", ret_chk, OK);
+
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index d573522..f771965 100644 (file)
@@ -220,11 +220,8 @@ static void tc_roundrobin_rr_pthread(void)
        int tc;
        int ret;
        ret = pthread_attr_set();
-       if (ret == ERROR) {
-               printf("tc_roundrobin_rr_pthread FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("pthread_attr_set", ret, ERROR);
+
        for (tc = 0; tc < TESTCASE; tc++) {
                int pthread_cnt;
                pthread_t pth[NTHREAD];
@@ -234,17 +231,11 @@ static void tc_roundrobin_rr_pthread(void)
                for (pthread_cnt = 0; pthread_cnt < NTHREAD; pthread_cnt++) {
                        param.sched_priority = priority[tc][pthread_cnt];
                        ret = pthread_attr_setschedparam(&attr, &param);
-                       if (ret != OK) {
-                               printf("tc_roundrobin_rr_pthread FAIL\n");
-                               total_fail++;
-                               RETURN_ERR;
-                       }
+                       TC_ASSERT_EQ("pthread_attr_setschedparam", ret, OK);
+
                        ret = pthread_create(&pth[pthread_cnt], &attr, pthread_func, NULL);
-                       if (ret != OK) {
-                               printf("tc_roundrobin_rr_pthread FAIL\n");
-                               total_fail++;
-                               RETURN_ERR;
-                       }
+                       TC_ASSERT_EQ("pthread_create ", ret, OK);
+
                        created++;
                        pid_prio[PIDHASH(pth[pthread_cnt])] = priority[tc][pthread_cnt];
                }
@@ -254,15 +245,10 @@ static void tc_roundrobin_rr_pthread(void)
                }
 
                ret = check_log();
-               if (ret != OK) {
-                       printf("tc_roundrobin_rr_pthread FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("check_log", ret, OK);
        }
 
-       printf("tc_roundrobin_rr_pthread PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 static void tc_roundrobin_rr_task(void)
@@ -270,11 +256,8 @@ static void tc_roundrobin_rr_task(void)
        int tc;
        int ret;
        ret = pthread_attr_set();
-       if (ret == ERROR) {
-               printf("tc_roundrobin_rr_task FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("pthread_attr_set", ret, ERROR);
+
        for (tc = 0; tc < TESTCASE; tc++) {
                int task_cnt;
                pid_t task_pid[NTHREAD];
@@ -283,19 +266,13 @@ static void tc_roundrobin_rr_task(void)
                sleep(1);
                for (task_cnt = 0; task_cnt < NTHREAD; task_cnt++) {
                        task_pid[task_cnt] = task_create("rrtask", priority[tc][task_cnt], 1024, task_func, NULL);
-                       if (task_pid[task_cnt] == ERROR) {
-                               printf("tc_roundrobin_rr_task FAIL\n");
-                               total_fail++;
-                               RETURN_ERR;
-                       }
+                       TC_ASSERT_NEQ("task_create", task_pid[task_cnt], ERROR);
+
                        created++;
                        param.sched_priority = priority[tc][task_cnt];
                        ret = sched_setscheduler(task_pid[task_cnt], SCHED_RR, &param);
-                       if (ret != OK) {
-                               printf("tc_roundrobin_rr_task FAIL\n");
-                               total_fail++;
-                               RETURN_ERR;
-                       }
+                       TC_ASSERT_EQ("sched_setscheduler", ret, OK);
+
                        pid_prio[PIDHASH(task_pid[task_cnt])] = priority[tc][task_cnt];
                }
 
@@ -309,15 +286,10 @@ static void tc_roundrobin_rr_task(void)
                }
 
                ret = check_log();
-               if (ret != OK) {
-                       printf("tc_roundrobin_rr_task FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("check_log", ret, OK);
        }
 
-       printf("tc_roundrobin_rr_task PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 static void tc_roundrobin_rr_taskNpthread(void)
@@ -325,11 +297,8 @@ static void tc_roundrobin_rr_taskNpthread(void)
        int tc;
        int ret;
        ret = pthread_attr_set();
-       if (ret == ERROR) {
-               printf("tc_roundrobin_rr_taskNpthread FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("pthread_attr_set", ret, ERROR);
+
        for (tc = 0; tc < TESTCASE; tc++) {
                int task_pid;
                FAR char *argv[2];
@@ -339,20 +308,14 @@ static void tc_roundrobin_rr_taskNpthread(void)
                logidx = 0;
                start = created = 0;
                sleep(1);
-               task_pid = task_create("rrtaskpth", priority[tc][0], 1024, taskNpthread_func, (FAR char *const *)argv);
-               if (task_pid == ERROR) {
-                       printf("tc_roundrobin_rr_taskNpthread FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               task_pid = task_create("rrtaskpth", priority[tc][0], 1024, taskNpthread_func, (FAR char * const *)argv);
+               TC_ASSERT_NEQ("task_create", task_pid, ERROR);
+
                created++;
                param.sched_priority = priority[tc][0];
                ret = sched_setscheduler(task_pid, SCHED_RR, &param);
-               if (ret != OK) {
-                       printf("tc_roundrobin_rr_taskNpthread FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("sched_setscheduler", ret, OK);
+
                pid_prio[PIDHASH(task_pid)] = priority[tc][0];
 
                if (task_pid != ERROR) {
@@ -363,15 +326,10 @@ static void tc_roundrobin_rr_taskNpthread(void)
                }
 
                ret = check_log();
-               if (ret != OK) {
-                       printf("tc_roundrobin_rr_taskNpthread FAIL\n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("check_log", ret, OK);
        }
 
-       printf("tc_roundrobin_rr_taskNpthread PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index ea51c5e..e17b372 100644 (file)
@@ -124,7 +124,7 @@ static void *threadfunc_callback(void *param)
 */
 static void tc_sched_sched_setget_scheduler_param(void)
 {
-       int ret_val = ERROR;
+       int ret_chk = ERROR;
        struct sched_param st_setparam;
        struct sched_param st_getparam;
        int loop_cnt = LOOPCOUNT;
@@ -133,44 +133,22 @@ static void tc_sched_sched_setget_scheduler_param(void)
 
        while (arr_idx < loop_cnt) {
                st_setparam.sched_priority = SCHED_PRIORITY;
-               ret_val = sched_setparam(getpid(), &st_setparam);
-               if (ret_val != OK) {
-                       printf("tc_sched_sched_setget_scheduler_param SETPARAM FAIL, Error No: %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
-
-               ret_val = sched_setscheduler(getpid(), sched_arr[arr_idx], &st_setparam);
-               if (ret_val == ERROR) {
-                       printf("tc_sched_sched_setget_scheduler_param SETSCHEDULER FAIL1 Error No: %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
-
-               /* ret_val should be SCHED set */
-               ret_val = sched_getscheduler(getpid());
-               if (ret_val != sched_arr[arr_idx]) {
-                       printf("tc_sched_sched_setget_scheduler_param FAIL, Error No: %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
-
-               ret_val = sched_getparam(getpid(), &st_getparam);
-               if (ret_val != OK) {
-                       printf("tc_sched_sched_setget_scheduler_param FAIL, Error No: %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
-
-               if (st_setparam.sched_priority != st_getparam.sched_priority) {
-                       printf("tc_sched_sched_setget_scheduler_param FAIL, Error No: %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               ret_chk = sched_setparam(getpid(), &st_setparam);
+               TC_ASSERT_EQ("sched_setparam", ret_chk, OK);
+
+               ret_chk = sched_setscheduler(getpid(), sched_arr[arr_idx], &st_setparam);
+               TC_ASSERT_NEQ("sched_setscheduler", ret_chk, ERROR);
+
+               /* ret_chk should be SCHED set */
+               ret_chk = sched_getscheduler(getpid());
+               TC_ASSERT_EQ("sched_getscheduler", ret_chk, sched_arr[arr_idx]);
+
+               ret_chk = sched_getparam(getpid(), &st_getparam);
+               TC_ASSERT_EQ("sched_getparam", ret_chk, OK);
+               TC_ASSERT_EQ("sched_getparam", st_setparam.sched_priority, st_getparam.sched_priority);
                arr_idx++;
        }
-       printf("tc_sched_sched_setget_scheduler_param PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -184,7 +162,7 @@ static void tc_sched_sched_setget_scheduler_param(void)
 */
 static void tc_sched_sched_rr_get_interval(void)
 {
-       int ret_val;
+       int ret_chk;
        struct timespec st_timespec1;
        struct timespec st_timespec2;
        st_timespec1.tv_sec = 0;
@@ -193,29 +171,21 @@ static void tc_sched_sched_rr_get_interval(void)
        st_timespec2.tv_sec = 0;
        st_timespec2.tv_nsec = -1;
        /* Values are filled in st_timespec structure to differentiate them with values overwritten by rr_interval */
-       ret_val = sched_rr_get_interval(0, &st_timespec1);
-       if (ret_val == ERROR || st_timespec1.tv_nsec < 0 || st_timespec1.tv_nsec >= 1000000000) {
-               printf("tc_sched_sched_rr_get_interval API FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = sched_rr_get_interval(0, &st_timespec1);
+       TC_ASSERT_NEQ("sched_rr_get_interval", ret_chk, ERROR);
+       TC_ASSERT_GEQ("sched_rr_get_interval", st_timespec1.tv_nsec, 0);
+       TC_ASSERT_LT("sched_rr_get_interval", st_timespec1.tv_nsec, 1000000000);
 
-       ret_val = sched_rr_get_interval(getpid(), &st_timespec2);
-       if (ret_val == ERROR || st_timespec2.tv_nsec < 0 || st_timespec2.tv_nsec >= 1000000000) {
-               printf("tc_sched_sched_rr_get_interval API FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = sched_rr_get_interval(getpid(), &st_timespec2);
+       TC_ASSERT_NEQ("sched_rr_get_interval", ret_chk, ERROR);
+       TC_ASSERT_GEQ("sched_rr_get_interval", st_timespec2.tv_nsec, 0);
+       TC_ASSERT_LT("sched_rr_get_interval", st_timespec2.tv_nsec, 1000000000);
 
        /* after sched_rr_get_interval() call, st_timespec structure should be overwritten with rr_interval values */
-       if ((st_timespec1.tv_sec - st_timespec2.tv_sec) != 0 || (st_timespec1.tv_nsec - st_timespec2.tv_nsec) != 0) {
-               printf("tc_sched_sched_rr_get_interval get interval FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sched_rr_get_interval", st_timespec1.tv_sec, st_timespec2.tv_sec);
+       TC_ASSERT_EQ("sched_rr_get_interval", st_timespec1.tv_nsec, st_timespec2.tv_nsec);
 
-       printf("tc_sched_sched_rr_get_interval PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -230,33 +200,20 @@ static void tc_sched_sched_rr_get_interval(void)
 */
 static void tc_sched_sched_yield(void)
 {
-       int ret_val = 0;
+       int ret_chk = 0;
+
+       ret_chk = pthread_create(&thread1, NULL, threadfunc_callback, NULL);
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
+       TC_ASSERT("sched_yield", g_pthread_callback);
+
+       ret_chk = pthread_create(&thread2, NULL, threadfunc_callback, NULL);
+       TC_ASSERT_EQ("pthread_create", ret_chk, OK);
+       TC_ASSERT("sched_yield", g_pthread_callback);
 
-       ret_val = pthread_create(&thread1, NULL, threadfunc_callback, NULL);
-       if (ret_val != OK) {
-               printf("tc_sched_sched_yield FAIL : pthread_create FAIL!\n");
-       }
-       if (g_pthread_callback == false) {
-               printf("tc_sched_sched_yield FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       ret_val = pthread_create(&thread2, NULL, threadfunc_callback, NULL);
-       if (ret_val != OK) {
-               printf("tc_sched_sched_yield FAIL : pthread_create FAIL!\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (g_pthread_callback == false) {
-               printf("tc_sched_sched_yield FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
        /* wait for threads to exit */
        pthread_join(thread1, 0);
        pthread_join(thread2, 0);
-       printf("tc_sched_sched_yield PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -274,39 +231,30 @@ static void tc_sched_sched_yield(void)
 #ifdef CONFIG_SCHED_HAVE_PARENT
 static void tc_sched_wait(void)
 {
-       int ret_val = 0;
+       int ret_chk;
        pid_t child1_pid;
        pid_t child2_pid;
        int status;
 
        /* creating new process */
-       child1_pid = task_create("sched1", SCHED_PRIORITY_DEFAULT, CONFIG_USERMAIN_STACKSIZE, function_wait, (char *const *)NULL);
-       child2_pid = task_create("sched2", SCHED_PRIORITY_DEFAULT, CONFIG_USERMAIN_STACKSIZE, function_waitlong, (char *const *)NULL);
-       if (child1_pid >= 0 && child2_pid >= 0) {
-               /* child which exits first is handled by wait, here child1_pid exits earlier. */
-               usleep(SLEEPVAL);
-               ret_val = wait(&status);        /* wait for child to exit, and store child's exit status */
-               if (ret_val == ERROR) {
-                       printf("tc_sched_wait FAIL, wait() didn't work Error No: %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
-               if (!(child1_pid == (pid_t)ret_val || child2_pid == (pid_t)ret_val)) {
-                       printf("tc_sched_wait FAIL, child_pid mismatched to retVal of wait() Error No: %d\n", errno);
-                       printf("retval is %d\n", ret_val);
-                       total_fail++;
-                       RETURN_ERR;
-               }
-       } else {
-               printf("tc_sched_wait FAIL: Child PID < 0. Could not be created, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       child1_pid = task_create("sched1", SCHED_PRIORITY_DEFAULT, CONFIG_USERMAIN_STACKSIZE, function_wait, (char * const *)NULL);
+       TC_ASSERT_GT("task_create", child1_pid, 0);
+
+       child2_pid = task_create("sched2", SCHED_PRIORITY_DEFAULT, CONFIG_USERMAIN_STACKSIZE, function_waitlong, (char * const *)NULL);
+       TC_ASSERT_GT("task_create", child2_pid, 0);
+
+       /* child which exits first is handled by wait, here child1_pid exits earlier. */
+       usleep(SLEEPVAL);
+
+       /* wait for child to exit, and store child's exit status */
+       ret_chk = wait(&status);
+       TC_ASSERT_NEQ("wait", ret_chk, ERROR);
+
+       TC_ASSERT("wait", child1_pid == (pid_t)ret_chk || child2_pid == (pid_t)ret_chk);
 
        /* wait for second child to exit */
        sleep(SEC_2);
-       printf("tc_sched_wait PASS \n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -321,30 +269,18 @@ static void tc_sched_wait(void)
 
 static void tc_sched_waitid(void)
 {
-       int ret_val = 0;
+       int ret_chk;
        pid_t child_pid;
        siginfo_t info;
-       child_pid = task_create("tc_waitid", SCHED_PRIORITY_DEFAULT, CONFIG_USERMAIN_STACKSIZE, function_waitid, (char *const *)NULL);
-
-       if (child_pid >= 0) {
-               ret_val = waitid(P_PID, child_pid, &info, WEXITED);
-               if (ret_val == ERROR) {
-                       printf("tc_sched_waitid FAIL: waitid fails, Error No: %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
-               if (info.si_pid != child_pid) {
-                       printf("tc_sched_waitid FAIL: pid mismatch, Error No: %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
-       } else {
-               printf("tc_sched_waitid FAIL: child could not be created, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_sched_waitid PASS\n");
-       total_pass++;
+
+       child_pid = task_create("tc_waitid", SCHED_PRIORITY_DEFAULT, CONFIG_USERMAIN_STACKSIZE, function_waitid, (char * const *)NULL);
+       TC_ASSERT_GT("task_create", child_pid, 0);
+
+       ret_chk = waitid(P_PID, child_pid, &info, WEXITED);
+       TC_ASSERT_NEQ("waitid", ret_chk, ERROR);
+       TC_ASSERT_EQ("waitid", info.si_pid, child_pid);
+
+       TC_SUCCESS_RESULT();
 }
 #endif
 
@@ -362,34 +298,19 @@ static void tc_sched_waitid(void)
 
 static void tc_sched_waitpid(void)
 {
-       int ret_val = ERROR;
+       int ret_chk;
        pid_t child_pid;
        int *status = (int *)malloc(sizeof(int));
-       child_pid = task_create("tc_waitpid", SCHED_PRIORITY_DEFAULT, CONFIG_USERMAIN_STACKSIZE, function_wait, (char *const *)NULL);
-
-       if (child_pid >= 0) {
-               ret_val = waitpid(child_pid, status, 0);
-               if (ret_val == ERROR) {
-                       printf("tc_sched_waitpid FAIL: waitpid fails, Error No: %d\n", errno);
-                       free(status);
-                       total_fail++;
-                       RETURN_ERR;
-               }
-               if (ret_val != child_pid) {
-                       printf("tc_sched_waitpid FAIL, child_pid mismatched to retVal of waitpid() Error No: %d\n", errno);
-                       free(status);
-                       total_fail++;
-                       RETURN_ERR;
-               }
-       } else {
-               printf("tc_sched_waitpid FAIL: Child PID Could not be created, Error No: %d\n", errno);
-               free(status);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_sched_waitpid PASS\n");
-       total_pass++;
+
+       child_pid = task_create("tc_waitpid", SCHED_PRIORITY_DEFAULT, CONFIG_USERMAIN_STACKSIZE, function_wait, (char * const *)NULL);
+       TC_ASSERT_GT("task_create", child_pid, 0);
+
+       ret_chk = waitpid(child_pid, status, 0);
+       TC_ASSERT_NEQ_CLEANUP("waitpid", ret_chk, ERROR, errno, TC_FREE_MEMORY(status));
+       TC_ASSERT_EQ_CLEANUP("waitpid", ret_chk, child_pid, errno, free(status));
+
        free(status);
+       TC_SUCCESS_RESULT();
 }
 #endif
 
@@ -406,20 +327,13 @@ static void tc_sched_sched_gettcb(void)
 {
        struct tcb_s *st_tcb;
        pid_t child_pid;
-       child_pid = task_create("tc_gettcb", SCHED_PRIORITY_DEFAULT, CONFIG_USERMAIN_STACKSIZE, function_wait, (char *const *)NULL);
+       child_pid = task_create("tc_gettcb", SCHED_PRIORITY_DEFAULT, CONFIG_USERMAIN_STACKSIZE, function_wait, (char * const *)NULL);
        st_tcb = sched_gettcb(child_pid);
-       if (st_tcb == NULL) {
-               printf("tc_sched_sched_gettcb API FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (st_tcb->pid != child_pid) {
-               printf("tc_sched_sched_gettcb FAIL,child_pid mismatch with st_tcb->pid Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_sched_sched_gettcb PASS\n");
-       total_pass++;
+
+       TC_ASSERT_NOT_NULL("sched_gettcb", st_tcb);
+       TC_ASSERT_EQ("sched_gettcb", st_tcb->pid, child_pid);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -435,78 +349,48 @@ static void tc_sched_sched_gettcb(void)
 
 static void tc_sched_sched_lock_unlock(void)
 {
-       int ret_val = ERROR;
+       int ret_chk = ERROR;
        int cntlock;
        struct tcb_s *st_tcb = NULL;
 
        st_tcb = sched_self();
-       if (st_tcb == NULL) {
-               printf("tc_sched_sched_lock_unlock LOCK FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("sched_self", st_tcb);
+
        cntlock = st_tcb->lockcount;
-       ret_val = sched_lock();
-       if (ret_val == ERROR) {
-               printf("tc_sched_sched_lock_unlock LOCK FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+
+       ret_chk = sched_lock();
+       TC_ASSERT_NEQ("sched_lock", ret_chk, ERROR);
+
        /* after sched_lock, lock count gets incremented */
-       ret_val = cntlock;
+       ret_chk = cntlock;
        cntlock = st_tcb->lockcount;
-       if (ret_val != cntlock - 1) {
-               printf("tc_sched_sched_lock_unlock Lock FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sched_lock", ret_chk, cntlock - 1);
+
+       ret_chk = sched_lock();
+       TC_ASSERT_NEQ("sched_lock", ret_chk, ERROR);
 
-       ret_val = sched_lock();
-       if (ret_val == ERROR) {
-               printf("tc_sched_sched_lock_unlock Lock FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
        /* after sched_lock, lock count gets incremented */
-       ret_val = cntlock;
+       ret_chk = cntlock;
        cntlock = st_tcb->lockcount;
-       if (ret_val != cntlock - 1) {
-               printf("tc_sched_sched_lock_unlock Lock FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sched_lock", ret_chk, cntlock - 1);
+
+       ret_chk = sched_unlock();
+       TC_ASSERT_NEQ("sched_unlock", ret_chk, ERROR);
 
-       ret_val = sched_unlock();
-       if (ret_val == ERROR) {
-               printf("tc_sched_sched_lock_unlock UnLock FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
        /* after sched_unlock, lock count gets decremented */
-       ret_val = cntlock;
+       ret_chk = cntlock;
        cntlock = st_tcb->lockcount;
-       if (ret_val != cntlock + 1) {
-               printf("tc_sched_sched_lock_unlock UnLock FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sched_unlock", ret_chk, cntlock + 1);
+
+       ret_chk = sched_unlock();
+       TC_ASSERT_NEQ("sched_unlock", ret_chk, ERROR);
 
-       ret_val = sched_unlock();
-       if (ret_val == ERROR) {
-               printf("tc_sched_sched_lock_unlock UnLock FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
        /* after sched_unlock, lock count gets decremented */
-       ret_val = cntlock;
+       ret_chk = cntlock;
        cntlock = st_tcb->lockcount;
-       if (ret_val != cntlock + 1) {
-               printf("tc_sched_sched_lock_unlock UnLock FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_sched_sched_lock_unlock PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("sched_unlock", ret_chk, cntlock + 1);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -525,25 +409,14 @@ static void tc_sched_sched_self(void)
        /* get process id */
 
        st_tcbpid = sched_self();
-       if (st_tcbpid == NULL) {
-               printf("tc_sched_sched_self sched_gettcb FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("sched_self", st_tcbpid);
+
        /* should return tcb for current process */
        st_tcbself = sched_self();
-       if (st_tcbself == NULL) {
-               printf("tc_sched_sched_self API FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (st_tcbself->pid != st_tcbpid->pid) {
-               printf("tc_sched_sched_self FAIL, pid's not matched Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_sched_sched_self PASS\n");
-       total_pass++;
+       TC_ASSERT_NOT_NULL("sched_self", st_tcbself);
+       TC_ASSERT_EQ("sched_self", st_tcbself->pid, st_tcbpid->pid);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -561,13 +434,9 @@ static void tc_sched_sched_verifytcb(void)
        struct tcb_s *st_tcb;
        st_tcb = sched_self();
        ret_chk = sched_verifytcb(st_tcb);
-       if (ret_chk == false) {
-               printf("tc_sched_sched_verifytcb FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_sched_sched_verifytcb PASS\n");
-       total_pass++;
+       TC_ASSERT("verfiytcb fail", ret_chk);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -585,15 +454,12 @@ static void tc_sched_sched_foreach(void)
        struct tcb_s *st_tcb;
        st_tcb = sched_self();
        g_task_pid = st_tcb->pid;
+
        /* provides TCB to user callback function "sched_foreach_callback" */
        sched_foreach(sched_foreach_callback, NULL);
-       if (g_callback != true) {
-               printf("tc_sched_sched_foreach FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_sched_sched_foreach PASS\n");
-       total_pass++;
+       TC_ASSERT("sched_foreach", g_callback);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -608,50 +474,32 @@ static void tc_sched_sched_foreach(void)
 
 static void tc_sched_sched_lockcount(void)
 {
-       int ret_val = ERROR;
+       int ret_chk = ERROR;
        int prev_cnt;
        int cur_cnt;
        struct tcb_s *st_tcb = NULL;
 
        st_tcb = sched_self();
-       if (st_tcb == NULL) {
-               printf("tc_sched_sched_lockcount LOCK FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("sched_self", st_tcb);
+
        prev_cnt = sched_lockcount();
-       ret_val = sched_lock();
-       if (ret_val == ERROR) {
-               printf("tc_sched_sched_lockcount FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = sched_lock();
+       TC_ASSERT_NEQ("sched_lock", ret_chk, ERROR);
+
        /* after sched_lock, lock count gets incremented */
        cur_cnt = sched_lockcount();
-       if (prev_cnt != cur_cnt-1) {
-               printf("tc_sched_sched_lockcount FAIL: not matched\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sched_lockcount", prev_cnt, cur_cnt - 1);
 
        prev_cnt = cur_cnt;
 
-       ret_val = sched_unlock();
-       if (ret_val == ERROR) {
-               printf("tc_sched_sched_lockcount FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_chk = sched_unlock();
+       TC_ASSERT_NEQ("sched_unlock", ret_chk, ERROR);
+
        /* after sched_unlock, lock count gets decremented */
        cur_cnt = sched_lockcount();
-       if (prev_cnt != cur_cnt+1) {
-               printf("tc_sched_sched_lockcount FAIL: not matched\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sched_lockcount", prev_cnt, cur_cnt + 1);
 
-       printf("tc_sched_sched_lockcount PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -669,14 +517,9 @@ static void tc_sched_sched_getstreams(void)
        struct streamlist *stream;
 
        stream = sched_getstreams();
-       if (stream == NULL) {
-               printf("tc_sched_sched_getstreams FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("sched_getstreams", stream);
 
-       printf("tc_sched_sched_getstreams PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index 05229c9..fac769e 100644 (file)
@@ -48,28 +48,22 @@ static void *producer_func(void *arg)
        for (index = 0; index < g_loop_cnt; index++) {
                ret_val = sem_wait(&g_empty);
                if (ret_val == ERROR) {
-                       printf("tc_semaphore_sem_init_post_wait FAIL, Error No: %d\n", errno);
-                       total_fail++;
-                       return NULL;
+                       pthread_exit("sem_wait(&g_empty)");
                }
+
                ret_val = sem_wait(&g_mutex);
                if (ret_val == ERROR) {
-                       printf("tc_semaphore_sem_init_post_wait FAIL, Error No: %d\n", errno);
-                       total_fail++;
-                       return NULL;
+                       pthread_exit("sem_wait(&g_mutex)");
                }
-               //printf("Producer val %d\n", index);
+
                ret_val = sem_post(&g_mutex);
                if (ret_val == ERROR) {
-                       printf("tc_semaphore_sem_init_post_wait FAIL, Error No: %d\n", errno);
-                       total_fail++;
-                       return NULL;
+                       pthread_exit("sem_post(&g_mutex)");
                }
+
                ret_val = sem_post(&g_full);
                if (ret_val == ERROR) {
-                       printf("tc_semaphore_sem_init_post_wait FAIL, Error No: %d\n", errno);
-                       total_fail++;
-                       return NULL;
+                       pthread_exit("sem_post(&g_full)");
                }
        }
        pthread_exit(NULL);
@@ -88,27 +82,22 @@ static void *consumer_func(void *arg)
        for (index = 0; index < g_loop_cnt; index++) {
                ret_val = sem_wait(&g_full);
                if (ret_val == ERROR) {
-                       printf("tc_semaphore_sem_init_post_wait FAIL, Error No: %d\n", errno);
-                       total_fail++;
-                       return NULL;
+                       pthread_exit("sem_wait(&g_full)");
                }
+
                ret_val = sem_wait(&g_mutex);
                if (ret_val == ERROR) {
-                       printf("tc_semaphore_sem_init_post_wait FAIL, Error No: %d\n", errno);
-                       total_fail++;
-                       return NULL;
+                       pthread_exit("sem_wait(&g_mutex)");
                }
+
                ret_val = sem_post(&g_mutex);
                if (ret_val == ERROR) {
-                       printf("tc_semaphore_sem_init_post_wait FAIL, Error No: %d\n", errno);
-                       total_fail++;
-                       return NULL;
+                       pthread_exit("sem_post(&g_mutex)");
                }
+
                ret_val = sem_post(&g_empty);
                if (ret_val == ERROR) {
-                       printf("tc_semaphore_sem_init_post_wait FAIL, Error No: %d\n", errno);
-                       total_fail++;
-                       return NULL;
+                       pthread_exit("sem_post(&g_empty)");
                }
        }
        pthread_exit(NULL);
@@ -126,60 +115,38 @@ static void *consumer_func(void *arg)
 */
 static void tc_semaphore_sem_init_post_wait(void)
 {
-       int ret_val = ERROR;
+       int ret_val;
+       pthread_addr_t *pexit_value = NULL;
        pthread_t pid;
        pthread_t cid;
 
        ret_val = sem_init(&g_empty, g_pshared, g_count);
-       if (ret_val == ERROR) {
-               printf("tc_semaphore_sem_init_post_wait FAIL : sem_init FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("sem_init", ret_val, ERROR);
+
        ret_val = sem_init(&g_full, g_pshared, 0);
-       if (ret_val == ERROR) {
-               printf("tc_semaphore_sem_init_post_wait FAIL : sem_init FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("sem_init", ret_val, ERROR);
+
        ret_val = sem_init(&g_mutex, g_pshared, g_count);
-       if (ret_val == ERROR) {
-               printf("tc_semaphore_sem_init_post_wait FAIL : sem_init FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("sem_init", ret_val, ERROR);
 
        ret_val = pthread_create(&pid, NULL, producer_func, NULL);
-       if (ret_val != OK) {
-               printf("tc_semaphore_sem_init_post_wait, pthread_create FAIL Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_create", ret_val, OK);
+
        ret_val = pthread_create(&cid, NULL, consumer_func, NULL);
-       if (ret_val != OK) {
-               printf("tc_semaphore_sem_init_post_wait, pthread_create FAIL Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pthread_create", ret_val, OK);
 
-       ret_val = pthread_join(pid, NULL);
-       if (ret_val != OK) {
-               printf("tc_semaphore_sem_init_post_wait, pthread_join FAIL Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       ret_val = pthread_join(cid, NULL);
-       if (ret_val != OK) {
-               printf("tc_semaphore_sem_init_post_wait, pthread_join FAIL Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       ret_val = pthread_join(pid, &pexit_value);
+       TC_ASSERT_EQ("pthread_join", ret_val, OK);
+       TC_ASSERT_EQ("pthread_join", pexit_value, NULL);
+
+       ret_val = pthread_join(cid, &pexit_value);
+       TC_ASSERT_EQ("pthread_join", ret_val, OK);
+       TC_ASSERT_EQ("pthread_join", pexit_value, NULL);
 
-       printf("tc_semaphore_sem_init_post_wait PASS\n");
-       total_pass++;
        sem_destroy(&g_empty);
        sem_destroy(&g_full);
        sem_destroy(&g_mutex);
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -202,40 +169,22 @@ static void tc_semaphore_sem_trywait(void)
        sem_t sem_name;
 
        ret_val = sem_init(&sem_name, g_pshared, 0);
-       if (ret_val == ERROR) {
-               printf("tc_semaphore_sem_trywait FAIL : sem_init FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("sem_init", ret_val, ERROR);
 
        /* semname count is 0, sem_trywait will not block, but return immediately with error */
        ret_val = sem_trywait(&sem_name);
-       if (ret_val != ERROR) {
-               printf("tc_semaphore_sem_trywait FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sem_trywait", ret_val, ERROR);
        sem_destroy(&sem_name);
 
        ret_val = sem_init(&sem_name, g_pshared, g_count);
-       if (ret_val == ERROR) {
-               printf("tc_semaphore_sem_trywait FAIL : sem_init FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("sem_init", ret_val, ERROR);
+
        ret_val = sem_trywait(&sem_name);
-       if (ret_val == ERROR) {
-               printf("tc_semaphore_sem_trywait FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("sem_trywait", ret_val, ERROR);
 
        ret_val = sem_post(&sem_name);
-       if (ret_val == ERROR) {
-               printf("tc_semaphore_sem_trywait FAIL : sem_post Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("sem_post", ret_val, ERROR);
+
        /* locking semaphore to test sem_trywait */
        ret_val = sem_wait(&sem_name);
        if (ret_val == ERROR) {
@@ -243,16 +192,10 @@ static void tc_semaphore_sem_trywait(void)
        } else {
                /* locking semaphore in locked state using sem_trywait will return ERROR on pass */
                ret_val = sem_trywait(&sem_name);
-               if (ret_val != ERROR) {
-                       printf("tc_semaphore_sem_trywait FAIL \n");
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("sem_trywait", ret_val, ERROR);
        }
-
-       printf("tc_semaphore_sem_trywait PASS \n");
-       total_pass++;
        sem_destroy(&sem_name);
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -274,44 +217,24 @@ static void tc_semaphore_sem_timedwait(void)
        struct timespec st_final_time;
        sem_t sem_name;
        ret_val = sem_init(&sem_name, g_pshared, g_count);
-       if (ret_val == ERROR) {
-               printf("tc_semaphore_sem_timedwait FAIL : sem_init FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("sem_init", ret_val, ERROR);
 
        ret_val = clock_gettime(CLOCK_REALTIME, &st_init_time);
-       if (ret_val != OK) {
-               printf("tc_semaphore_sem_timedwait FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("clock_gettime", ret_val, OK);
 
        st_set_time.tv_sec = st_init_time.tv_sec + SEC_1;
 
        ret_val = sem_timedwait(&sem_name, &st_set_time);
-       if (ret_val == ERROR) {
-               printf("tc_semaphore_sem_timedwait FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("sem_timedwait", ret_val, ERROR);
 
        ret_val = clock_gettime(CLOCK_REALTIME, &st_final_time);
-       if (ret_val != OK) {
-               printf("tc_semaphore_sem_timedwait FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("clock_gettime", ret_val, OK);
+
        if (g_count == 0) {
-               if (st_init_time.tv_sec + SEC_1 != st_final_time.tv_sec) {
-                       printf("tc_semaphore_sem_timedwait FAIL, Error No: %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("sem_timedwait", st_init_time.tv_sec + SEC_1, st_final_time.tv_sec);
        }
-       printf("tc_semaphore_sem_timedwait PASS \n");
-       total_pass++;
        sem_destroy(&sem_name);
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -328,21 +251,14 @@ static void tc_semaphore_sem_destroy(void)
        int ret_val = ERROR;
        sem_t sem_name;
        ret_val = sem_init(&sem_name, g_pshared, g_count);
-       if (ret_val == ERROR) {
-               printf("tc_semaphore_sem_destroy FAIL : sem_init FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("sem_init", ret_val, ERROR);
+
        ret_val = sem_destroy(&sem_name);
-       if (ret_val != OK) {
-               printf("tc_semaphore_sem_destroy FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sem_destroy", ret_val, OK);
+
        /* The effect of subsequent use of the semaphore sem is undefined until sem is re-initialised
           by another call to sem_init(). */
-       printf("tc_semaphore_sem_destroy PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT()
 }
 
 /****************************************************************************
index a8d4c36..5bd043d 100644 (file)
@@ -39,8 +39,9 @@
 #endif
 #define SIGKILL 9
 #define SIGTERM 15
-#define SEC_2 2
 #define SEC_1 1
+#define SEC_2 2
+#define SEC_3 3
 #define SEC_5 5
 #define VAL_100 100
 
@@ -55,11 +56,8 @@ static bool g_sig_handle = false;
 */
 static void sigquit_handler(int signo)
 {
-       if (signo != SIGQUIT) {
-               printf("tc_signal_sig_pending_procmask_emptyset_addset FAIL sigquit_handler error\n");
-               total_fail++;
-       }
        g_sig_handle = true;
+       TC_ASSERT_EQ("sigquit_handler", signo, SIGQUIT);
 }
 
 /**
@@ -69,11 +67,8 @@ static void sigquit_handler(int signo)
 */
 static void sigint_handler(int signo, siginfo_t *info, void *ctx)
 {
-       if (info->si_value.sival_int != VAL_100) {
-               printf("tc_signal_sigqueue FAIL sigint_handler error\n");
-               total_fail++;
-       }
        g_sig_handle = true;
+       TC_ASSERT_EQ("sigint handler", info->si_value.sival_int, VAL_100);
 }
 
 /**
@@ -130,32 +125,24 @@ void sigaction_handler(int signo)
 */
 static void tc_signal_sigwaitinfo(void)
 {
-       int ret;
+       int ret_chk;
        struct siginfo value;
        sigset_t sigset;
 
        g_sig_pid = getpid();
 
-       task_create("sigwaitinfo", SCHED_PRIORITY_DEFAULT, 512, sigusr1_func, (char *const *)NULL);
+       task_create("sigwaitinfo", SCHED_PRIORITY_DEFAULT, 512, sigusr1_func, (char * const *)NULL);
 
        /* Wait for a signal */
 
        (void)sigemptyset(&sigset);
        (void)sigaddset(&sigset, SIGUSR1);
        value.si_value.sival_int = -1;
-       ret = sigwaitinfo(&sigset, &value);
-       if (ret != SIGUSR1) {
-               printf("tc_signal_sigwaitinfo FAIL: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (value.si_value.sival_int < 0) {
-               printf("tc_signal_sigwaitinfo FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_signal_sigwaitinfo PASS\n");
-       total_pass++;
+       ret_chk = sigwaitinfo(&sigset, &value);
+       TC_ASSERT_EQ("sigwaitinfo", ret_chk, SIGUSR1);
+       TC_ASSERT_GEQ("sigwaitinfo", value.si_value.sival_int, 0);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -183,37 +170,20 @@ static void tc_signal_sigaction(void)
        sigemptyset(&st_act.sa_mask);
 
        ret_chk = sigaction(SIGINT, &st_act, &st_oact);
-       if (ret_chk < 0) {
-               printf("tc_signal_sigaction FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_GEQ("sigaction", ret_chk, 0);
 
        st_act.sa_handler = NULL;
 
        ret_chk = sigaction(SIGINT, &st_oact, &st_act);
-       if (ret_chk < 0) {
-               printf("tc_signal_sigaction FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_GEQ("sigaction", ret_chk, 0);
 
-       if (st_act.sa_handler != sigaction_handler) {
-               printf("tc_signal_sigaction FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sigaction", st_act.sa_handler, sigaction_handler);
 
        /* make sure action is not changed */
        sigact_after = sig_findaction(sched_self(), SIGINT);
-       if (sigact_before != sigact_after) {
-               printf("tc_signal_sigaction FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sig_findaction", sigact_before, sigact_after);
 
-       printf("tc_signal_sigaction PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -236,28 +206,17 @@ static void tc_signal_kill(void)
        if (pid != 0) {
                ret_chk = kill(pid, SIGHUP);
                sleep(SEC_1);
-               if (ret_chk == ERROR) {
-                       printf("tc_signal_kill FAIL : not able to kill() SIGHUP Error is %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_NEQ("kill", ret_chk, ERROR);
+
                ret_chk = kill(pid, SIGINT);
                sleep(SEC_1);
-               if (ret_chk == ERROR) {
-                       printf("tc_signal_kill FAIL : not able to kill() SIGINT Error is %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_NEQ("kill", ret_chk, ERROR);
+
                ret_chk = kill(pid, SIGQUIT);
                sleep(SEC_1);
-               if (ret_chk == ERROR) {
-                       printf("tc_signal_kill FAIL : not able to kill SIGQUIT Error is %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_NEQ("kill", ret_chk, ERROR);
        }
-       printf("tc_signal_kill PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -285,20 +244,11 @@ static void tc_signal_nanosleep(void)
        clock_gettime(clock_id, &st_init_timespec);
 
        ret_chk = nanosleep(&st_timespec, NULL);
-       if (ret_chk == ERROR) {
-               printf("tc_signal_nanosleep FAIL, Error: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("nanosleep", ret_chk, ERROR);
 
        clock_gettime(clock_id, &st_final_timespec);
-       if (st_final_timespec.tv_sec - st_init_timespec.tv_sec != st_timespec.tv_sec) {
-               printf("tc_signal_nanosleep FAIL: Time mismatch\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_signal_nanosleep PASS\n");
-       total_pass++;
+       TC_ASSERT_EQ("clock_gettime", st_final_timespec.tv_sec - st_init_timespec.tv_sec, st_timespec.tv_sec);
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -326,46 +276,30 @@ static void tc_signal_pause(void)
        /* Save the current sigprocmask */
 
        ret_chk = sigprocmask(SIG_SETMASK, &newmask, &saved);
-       if (ret_chk != OK) {
-               printf("tc_signal_pause FAIL : sigprocmask errno:%d\n", get_errno());
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sigprocmask", ret_chk, OK);
 
        clock_gettime(clock_id, &st_init_timespec);
-       task_create("sigpause1", SCHED_PRIORITY_DEFAULT, 512, sigusr1_func, (char *const *)NULL);
-       task_create("sigpause2", SCHED_PRIORITY_DEFAULT, 512, sigusr2_func, (char *const *)NULL);
+       task_create("sigpause1", SCHED_PRIORITY_DEFAULT, 512, sigusr1_func, (char * const *)NULL);
+       task_create("sigpause2", SCHED_PRIORITY_DEFAULT, 512, sigusr2_func, (char * const *)NULL);
 
        /* Wait for a signal */
 
        ret_chk = pause();
-       if (ret_chk != ERROR || get_errno() != EINTR) {
-               printf("tc_signal_pause FAIL : pause errno:%d\n", get_errno());
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("pause", ret_chk, ERROR);
+       TC_ASSERT_EQ("pause", get_errno(), EINTR);
 
        clock_gettime(clock_id, &st_final_timespec);
        if (st_final_timespec.tv_sec - st_init_timespec.tv_sec < SEC_5) {
                ret_chk = sigprocmask(SIG_SETMASK, &saved, NULL);
-               if (ret_chk != OK) {
-                       printf("tc_signal_pause FAIL : sigprocmask errno:%d\n", get_errno());
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("sigprocmask", ret_chk, OK);
        }
 
        /* Restore sigprocmask */
 
        ret_chk = sigprocmask(SIG_SETMASK, &saved, NULL);
-       if (ret_chk != OK) {
-               printf("tc_signal_pause FAIL : sigprocmask errno:%d\n", get_errno());
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sigprocmask", ret_chk, OK);
 
-       printf("tc_signal_pause PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
        return;
 }
 
@@ -395,37 +329,38 @@ static void tc_signal_sigsuspend(void)
        /* Save the current sigprocmask */
 
        ret_chk = sigprocmask(SIG_SETMASK, &newmask, &saved);
-       if (ret_chk != OK) {
-               tckndbg("ERROR sigprocmask failed: %d\n", get_errno());
-               goto errout;
+       TC_ASSERT_EQ_CLEANUP("sigprocmask", ret_chk, OK, errno, {
+               tckndbg("ERROR sigprocmask failed: %d\n", get_errno()); goto errout;
        }
+                                               );
 
        clock_gettime(clock_id, &st_init_timespec);
-       task_create("sigsuspend1", SCHED_PRIORITY_DEFAULT, 512, sigusr1_func, (char *const *)NULL);
-       task_create("sigsuspend2", SCHED_PRIORITY_DEFAULT, 512, sigusr2_func, (char *const *)NULL);
+       task_create("sigsuspend1", SCHED_PRIORITY_DEFAULT, 512, sigusr1_func, (char * const *)NULL);
+       task_create("sigsuspend2", SCHED_PRIORITY_DEFAULT, 512, sigusr2_func, (char * const *)NULL);
 
        /* Wait for a signal */
 
        ret_chk = sigsuspend(&newmask);
-       if (ret_chk != ERROR) {
-               tckndbg("ERROR sigsuspend failed: %d\n", get_errno());
-               goto errout_with_mask;
+       TC_ASSERT_EQ_CLEANUP("sigsuspend", ret_chk, ERROR, get_errno(), {
+               tckndbg("ERROR sigsuspend failed: %d\n", get_errno()); goto errout_with_mask;
        }
+                                               );
+
        clock_gettime(clock_id, &st_final_timespec);
-       if (st_final_timespec.tv_sec - st_init_timespec.tv_sec < SEC_5) {
+       TC_ASSERT_GEQ_CLEANUP("clock_gettime", st_final_timespec.tv_sec - st_init_timespec.tv_sec, SEC_5, "Difference less than 5", {
                goto errout_with_mask;
        }
+                                                );
 
        /* Restore sigprocmask */
 
        ret_chk = sigprocmask(SIG_SETMASK, &saved, NULL);
-       if (ret_chk != OK) {
-               tckndbg("ERROR sigprocmask failed: %d\n", get_errno());
-               goto errout;
+       TC_ASSERT_EQ_CLEANUP("sigprocmask", ret_chk, OK, errno, {
+               tckndbg("ERROR sognprocmask failed: %d\n", get_errno()); goto errout;
        }
+                                               );
 
-       printf("tc_signal_sigsuspend PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
        return;
 
 errout_with_mask:
@@ -435,8 +370,6 @@ errout_with_mask:
        sigprocmask(SIG_SETMASK, &saved, NULL);
 errout:
 
-       printf("tc_signal_sigsuspend FAIL\n");
-       total_fail++;
        RETURN_ERR;
 }
 
@@ -471,65 +404,38 @@ static void tc_signal_sig_pending_procmask_emptyset_addset(void)
        memset(&st_act, 0, sizeof(st_act));
        st_act.sa_handler = sigquit_handler;
 
-       if (sigaction(SIGQUIT, &st_act, &st_oact)) {
-               printf("tc_signal_sig_pending_procmask_emptyset_addset FAIL sigaction error\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT("sigaction", !(sigaction(SIGQUIT, &st_act, &st_oact)));
+
        sigemptyset(&st_newmask);
        sigaddset(&st_newmask, SIGQUIT);
 
        ret_chk = sigprocmask(SIG_BLOCK, &st_newmask, &st_oldmask);
-       if (ret_chk < 0) {
-               printf("tc_signal_sig_pending_procmask_emptyset_addset FAIL SIG_BLOCK error\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_GEQ("sigprocmask", ret_chk, 0);
 
        nanosleep(&st_timespec, NULL);
 
        kill(pid, SIGQUIT);
        /* to call the handler function for verifying the sigpromask */
        ret_chk = sigprocmask(SIG_SETMASK, &st_oldmask, NULL);
-       if (ret_chk < 0) {
-               printf("tc_signal_sig_pending_procmask_emptyset_addset FAIL SIG_SETMASK error\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_GEQ("sigprocmask", ret_chk, 0);
 
        st_timespec.tv_sec = 1;
 
        nanosleep(&st_timespec, NULL);
 
        ret_chk = sigprocmask(SIG_UNBLOCK, &st_oldmask, NULL);
-       if (ret_chk < 0) {
-               printf("tc_signal_sig_pending_procmask_emptyset_addset FAIL SIG_UNBLOCK error\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_GEQ("sigprocmask", ret_chk, 0);
 
        ret_chk = sigpending(&st_pendmask);
-       if (ret_chk < 0) {
-               printf("tc_signal_sig_pending_procmask_emptyset_addset FAIL sigpending error\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_GEQ("sigpending", ret_chk, 0);
 
        nanosleep(&st_timespec, NULL);
 
-       if (!g_sig_handle) {
-               printf("tc_signal_sig_pending_procmask_emptyset_addset FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT("nanosleep", g_sig_handle);
 
-       if (sigaction(SIGQUIT, &st_oact, NULL)) {
-               printf("tc_signal_sig_pending_procmask_emptyset_addset FAIL sigaction error\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_signal_sig_pending_procmask_emptyset_addset PASS\n");
-       total_pass++;
+       TC_ASSERT("sigaction", !sigaction(SIGQUIT, &st_oact, NULL));
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -552,34 +458,21 @@ static void tc_signal_sigqueue(void)
        sigemptyset(&st_act.sa_mask);
        /*information transfer switch */
        st_act.sa_flags = SA_SIGINFO;
-       if (sigaction(SIGINT, &st_act, &st_oact) == ERROR) {
-               printf("tc_signal_sigqueue error %d \n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("sigaction", sigaction(SIGINT, &st_act, &st_oact), ERROR);
 
        sleep(SEC_2);
 
        union sigval mysigval;
        mysigval.sival_int = VAL_100;
-       if (sigqueue(getpid(), SIGINT, mysigval) == ERROR) {
-               printf("tc_signal_sigqueue error %d \n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("sigqueue", sigqueue(getpid(), SIGINT, mysigval), ERROR);
+
        sleep(SEC_1);
-       if (!g_sig_handle) {
-               printf("tc_signal_sigqueue FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (sigaction(SIGINT, &st_oact, NULL) == ERROR) {
-               printf("tc_signal_sigqueue error %d \n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_signal_sigqueue PASS\n");
-       total_pass++;
+
+       TC_ASSERT("sigqueue", g_sig_handle);
+
+       TC_ASSERT_NEQ("sigaction", sigaction(SIGINT, &st_oact, NULL), ERROR);
+
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -596,54 +489,35 @@ static void tc_signal_sigqueue(void)
 
 static void tc_signal_sigtimedwait(void)
 {
-       int ret;
+       int ret_chk;
        struct siginfo value;
        sigset_t sigset;
-       /* ssize_t nread; */
        struct timespec st_timeout;
-       struct timespec st_timespec;
-
-       st_timeout.tv_sec = SEC_5;
-       st_timeout.tv_nsec = 0;
-
-       st_timespec.tv_sec = SEC_2;
-       st_timespec.tv_nsec = 0;
-
        struct timespec st_init_timespec;
        struct timespec st_final_timespec;
        clockid_t clock_id = CLOCK_REALTIME;
 
-       clock_gettime(clock_id, &st_init_timespec);
-
        g_sig_pid = getpid();
+       st_timeout.tv_sec = SEC_5;
+       st_timeout.tv_nsec = 0;
+       value.si_value.sival_int = -1;
 
-       task_create("tc_sig_time", SCHED_PRIORITY_DEFAULT, 512, sigusr1_func, (char *const *)NULL);
+       /* Set signal set */
 
-       /* Wait for a signal */
-       (void)sigemptyset(&sigset);
-       (void)sigaddset(&sigset, SIGUSR1);
+       sigemptyset(&sigset);
+       sigaddset(&sigset, SIGUSR1);
+
+       task_create("tc_sig_time", SCHED_PRIORITY_DEFAULT - 1, 512, sigusr1_func, (char * const *)NULL);
+
+       clock_gettime(clock_id, &st_init_timespec);
+       ret_chk = sigtimedwait(&sigset, &value, &st_timeout);
+       TC_ASSERT_NEQ("sigtimedwait", ret_chk, ERROR);
 
-       value.si_value.sival_int = -1;
-       ret = sigtimedwait(&sigset, &value, &st_timeout);
-       if (ret < 0) {
-               fprintf(stderr, "ERROR: sigwaitinfo() failed: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
        clock_gettime(clock_id, &st_final_timespec);
-       if (st_final_timespec.tv_sec - st_init_timespec.tv_sec != st_timespec.tv_sec) {
-               printf("tc_signal_sigtimedwait waittime FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (value.si_value.sival_int < 0) {
-               printf("tc_signal_sigtimedwait FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_LEQ("clock_gettime", st_final_timespec.tv_sec - st_init_timespec.tv_sec, SEC_3);
 
-       printf("tc_signal_sigtimedwait PASS\n");
-       total_pass++;
+       TC_ASSERT_GEQ("sigtimedwait", value.si_value.sival_int, 0);
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -666,35 +540,20 @@ static void tc_signal_sighold_sigrelse(void)
        org_set = cur_tcb->sigprocmask;
 
        ret_chk = sighold(SIGUSR1);
-       if (ret_chk != OK) {
-               printf("tc_signal_sighold_sigrelse FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+
+       TC_ASSERT_EQ("sighold", ret_chk, OK);
 
        hold_set = cur_tcb->sigprocmask;
-       if (org_set == hold_set) {
-               printf("tc_signal_sighold_sigrelse FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("sighold", org_set, hold_set);
 
        ret_chk = sigrelse(SIGUSR1);
-       if (ret_chk != OK) {
-               printf("tc_signal_sighold_sigrelse FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("sigrelease", ret_chk, OK);
 
        relse_set = cur_tcb->sigprocmask;
-       if (hold_set == relse_set || org_set != relse_set) {
-               printf("tc_signal_sighold_sigrelse FAIL \n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("sighold", hold_set, relse_set);
+       TC_ASSERT_EQ("Sigrelease", org_set, relse_set);
 
-       printf("tc_signal_sighold_sigrelse PASS \n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index b1d3ee4..c137fae 100644 (file)
@@ -81,13 +81,11 @@ static int tc_tash_heapinfo(int argc, char **args)
        tc_thread_attr.priority = TC_HEAPINFO_PRIO;
 
        ret = pthread_create(&tc_thread, &tc_thread_attr, heapinfo_thread, NULL);
-       if (ret != OK) {
-               printf("tc_tash_heapinfo FAIL : task_create\n");
-               return ERROR;
-       }
+       TC_ASSERT_EQ("pthread_create", ret, OK);
        pthread_setname_np(tc_thread, TC_HEAPINFO_TASKNAME);
 
        pthread_detach(tc_thread);
+       TC_SUCCESS_RESULT();
        return OK;
 }
 
index e84b79d..0e5b741 100644 (file)
@@ -61,13 +61,11 @@ static int tc_tash_stackmonitor(int argc, char *args[])
        tc_thread_attr.priority = TC_STACKMONITOR_PRIO;
 
        ret = pthread_create(&tc_thread, &tc_thread_attr, stkmon_thread, NULL);
-       if (ret != OK) {
-               printf("tc_tash_stackmonitor FAIL : pthread_create\n");
-               return ERROR;
-       }
+       TC_ASSERT_EQ("pthread_create", ret, OK);
        pthread_setname_np(tc_thread, TC_STACKMONITOR_TASKNAME);
 
        pthread_detach(tc_thread);
+       TC_SUCCESS_RESULT();
        return OK;
 }
 
index 06388ab..42d0aba 100644 (file)
 #include <unistd.h>
 #include "tc_internal.h"
 
-#define USECVAL         1000000
 #define TEST_STRING     "test"
 #define ONEXIT_VAL      123
+#define SEC_1           1
 #define SEC_2           2
-#define SEC_3           3
+#define USEC_10         10
 
-static int g_icounter = 0;
-static bool g_callback = false;
-static bool g_exit_val = false;
+static int g_callback;
 #ifndef CONFIG_BUILD_PROTECTED
 static volatile int vfork_val;
 static volatile int task_cnt;
@@ -48,93 +46,51 @@ pid_t existed_pid[CONFIG_MAX_TASKS];
 static volatile int vfork_cnt;
 static volatile pid_t ppid;
 static volatile int existed_pid_idx;
+#endif
 
 /**
-* @fn                   :task_cnt_func
-* @brief                :handler of sched_foreach for counting the alive tasks and saving the pids
-* @return               :void
+* @fn                   :create_task
+* @brief                :utility function for tc_task_create
+* @return               :int
 */
-static void task_cnt_func(struct tcb_s *tcb, void *arg)
+static int create_task(int argc, char *argv[])
 {
-       existed_pid[task_cnt] = tcb->pid;
-       task_cnt++;
+       if (strcmp(argv[1], TEST_STRING) == 0) {
+               g_callback = OK;
+       }
+
+       return OK;
 }
 
 /**
-* @fn                   :vfork_task function
-* @brief                :utility function for tc_task_vfork
-* @return               :void
+* @fn                   :delete_task
+* @brief                :utility function for tc_task_task_delete
+* @return               :int
 */
-static int vfork_task(int argc, char *argv[])
+static int delete_task(int argc, char *argv[])
 {
-       pid_t pid;
-       bool result_chk = true;
-       int repeat_criteria;
-       int repeat_iter;
-
-       /* initialize the task_cnt and existed_pid arr */
-       task_cnt = vfork_val = 0;
-       for (existed_pid_idx = 0; existed_pid_idx < CONFIG_MAX_TASKS; existed_pid_idx++) {
-               existed_pid[existed_pid_idx] = -1;
-       }
-
-       ppid = getpid();
-
-       sched_foreach(task_cnt_func, NULL);
-       existed_pid_idx = task_cnt;
-
-       for (vfork_cnt = 0; vfork_cnt < (CONFIG_MAX_TASKS - task_cnt + 1); vfork_cnt++) {
-               pid = vfork();
-               if (pid == 0) {
-                       vfork_val++;
-                       /* check that created pid is repeated or not */
-                       if (existed_pid[existed_pid_idx] != -1) {
-                               result_chk = false;
-                               exit(0);
-                       } else {
-                               existed_pid[existed_pid_idx++] = getpid();
-                       }
-               } else if (pid < 0) {
-                       if (vfork_val >= (CONFIG_MAX_TASKS - task_cnt) && errno == EPERM) {
-                               /* the num of tasks is full, and the errno is set to EPERM */
-                               break;
-                       }
-                       result_chk = false;
-               }
-       }
-
-       while (vfork_val != CONFIG_MAX_TASKS - task_cnt) {
-               usleep(10);
-       }
-
-       if (getpid() != ppid) {
-               exit(0);
-       }
+       g_callback = OK;
+       task_delete(getpid());
 
-       /* check all pids in existed_pid arr whether repeated or not */
-       for (repeat_criteria = 0; repeat_criteria < CONFIG_MAX_TASKS; repeat_criteria++) {
-               for (repeat_iter = repeat_criteria + 1; repeat_iter < CONFIG_MAX_TASKS; repeat_iter++) {
-                       if (existed_pid[repeat_criteria] == existed_pid[repeat_iter]) {
-                               result_chk = false;
-                               break;
-                       }
-               }
-               if (result_chk == false) {
-                       break;
-               }
-       }
+       /* this sleep is for entering callcellation point */
 
-       if (result_chk == true) {
-               printf("tc_task_vfork PASS\n");
-               total_pass++;
-       } else {
-               printf("tc_task_vfork FAIL\n");
-               total_fail++;
-       }
+       sleep(SEC_1);
+       g_callback = ERROR;
+       return OK;
+}
 
-       return 0;
+/**
+* @fn                   :restart_task
+* @brief                :utility function for tc_task_task_restart
+* @return               :int
+*/
+static int restart_task(int argc, char *argv[])
+{
+       g_callback++;
+       sleep(SEC_1);
+       return OK;
 }
-#endif
+
 /**
 * @fn                   :exit_task function
 * @brief                :utility function for tc_task_exit
@@ -142,63 +98,31 @@ static int vfork_task(int argc, char *argv[])
 */
 static int exit_task(int argc, char *argv[])
 {
-       g_exit_val = true;
-       exit(0);
-       g_exit_val = false;
-       return false;
+       g_callback = OK;
+       exit(OK);
+       g_callback = ERROR;
+       return OK;
 }
 
 /**
-* @fn                   :Fn_exit
+* @fn                   :fn_atexit
 * @brief                :utility function for tc_task_atexit
 * @return               :void
 */
-static void fn_exit(void)
-{
-       usleep(USECVAL);
-}
-
-/**
-* @fn                   :temp_task
-* @brief                :utility function for tc_task_getpid
-* @return               :int
-*/
-static int temp_task(int argc, char *argv[])
-{
-       g_callback = true;
-       sleep(SEC_2);
-       task_delete(getpid());
-       return 0;
-}
-
-/**
-* @fn                   :restart_task
-* @brief                :utility function for tc_task_task_restart
-* @return               :int
-*/
-static int restart_task(int argc, char *argv[])
+static void fn_atexit(void)
 {
-       g_icounter++;
-       sleep(SEC_3);
-       task_delete(getpid());
-       return 0;
+       g_callback = OK;
 }
 
 /**
-* @fn                   :delete_task
-* @brief                :utility function for tc_task_task_delete
+* @fn                   :atexit_task
+* @brief                :utility function for tc_task_atexit
 * @return               :int
 */
-static int delete_task(int argc, char *argv[])
+static int atexit_task(int argc, char *argv[])
 {
-       int ret_chk;
-       g_callback = true;
-       ret_chk = task_delete(getpid());
-       if (ret_chk != OK) {
-               printf("tc_task_task_delete FAIL : ret_chk is %d\n", ret_chk);
-       }
-       g_callback = false;
-       return 0;
+       atexit(fn_atexit);
+       return OK;
 }
 
 /**
@@ -208,13 +132,11 @@ static int delete_task(int argc, char *argv[])
 */
 static void fn_onexit(int status, void *arg)
 {
-       char *ptr = (char *)arg;
-
-       if (strcmp(ptr, TEST_STRING) != 0 || status != OK) {
-               printf("%s FAIL, Error No: %d\n", __func__, errno);
-               total_fail++;
+       if (status != ONEXIT_VAL || strcmp((char *)arg, TEST_STRING) != 0) {
+               return;
        }
-       g_callback = true;
+
+       g_callback = OK;
 }
 
 /**
@@ -224,87 +146,103 @@ static void fn_onexit(int status, void *arg)
 */
 static int onexit_task(int argc, char *argv[])
 {
-       usleep(USECVAL);
-       int ret_chk = 0;
-       char *ptr = TEST_STRING;
-       ret_chk = on_exit(fn_onexit, ptr);
-       if (ret_chk != OK) {
-               printf("%s FAIL, Error No: %d\n", __func__, errno);
-               total_fail++;
+       if (on_exit(fn_onexit, TEST_STRING) != OK) {
                return ERROR;
        }
-       task_delete(getpid());
-       return ONEXIT_VAL;
+
+       exit(ONEXIT_VAL);
+       return OK;
 }
 
 /**
-* @fn                   :atexit_test
-* @brief                :utility function for tc_task_atexit
+* @fn                   :getpid_task
+* @brief                :utility function for tc_task_getpid
 * @return               :int
 */
-static int atexit_test(int argc, char *argv[])
+static int getpid_task(int argc, char *argv[])
 {
-       int ret_chk;
-       ret_chk = atexit(fn_exit);
-       if (ret_chk != OK) {
-               printf("tc_task_atexit FAIL, Error No: %d\n", errno);
-               total_fail++;
-               return ERROR;
-       }
-       printf("tc_task_atexit PASS\n");
-       total_pass++;
-       task_delete(getpid());
+       g_callback = (int)getpid();
        return OK;
 }
 
+#ifndef CONFIG_BUILD_PROTECTED
 /**
-* @fn                   :tc_task_atexit
-* @brief                :Register a function to be called at normal process termination
-* @Scenario             :Register a function to be called at normal process termination
-* API's covered         :atexit
-* Preconditions         :none
-* Postconditions        :none
-* @return               :return SUCCESS on success
+* @fn                   :task_cnt_func
+* @brief                :handler of sched_foreach for counting the alive tasks and saving the pids
+* @return               :void
 */
-
-static void tc_task_atexit(void)
+static void task_cnt_func(struct tcb_s *tcb, void *arg)
 {
-       int pid;
-
-       pid = task_create("tc_atexit", SCHED_PRIORITY_DEFAULT, 2048, atexit_test, (char *const *)NULL);
-       if (pid < 0) {
-               printf("tc_task_atexit FAIL : task_create\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       existed_pid[task_cnt] = tcb->pid;
+       task_cnt++;
 }
 
 /**
-* @fn                   :tc_task_getpid
-* @brief                :Returns the process ID of the calling process
-* @Scenario             :Returns the process ID of the calling process
-* API's covered         :getpid
-* Preconditions         :none
-* Postconditions        :none
+* @fn                   :vfork_task function
+* @brief                :utility function for tc_task_vfork
 * @return               :void
 */
-
-static void tc_task_getpid(void)
+static int vfork_task(int argc, char *argv[])
 {
-       int id;
        pid_t pid;
-       id = task_create("tc_getpid", SCHED_PRIORITY_DEFAULT, 2048, temp_task, (char *const *)NULL);
-       if (id == 0) {
-               pid = getpid();
-               if (pid < 0) {
-                       printf("tc_task_getpid FAIL, Error No: %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
+       int repeat_criteria;
+       int repeat_iter;
+
+       /* initialize the task_cnt and existed_pid arr */
+       task_cnt = vfork_val = 0;
+       for (existed_pid_idx = 0; existed_pid_idx < CONFIG_MAX_TASKS; existed_pid_idx++) {
+               existed_pid[existed_pid_idx] = -1;
+       }
+
+       ppid = getpid();
+
+       sched_foreach(task_cnt_func, NULL);
+       existed_pid_idx = task_cnt;
+
+       for (vfork_cnt = 0; vfork_cnt < (CONFIG_MAX_TASKS - task_cnt + 1); vfork_cnt++) {
+               pid = vfork();
+               if (pid == 0) {
+                       vfork_val++;
+                       /* check that created pid is repeated or not */
+                       if (existed_pid[existed_pid_idx] != -1) {
+                               g_callback = ERROR;
+                               exit(OK);
+                       } else {
+                               existed_pid[existed_pid_idx++] = getpid();
+                       }
+               } else if (pid < 0) {
+                       if (vfork_val >= (CONFIG_MAX_TASKS - task_cnt) && errno == EPERM) {
+                               /* the num of tasks is full, and the errno is set to EPERM */
+                               break;
+                       }
+                       g_callback = ERROR;
                }
        }
-       printf("tc_task_getpid PASS\n");
-       total_pass++;
+
+       while (vfork_val != CONFIG_MAX_TASKS - task_cnt) {
+               usleep(USEC_10);
+       }
+
+       if (getpid() != ppid) {
+               exit(OK);
+       }
+
+       /* check all pids in existed_pid arr whether repeated or not */
+       for (repeat_criteria = 0; repeat_criteria < CONFIG_MAX_TASKS; repeat_criteria++) {
+               for (repeat_iter = repeat_criteria + 1; repeat_iter < CONFIG_MAX_TASKS; repeat_iter++) {
+                       if (existed_pid[repeat_criteria] == existed_pid[repeat_iter]) {
+                               g_callback = ERROR;
+                               break;
+                       }
+               }
+               if (g_callback == ERROR) {
+                       break;
+               }
+       }
+
+       return OK;
 }
+#endif
 
 /**
 * @fn                   :tc_task_task_create
@@ -315,26 +253,15 @@ static void tc_task_getpid(void)
 * Postconditions        :none
 * @return               :void
 */
-
 static void tc_task_task_create(void)
 {
        int pid;
-       g_callback = false;
-       pid = task_create("tc_task_create", SCHED_PRIORITY_DEFAULT, 2048, temp_task, (char *const *)NULL);
-       sleep(SEC_2);
-       if (pid < 0 || g_callback == false) {
-               printf("tc_task_task_create FAIL %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (pid == ENOMEM) {
-               printf("Not enough memory to create task \n");
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       printf("tc_task_task_create PASS\n");
-       total_pass++;
+       const char *task_param[2] = { TEST_STRING, NULL };
+       g_callback = ERROR;
+       pid = task_create("tc_task_create", SCHED_PRIORITY_MAX - 1, 1024, create_task, (char * const *)task_param);
+       TC_ASSERT_GT("task_create", pid, 0);
+       TC_ASSERT_EQ("task_create", g_callback, OK);
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -346,18 +273,18 @@ static void tc_task_task_create(void)
 * Postconditions        :none
 * @return               :void
 */
-
 static void tc_task_task_delete(void)
 {
-       task_create("tc_task_del", SCHED_PRIORITY_DEFAULT, 2048, delete_task, (char *const *)NULL);
-       sleep(1);
-       if (g_callback == false) {
-               printf("tc_task_task_delete FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_task_task_delete PASS\n");
-       total_pass++;
+       int pid;
+       int ret_chk;
+       g_callback = ERROR;
+       pid = task_create("tc_task_del", SCHED_PRIORITY_MAX - 1, 1024, delete_task, (char * const *)NULL);
+       TC_ASSERT_GT("task_create", pid, 0);
+
+       ret_chk = task_delete(pid);
+       TC_ASSERT_LT("task_delete", ret_chk, 0);
+       TC_ASSERT_EQ("task_delete", g_callback, OK);
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -369,29 +296,92 @@ static void tc_task_task_delete(void)
 * Postconditions        :none
 * @return               :void
 */
-
 static void tc_task_task_restart(void)
 {
+       int pid;
        int ret_chk;
-       pid_t pid = -1;
-       g_icounter = 0;
-       pid = task_create("tc_task_re", SCHED_PRIORITY_DEFAULT, 2048, restart_task, (char *const *)NULL);
-       sleep(SEC_2);
+       unsigned int remain;
+       g_callback = 0;
+       pid = task_create("tc_task_re", SCHED_PRIORITY_MAX - 1, 1024, restart_task, (char * const *)NULL);
+       TC_ASSERT_GT("task_create", pid, 0);
+
        ret_chk = task_restart(pid);
-       if (ret_chk != OK) {
-               printf("tc_task_task_restart FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
+
+       /* wait for terminating restart_task */
+
+       remain = sleep(SEC_2);
+       while (remain > 0) {
+               remain = sleep(remain);
        }
-       sleep(SEC_2);
+
+       TC_ASSERT_EQ("task_restart", ret_chk, 0);
+
        /* g_icounter shall be increment when do start and restart operation */
-       if (g_icounter != 2) {
-               printf("tc_task_task_restart FAIL, unexpected value of function counter %d \n", g_icounter);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_task_task_restart PASS\n");
-       total_pass++;
+
+       TC_ASSERT_EQ("task_restart", g_callback, 2);
+
+       TC_SUCCESS_RESULT();
+}
+
+/**
+* @fn                   :tc_task_exit
+* @brief                :exit function will terminate the task
+* @Scenario             :make a task which calls exit(). after calling exit,
+*                       that task cannot do anything such as printf
+* API's covered         :on_exit
+* Preconditions         :task_create
+* Postconditions        :none
+* @return               :void
+*/
+static void tc_task_exit(void)
+{
+       int pid;
+       g_callback = ERROR;
+       pid = task_create("tc_exit", SCHED_PRIORITY_MAX - 1, 1024, exit_task, (char * const *)NULL);
+       TC_ASSERT_GT("task_create", pid, 0);
+       TC_ASSERT_EQ("task_exit", g_callback, OK);
+       TC_SUCCESS_RESULT();
+}
+
+/**
+* @fn                   :tc_task_atexit
+* @brief                :Register a function to be called at normal process termination
+* @Scenario             :Register a function to be called at normal process termination
+* API's covered         :atexit
+* Preconditions         :none
+* Postconditions        :none
+* @return               :return SUCCESS on success
+*/
+static void tc_task_atexit(void)
+{
+       int pid;
+       g_callback = ERROR;
+       pid = task_create("tc_atexit", SCHED_PRIORITY_MAX - 1, 1024, atexit_task, (char * const *)NULL);
+       TC_ASSERT_GT("task_create", pid, 0);
+       TC_ASSERT_EQ("task_atexit", g_callback, OK);
+       TC_SUCCESS_RESULT();
+}
+
+/**
+* @fn                   :tc_task_on_exit
+* @brief                :on_exit() function registers the given function to be called\
+*                        at normal process termination
+* @Scenario             :The function is passed the status argument\
+*                        given to the last call to exit and the arg argument from on_exit().
+* API's covered         :on_exit
+* Preconditions         :task_create
+* Postconditions        :none
+* @return               :void
+*/
+static void tc_task_on_exit(void)
+{
+       int pid;
+       g_callback = ERROR;
+
+       pid = task_create("tc_on_exit", SCHED_PRIORITY_MAX - 1, 1024, onexit_task, (char * const *)NULL);
+       TC_ASSERT_GT("task_create", pid, 0);
+       TC_ASSERT_EQ("on_exit", g_callback, OK);
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -405,7 +395,6 @@ static void tc_task_task_restart(void)
 * Postconditions        :none
 * @return               :void
 */
-
 static void tc_task_prctl(void)
 {
        int ret_chk;
@@ -416,104 +405,43 @@ static void tc_task_prctl(void)
        /* save taskname */
 
        ret_chk = prctl(PR_GET_NAME, (unsigned long)oldname, 0, 0, 0);
-       if (ret_chk != OK) {
-               printf("tc_task_prctl FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("prctl", ret_chk, OK);
 
        /* set taskname */
 
        ret_chk = prctl(PR_SET_NAME, (unsigned long)setname, 0, 0, 0);
-       if (ret_chk != OK) {
-               printf("tc_task_prctl FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ("prctl", ret_chk, OK);
 
        /* get taskname */
 
        ret_chk = prctl(PR_GET_NAME, (unsigned long)getname, 0, 0, 0);
-       if (ret_chk != OK) {
-               printf("tc_task_prctl FAIL, Error No: %d\n", errno);
-               prctl(PR_SET_NAME, (unsigned long)oldname, 0, 0, 0);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ_CLEANUP("prctl", ret_chk, OK, get_errno(), prctl(PR_SET_NAME, (unsigned long)oldname, 0, 0, 0));
 
        /* compare getname and setname */
 
-       if (strncmp(getname, setname, CONFIG_TASK_NAME_SIZE) != 0) {
-               printf("tc_task_prctl FAIL, The new process name doesn't match the expected FAIL, Error No: %d\n", errno);
-               prctl(PR_SET_NAME, (unsigned long)oldname, 0, 0, 0);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ_CLEANUP("prctl", strncmp(getname, setname, CONFIG_TASK_NAME_SIZE), 0, get_errno(), prctl(PR_SET_NAME, (unsigned long)oldname, 0, 0, 0));
 
        prctl(PR_SET_NAME, (unsigned long)oldname, 0, 0, 0);
-       printf("tc_task_prctl PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
-* @fn                   :tc_task_on_exit
-* @brief                :on_exit() function registers the given function to be called\
-*                        at normal process termination
-* @Scenario             :The function is passed the status argument\
-*                        given to the last call to exit and the arg argument from on_exit().
-* API's covered         :on_exit
-* Preconditions         :task_create
+* @fn                   :tc_task_getpid
+* @brief                :Returns the process ID of the calling process
+* @Scenario             :Returns the process ID of the calling process
+* API's covered         :getpid
+* Preconditions         :none
 * Postconditions        :none
 * @return               :void
 */
-static void tc_task_on_exit(void)
+static void tc_task_getpid(void)
 {
        int pid;
-       unsigned int remain;
-       g_callback = false;
-
-       pid = task_create("tc_on_exit", SCHED_PRIORITY_DEFAULT, 2048, onexit_task, (char *const *)NULL);
-       if (pid < 0) {
-               printf("tc_task_on_exit task_create FAIL, Error No: %d %d\n", errno, pid);
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       remain = sleep(SEC_3);
-       while (remain > 0) {
-               remain = sleep(remain);
-       }
-
-       if (!g_callback) {
-               printf("tc_task_on_exit FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       printf("tc_task_on_exit PASS\n");
-       total_pass++;
-}
-
-/**
-* @fn                   :tc_task_exit
-* @brief                :exit function will terminate the task
-* @Scenario             :make a task which calls exit(). after calling exit,
-*                       that task cannot do anything such as printf
-* API's covered         :on_exit
-* Preconditions         :task_create
-* Postconditions        :none
-* @return               :void
-*/
-static void tc_task_exit(void)
-{
-       task_create("tc_exit", SCHED_PRIORITY_MAX - 1, 1024, exit_task, (char *const *)NULL);
-
-       if (g_exit_val == true) {
-               printf("tc_task_exit PASS\n");
-               total_pass++;
-       } else {
-               printf("tc_task_exit FAIL\n");
-               total_fail++;
-       }
+       g_callback = ERROR;
+       pid = task_create("tc_getpid", SCHED_PRIORITY_MAX - 1, 1024, getpid_task, (char * const *)NULL);
+       TC_ASSERT_GT("task_create", pid, 0);
+       TC_ASSERT_EQ("getpid", pid, g_callback);
+       TC_SUCCESS_RESULT();
 }
 
 #ifndef CONFIG_BUILD_PROTECTED
@@ -529,7 +457,13 @@ static void tc_task_exit(void)
 */
 static void tc_task_vfork(void)
 {
-       task_create("tc_vfork", SCHED_PRIORITY_MAX - 1, 1024, vfork_task, (char *const *)NULL);
+       int pid;
+       g_callback = OK;
+       pid = task_create("tc_vfork", SCHED_PRIORITY_MAX - 1, 1024, vfork_task, (char * const *)NULL);
+       TC_ASSERT_GT("task_create", pid, 0);
+       TC_ASSERT_EQ("task_restart", g_callback, OK);
+
+       TC_SUCCESS_RESULT();
 }
 #endif
 /****************************************************************************
@@ -537,17 +471,16 @@ static void tc_task_vfork(void)
  ****************************************************************************/
 int task_main(void)
 {
-       tc_task_task_restart();
-       tc_task_atexit();
-       tc_task_getpid();
        tc_task_task_create();
        tc_task_task_delete();
-       tc_task_prctl();
-       tc_task_on_exit();
+       tc_task_task_restart();
        tc_task_exit();
+       tc_task_atexit();
+       tc_task_on_exit();
+       tc_task_prctl();
+       tc_task_getpid();
 #if defined(CONFIG_ARCH_HAVE_VFORK) && defined(CONFIG_SCHED_WAITPID) && !defined(CONFIG_BUILD_PROTECTED)
        tc_task_vfork();
 #endif
-
        return 0;
 }
index 676e915..45b0d08 100644 (file)
@@ -39,6 +39,7 @@ static void tc_termios_tcsetattr_tcgetattr(void)
        struct termios prev_tio;
 
        ret_chk = tcgetattr(fileno(stdin), &prev_tio);
+       TC_ASSERT_EQ("tcgetattr", ret_chk, 0);
        if (ret_chk != 0) {
                printf("tc_termios_tcsetattr_tcgetattr fail : getattr %d\n", errno);
        }
@@ -46,6 +47,7 @@ static void tc_termios_tcsetattr_tcgetattr(void)
        sleep(1);
        prev_tio.c_oflag &= ~ONLCR;
        ret_chk = tcsetattr(fileno(stdin), TCSANOW, &prev_tio);
+       TC_ASSERT_EQ("tcsetattr", ret_chk, 0);
        if (ret_chk != 0) {
                printf("tc_termios_tcsetattr_tcgetattr fail : setattr %d\n", errno);
        }
@@ -57,6 +59,7 @@ static void tc_termios_tcsetattr_tcgetattr(void)
        sleep(1);
        prev_tio.c_oflag |= ONLCR;
        ret_chk = tcsetattr(fileno(stdin), TCSANOW, &prev_tio);
+       TC_ASSERT_EQ("tcsetattr", ret_chk, 0);
        if (ret_chk != 0) {
                printf("tc_termios_tcsetattr_tcgetattr fail : setattr %d\n", errno);
        }
index 04dba09..7ccb150 100644 (file)
@@ -54,24 +54,15 @@ static void tc_timer_timer_create_delete(void)
        st_sigevent.sigev_value.sival_ptr = &timer_id;
 
        ret_chk = timer_create(clockid, &st_sigevent, &timer_id);
-       if (ret_chk == ERROR) {
-               printf("tc_timer_timer_create_delete FAIL : timer_cretae FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-       if (timer_id == NULL) {         /* check fail condition of timer_id */
-               printf("tc_timer_timer_create_delete FAIL : timer_create FAIL, Timer ID not available\n");
-               total_fail++;
-               RETURN_ERR;
-       }
-       st_ret_prt = (struct posix_timer_s *)timer_id;
+       TC_ASSERT_NEQ("timer_create", ret_chk, ERROR);
+       TC_ASSERT_NOT_NULL("timer_create", timer_id);
 
-       if (st_ret_prt->pt_value.sival_ptr != st_sigevent.sigev_value.sival_ptr || st_ret_prt->pt_signo != st_sigevent.sigev_signo || st_ret_prt->pt_crefs != 1 || st_ret_prt->pt_owner != getpid() || st_ret_prt->pt_delay != 0) {
-               ret_chk = timer_delete(timer_id);
-               printf("tc_timer_timer_create_delete FAIL : timer_create FAIL, posix_timer_s for sigevent not available\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       st_ret_prt = (struct posix_timer_s *)timer_id;
+       TC_ASSERT_EQ_CLEANUP("timer_create", st_ret_prt->pt_value.sival_ptr, st_sigevent.sigev_value.sival_ptr, "posix_timer_s for sigevent not available", timer_delete(timer_id));
+       TC_ASSERT_EQ_CLEANUP("timer_create", st_ret_prt->pt_signo, st_sigevent.sigev_signo, "posix_timer_s for sigevent not available", timer_delete(timer_id));
+       TC_ASSERT_EQ_CLEANUP("timer_create", st_ret_prt->pt_crefs, 1, "posix_timer_s for sigevent not available", timer_delete(timer_id));
+       TC_ASSERT_EQ_CLEANUP("timer_create", st_ret_prt->pt_owner, getpid(), "posix_timer_s for sigevent not available", timer_delete(timer_id));
+       TC_ASSERT_EQ_CLEANUP("timer_create", st_ret_prt->pt_delay, 0, "posix_timer_s for sigevent not available", timer_delete(timer_id));
 
        st_timer_spec_val.it_value.tv_sec = 1;
        st_timer_spec_val.it_value.tv_nsec = 0;
@@ -80,45 +71,24 @@ static void tc_timer_timer_create_delete(void)
        st_timer_spec_val.it_interval.tv_nsec = 0;
 
        ret_chk = timer_settime(timer_id, 0, &st_timer_spec_val, NULL);
-       if (ret_chk == ERROR) {
-               printf("tc_timer_timer_create_delete FAIL : timer_settime FAIL, Error No: %d\n", errno);
-               timer_delete(timer_id);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ_CLEANUP("timer_settime", ret_chk, ERROR, errno, timer_delete(timer_id));
 
        ret_chk = timer_delete(timer_id);
-       if (ret_chk == ERROR) {
-               printf("tc_timer_timer_create_delete FAIL : timer_delete FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("timer_delete", ret_chk, ERROR);
 
        ret_chk = timer_create(CLOCK_REALTIME, NULL, &gtimer_id);
-       if (ret_chk == ERROR) {
-               printf("tc_timer_timer_create_delete FAIL : timer_create FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("timer_create", ret_chk, ERROR);
 
        st_ret_prt = (struct posix_timer_s *)gtimer_id;
 
-       if (st_ret_prt->pt_value.sival_ptr != st_ret_prt || st_ret_prt->pt_signo != SIGALRM || st_ret_prt->pt_crefs != 1 || st_ret_prt->pt_owner != getpid() || st_ret_prt->pt_delay != 0) {
-               timer_delete(gtimer_id);
-               printf("tc_timer_timer_create_delete FAIL : timer_create FAIL, posix_timer_s for NULL not available\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ_CLEANUP("timer_create", st_ret_prt->pt_value.sival_ptr, st_ret_prt, "posix_timer_s for NULL not available", timer_delete(gtimer_id));
+       TC_ASSERT_EQ_CLEANUP("timer_create", st_ret_prt->pt_crefs, 1, "posix_timer_s for NULL not available", timer_delete(gtimer_id));
+       TC_ASSERT_EQ_CLEANUP("timer_create", st_ret_prt->pt_owner, getpid(), "posix_timer_s for NULL not available", timer_delete(gtimer_id));
+       TC_ASSERT_EQ_CLEANUP("timer_create", st_ret_prt->pt_delay, 0, "posix_timer_s for NULL not available", timer_delete(gtimer_id));
 
        ret_chk = timer_delete(gtimer_id);
-       if (ret_chk == ERROR) {
-               printf("tc_timer_timer_create_delete FAIL : timer_delete FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
-
-       printf("tc_timer_timer_create_delete PASS\n");
-       total_pass++;
+       TC_ASSERT_NEQ("timer_delete", ret_chk, ERROR);
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -144,11 +114,8 @@ static void tc_timer_timer_set_get_time(void)
        st_sigevent.sigev_signo = sig_no;
        st_sigevent.sigev_value.sival_ptr = &timer_id;
        ret_chk = timer_create(clockid, &st_sigevent, &timer_id);
-       if (ret_chk == ERROR || timer_id == NULL) {
-               printf("tc_timer_timer_set_get_time TIMER CREATE FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ("timer_create", ret_chk, ERROR);
+       TC_ASSERT_NOT_NULL("timer_create", timer_id);
 
        st_timer_spec_set.it_interval.tv_sec = 1;
        st_timer_spec_set.it_interval.tv_nsec = 0;      /* interval; */
@@ -156,25 +123,19 @@ static void tc_timer_timer_set_get_time(void)
        st_timer_spec_set.it_value.tv_nsec = 0; /* expire; */
 
        ret_chk = timer_settime(timer_id, 0, &st_timer_spec_set, NULL); /* Flag =1 :TIMER_ABSTIME */
-       if (ret_chk != OK) {
-               timer_delete(timer_id);
-               printf("tc_timer_timer_set_get_time TIMER SETTIME FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ_CLEANUP("timer_settime", ret_chk, OK, errno, timer_delete(timer_id));
 
        usleep(USECINT);
 
        ret_chk = timer_gettime(timer_id, &st_timer_spec_get);
-       if ((ret_chk == ERROR) || (st_timer_spec_get.it_interval.tv_nsec < st_timer_spec_set.it_interval.tv_nsec) || (st_timer_spec_get.it_interval.tv_sec < st_timer_spec_set.it_interval.tv_sec) || (st_timer_spec_get.it_value.tv_sec < st_timer_spec_set.it_value.tv_sec) || (st_timer_spec_get.it_value.tv_nsec < st_timer_spec_set.it_value.tv_nsec)) {
-               timer_delete(timer_id);
-               printf("tc_timer_timer_set_get_time TIMER GETTIME FAIL, Error No: %d\n", errno);
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NEQ_CLEANUP("timer_gettime", ret_chk, ERROR, errno, timer_delete(timer_id));
+       TC_ASSERT_GEQ_CLEANUP("timer_gettime", st_timer_spec_get.it_interval.tv_nsec, st_timer_spec_set.it_interval.tv_nsec, errno, timer_delete(timer_id));
+       TC_ASSERT_GEQ_CLEANUP("timer_gettime", st_timer_spec_get.it_interval.tv_sec, st_timer_spec_set.it_interval.tv_sec, errno, timer_delete(timer_id));
+       TC_ASSERT_GEQ_CLEANUP("timer_gettime", st_timer_spec_get.it_value.tv_sec, st_timer_spec_set.it_value.tv_sec, errno, timer_delete(timer_id));
+       TC_ASSERT_GEQ_CLEANUP("timer_gettime", st_timer_spec_get.it_value.tv_nsec, st_timer_spec_set.it_value.tv_nsec, errno, timer_delete(timer_id));
+
        timer_delete(timer_id);
-       printf("tc_timer_timer_set_get_time PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -245,15 +206,13 @@ static void tc_timer_timer_initialize(void)
                finalfree_cnt++;
        }
 
-       if (initalloc_cnt != finalalloc_cnt || initfree_cnt != finalfree_cnt || createalloc_cnt == finalalloc_cnt || createfree_cnt == finalfree_cnt) {
-               timer_delete(timer_id);
-               printf("tc_timer_timer_initialize FAIL, Timer ID not available\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_EQ_CLEANUP("timer_initialise", initalloc_cnt, finalalloc_cnt, "Timer ID not available", timer_delete(timer_id));
+       TC_ASSERT_EQ_CLEANUP("timer_initialise", initfree_cnt, finalfree_cnt, "Timer ID not available", timer_delete(timer_id));
+       TC_ASSERT_NEQ_CLEANUP("timer_initialise", createalloc_cnt, finalalloc_cnt, "Timer ID not available", timer_delete(timer_id));
+       TC_ASSERT_NEQ_CLEANUP("timer_initialise", createfree_cnt, finalfree_cnt, "Timer ID not available", timer_delete(timer_id));
+
        timer_delete(timer_id);
-       printf("tc_timer_timer_initialize PASS\n");
-       total_pass++;
+       TC_SUCCESS_RESULT();
 }
 
 /****************************************************************************
index 6098a45..147cf08 100644 (file)
@@ -69,28 +69,13 @@ static void tc_umm_heap_malloc_free(struct tcb_s *st_tcb)
        for (alloc_tc_cnt = 0; alloc_tc_cnt < TEST_TIMES; alloc_tc_cnt++) {
                for (alloc_cnt = 0; alloc_cnt < ALLOC_FREE_TIMES; alloc_cnt++) {
                        mem_ptr[alloc_cnt] = (int *)malloc(ALLOC_SIZE_VAL * sizeof(int));
-                       if (mem_ptr[alloc_cnt] == NULL) {
-                               mem_deallocate_func(mem_ptr, alloc_cnt);
-                               printf("tc_umm_heap_malloc_free FAIL : errno %d\n", errno);
-                               total_fail++;
-                               RETURN_ERR;
-                       }
-               }
-               if (st_tcb->curr_alloc_size != TOTAL_ALLOC_SIZE) {
-                       printf("tc_umm_heap_malloc_free malloc FAIL : errno %d size %d definedSize %d\n", errno, st_tcb->curr_alloc_size, TOTAL_ALLOC_SIZE);
-                       mem_deallocate_func(mem_ptr, ALLOC_FREE_TIMES);
-                       total_fail++;
-                       RETURN_ERR;
+                       TC_ASSERT_NOT_NULL("malloc", mem_ptr[alloc_cnt]);
                }
+               TC_ASSERT_EQ_CLEANUP("malloc", st_tcb->curr_alloc_size, TOTAL_ALLOC_SIZE, get_errno(), mem_deallocate_func(mem_ptr, ALLOC_FREE_TIMES));
                mem_deallocate_func(mem_ptr, ALLOC_FREE_TIMES);
-               if (st_tcb->curr_alloc_size != ALL_FREE) {
-                       printf("tc_umm_heap_malloc_free free FAIL : errno %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("malloc", st_tcb->curr_alloc_size, ALL_FREE);
        }
-       total_pass++;
-       printf("tc_umm_heap_malloc_free PASS\n");
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -112,28 +97,15 @@ static void tc_umm_heap_calloc(struct tcb_s *st_tcb)
        for (alloc_tc_cnt = 0; alloc_tc_cnt < TEST_TIMES; alloc_tc_cnt++) {
                for (alloc_cnt = 0; alloc_cnt < ALLOC_FREE_TIMES; alloc_cnt++) {
                        mem_ptr[alloc_cnt] = (int *)calloc(ALLOC_SIZE_VAL, sizeof(int));
-                       if (mem_ptr[alloc_cnt] == NULL) {
-                               mem_deallocate_func(mem_ptr, alloc_cnt);
-                               printf("tc_umm_heap_calloc FAIL : errno %d\n", errno);
-                               total_fail++;
-                               RETURN_ERR;
-                       }
-               }
-               if (st_tcb->curr_alloc_size != TOTAL_ALLOC_SIZE) {
-                       printf("tc_umm_heap_calloc calloc FAIL : errno %d\n", errno);
-                       mem_deallocate_func(mem_ptr, ALLOC_FREE_TIMES);
-                       total_fail++;
-                       RETURN_ERR;
+                       TC_ASSERT_NOT_NULL("calloc", mem_ptr[alloc_cnt]);
                }
+
+               TC_ASSERT_EQ_CLEANUP("calloc", st_tcb->curr_alloc_size, TOTAL_ALLOC_SIZE, get_errno(), mem_deallocate_func(mem_ptr, ALLOC_FREE_TIMES));
                mem_deallocate_func(mem_ptr, ALLOC_FREE_TIMES);
-               if (st_tcb->curr_alloc_size != ALL_FREE) {
-                       printf("tc_umm_heap_calloc free FAIL : errno %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
+
+               TC_ASSERT_EQ("calloc", st_tcb->curr_alloc_size, ALL_FREE);
        }
-       total_pass++;
-       printf("tc_umm_heap_calloc PASS \n");
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -157,28 +129,14 @@ static void tc_umm_heap_realloc(struct tcb_s *st_tcb)
        for (alloc_tc_cnt = 0; alloc_tc_cnt < TEST_TIMES; alloc_tc_cnt++) {
                for (alloc_cnt = 0; alloc_cnt < ALLOC_FREE_TIMES; alloc_cnt++) {
                        mem_ptr[alloc_cnt] = (int *)realloc(val, ALLOC_SIZE_VAL * sizeof(int));
-                       if (mem_ptr[alloc_cnt] == NULL) {
-                               mem_deallocate_func(mem_ptr, alloc_cnt);
-                               printf("tc_umm_heap_realloc FAIL : errno %d\n", errno);
-                               total_fail++;
-                               RETURN_ERR;
-                       }
-               }
-               if (st_tcb->curr_alloc_size != TOTAL_ALLOC_SIZE) {
-                       printf("tc_umm_heap_realloc realloc FAIL : errno %d\n", errno);
-                       mem_deallocate_func(mem_ptr, ALLOC_FREE_TIMES);
-                       total_fail++;
-                       RETURN_ERR;
+                       TC_ASSERT_NOT_NULL("realloc", mem_ptr[alloc_cnt]);
                }
+               TC_ASSERT_EQ_CLEANUP("realloc", st_tcb->curr_alloc_size, TOTAL_ALLOC_SIZE, get_errno(), mem_deallocate_func(mem_ptr, ALLOC_FREE_TIMES));
                mem_deallocate_func(mem_ptr, ALLOC_FREE_TIMES);
-               if (st_tcb->curr_alloc_size != ALL_FREE) {
-                       printf("tc_umm_heap_realloc free FAIL : errno %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
+
+               TC_ASSERT_EQ("realloc", st_tcb->curr_alloc_size, ALL_FREE);
        }
-       total_pass++;
-       printf("tc_umm_heap_realloc PASS \n");
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -200,28 +158,14 @@ static void tc_umm_heap_memalign(struct tcb_s *st_tcb)
        for (alloc_tc_cnt = 0; alloc_tc_cnt < TEST_TIMES; alloc_tc_cnt++) {
                for (alloc_cnt = 0; alloc_cnt < ALLOC_FREE_TIMES; alloc_cnt++) {
                        mem_ptr[alloc_cnt] = (int *)memalign(sizeof(int), ALLOC_SIZE_VAL * sizeof(int));
-                       if (mem_ptr[alloc_cnt] == NULL) {
-                               mem_deallocate_func(mem_ptr, alloc_cnt);
-                               printf("tc_umm_heap_memalign FAIL : errno %d\n", errno);
-                               total_fail++;
-                               RETURN_ERR;
-                       }
-               }
-               if (st_tcb->curr_alloc_size != TOTAL_ALLOC_SIZE) {
-                       printf("tc_umm_heap_memalign realloc FAIL : errno %d\n", errno);
-                       mem_deallocate_func(mem_ptr, ALLOC_FREE_TIMES);
-                       total_fail++;
-                       RETURN_ERR;
+                       TC_ASSERT_NOT_NULL("memalign", mem_ptr[alloc_cnt]);
                }
+               TC_ASSERT_EQ_CLEANUP("memalign", st_tcb->curr_alloc_size, TOTAL_ALLOC_SIZE, get_errno(), mem_deallocate_func(mem_ptr, ALLOC_FREE_TIMES));
                mem_deallocate_func(mem_ptr, ALLOC_FREE_TIMES);
-               if (st_tcb->curr_alloc_size != ALL_FREE) {
-                       printf("tc_umm_heap_memalign free FAIL : errno %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
+
+               TC_ASSERT_EQ("memalign", st_tcb->curr_alloc_size, ALL_FREE);
        }
-       total_pass++;
-       printf("tc_umm_heap_memalign PASS \n");
+       TC_SUCCESS_RESULT();
 }
 
 /**
@@ -249,36 +193,19 @@ static void tc_umm_heap_random_malloc(struct tcb_s *st_tcb)
                for (alloc_cnt = 0; alloc_cnt < ALLOC_FREE_TIMES; alloc_cnt++) {
                        allocated[alloc_cnt] = rand();
                        mem_ptr[alloc_cnt] = (int *)malloc(allocated[alloc_cnt]);
-                       if (mem_ptr[alloc_cnt] == NULL) {
-                               mem_deallocate_func(mem_ptr, alloc_cnt);
-                               printf("tc_umm_heap_random_malloc FAIL : errno %d\n", errno);
-                               total_fail++;
-                               RETURN_ERR;
-                       }
+                       TC_ASSERT_NOT_NULL("malloc", mem_ptr[alloc_cnt]);
                }
-
                for (alloc_cnt = 0; alloc_cnt < ALLOC_FREE_TIMES; alloc_cnt++) {
                        /* do alloc 'allocated[alloc_cnt]',
                           but allocated MM_ALIGN_UP'(allocated[alloc_cnt] + SIZEOF_MM_ALLOCNODE)',
                           because of the chunk size */
                        allocated_size += MM_ALIGN_UP(allocated[alloc_cnt] + SIZEOF_MM_ALLOCNODE);
                }
-               if (st_tcb->curr_alloc_size != allocated_size) {
-                       printf("tc_umm_heap_random_malloc FAIL : errno %d\n", errno);
-                       mem_deallocate_func(mem_ptr, ALLOC_FREE_TIMES);
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ_CLEANUP("malloc", st_tcb->curr_alloc_size, allocated_size, get_errno(), mem_deallocate_func(mem_ptr, ALLOC_FREE_TIMES));
                mem_deallocate_func(mem_ptr, ALLOC_FREE_TIMES);
-               if (st_tcb->curr_alloc_size != ALL_FREE) {
-                       printf("tc_umm_heap_random_malloc free FAIL : errno %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ("random_malloc", st_tcb->curr_alloc_size, ALL_FREE);
        }
-       total_pass++;
-       printf("tc_umm_heap_random_malloc PASS\n");
-
+       TC_SUCCESS_RESULT();
 }
 #endif
 
@@ -301,23 +228,13 @@ static void tc_umm_heap_mallinfo(void)
 
        for (alloc_tc_cnt = 0; alloc_tc_cnt < TEST_TIMES; alloc_tc_cnt++) {
                mem_ptr = (int *)malloc(sizeof(int));
-               if (mem_ptr == NULL) {
-                       printf("tc_umm_heap_mallinfo malloc FAIL : errno %d\n", errno);
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_NOT_NULL("malloc", mem_ptr);
+
                st_mallinfo = mallinfo();
-               if (st_mallinfo.fordblks <= 0) {
-                       printf("tc_umm_heap_mallinfo FAIL : errno %d\n", errno);
-                       free(mem_ptr);
-                       total_fail++;
-                       RETURN_ERR;
-               }
-               free(mem_ptr);
-               mem_ptr = NULL;
+               TC_ASSERT_GT_CLEANUP("mallinfo", st_mallinfo.fordblks, 0, get_errno(), TC_FREE_MEMORY(mem_ptr));
+               TC_FREE_MEMORY(mem_ptr);
        }
-       total_pass++;
-       printf("tc_umm_heap_mallinfo PASS \n");
+       TC_SUCCESS_RESULT();
 }
 
 static void tc_umm_heap_zalloc(void)
@@ -325,25 +242,13 @@ static void tc_umm_heap_zalloc(void)
        int mem_idx;
        int *mem_ptr = NULL;
        mem_ptr = zalloc(sizeof(int) * 5);
-
-       if (mem_ptr == NULL) {
-               printf("tc_umm_heap_zalloc FAIL\n");
-               total_fail++;
-               RETURN_ERR;
-       }
+       TC_ASSERT_NOT_NULL("zalloc", mem_ptr);
 
        for (mem_idx = 0; mem_idx < 5; mem_idx++) {
-               if (mem_ptr[mem_idx] != 0) {
-                       printf("tc_umm_heap_zalloc FAIL\n");
-                       free(mem_ptr);
-                       total_fail++;
-                       RETURN_ERR;
-               }
+               TC_ASSERT_EQ_CLEANUP("zalloc", mem_ptr[mem_idx], 0, get_errno(), TC_FREE_MEMORY(mem_ptr));
        }
-
-       free(mem_ptr);
-       total_pass++;
-       printf("tc_umm_heap_zalloc PASS\n");
+       TC_FREE_MEMORY(mem_ptr);
+       TC_SUCCESS_RESULT();
 }
 
 static int umm_task(int argc, char *argv[])
@@ -369,7 +274,7 @@ static int umm_task(int argc, char *argv[])
 
 int umm_heap_main(void)
 {
-       task_create("umm_task", 150, 2048, umm_task, (char *const *)NULL);
+       task_create("umm_task", 150, 2048, umm_task, (char * const *)NULL);
        sleep(1);
 
        return 0;
index 0d24732..91e5b2b 100644 (file)
 int total_pass;
 int total_fail;
 
-#define TC_ASSERT(api_name, var) \
+#define TC_ASSERT_CLEANUP(api_name, var, error, freeResource) \
 {\
-    if (!(var)) {\
-            printf("\n[%s][Line : %d] FAIL, %s : Following expression is not true: %s\n", __func__, __LINE__, api_name, #var); \
-            total_fail++; \
-            return; \
-        }\
+       if (!(var)) {\
+               printf("\n[%s][Line : %d] FAIL, %s : API error returned = %s [%s]\n", __func__, __LINE__, api_name, error, #var); \
+               total_fail++; \
+               freeResource; \
+               return; \
+       } \
 }
 
-#define TC_ASSERT_EQ(api_name, var, ref) \
+#define TC_ASSERT(api_name, var) \
 {\
-    if (var != ref) {\
-            printf("\n[%s][Line : %d] FAIL, %s : Values (%s == 0x%x) and (%s == 0x%x) are not equal\n", __func__, __LINE__, api_name, #var, (int)var, #ref, (int)ref); \
-            total_fail++; \
-            return; \
-    }\
+       if (!(var)) {\
+               printf("\n[%s][Line : %d] FAIL, %s : Following expression is not true: %s\n", __func__, __LINE__, api_name, #var); \
+               total_fail++; \
+               return; \
+       } \
 }
 
 #define TC_ASSERT_EQ_CLEANUP(api_name, var, ref, error, freeResource) \
 {\
-    if (var != ref) {\
-            printf("\n[%s][Line : %d] FAIL, %s : API error returned = %s [%d] ", __func__, __LINE__, api_name, error, #var); \
-            freeResource; \
-            total_fail++; \
-            return; \
-        }\
+       if (var != ref) {\
+               printf("\n[%s][Line : %d] FAIL, %s : API error returned = %s [%d] ", __func__, __LINE__, api_name, error, #var); \
+               total_fail++; \
+               freeResource; \
+               return; \
+       } \
+}
+
+#define TC_ASSERT_EQ(api_name, var, ref) \
+{\
+       if (var != ref) {\
+               printf("\n[%s][Line : %d] FAIL, %s : Values (%s == 0x%x) and (%s == 0x%x) are not equal\n", __func__, __LINE__, api_name, #var, (int)var, #ref, (int)ref); \
+               total_fail++; \
+               return; \
+       } \
 }
 
 #define TC_ASSERT_NEQ_CLEANUP(api_name, var, ref, error, freeResource) \
 {\
-    if (var == ref) {\
-            printf("\n[%s][Line : %d] FAIL, %s : API error returned = %s [%d] ", __func__, __LINE__, api_name, error, #var); \
-            freeResource; \
-            total_fail++; \
-            return; \
-        }\
+       if (var == ref) {\
+               printf("\n[%s][Line : %d] FAIL, %s : API error returned = %s [%d] ", __func__, __LINE__, api_name, error, #var); \
+               total_fail++; \
+               freeResource; \
+               return; \
+       \
 }
 
 #define TC_ASSERT_NEQ(api_name, var, ref) \
 {\
-    if (var == ref) {\
-            printf("\n[%s][Line : %d] FAIL, %s : Values (%s == 0x%x) and (%s == 0x%x) are equal\n", __func__, __LINE__, api_name, #var, (int)var, #ref, (int)ref); \
-            total_fail++; \
-            return; \
-        }\
+       if (var == ref) {\
+               printf("\n[%s][Line : %d] FAIL, %s : Values (%s == 0x%x) and (%s == 0x%x) are equal\n", __func__, __LINE__, api_name, #var, (int)var, #ref, (int)ref); \
+               total_fail++; \
+               return; \
+       } \
+}
+
+#define TC_ASSERT_GT_CLEANUP(api_name, var, ref, error, freeResource) \
+{\
+       if (var <= ref) {\
+               printf("\n[%s][Line : %d] FAIL, %s : Values (%s == 0x%x) is not greater than (%s == 0x%x)\n", __func__, __LINE__, api_name, error, #var); \
+               total_fail++; \
+               freeResource; \
+               return; \
+       } \
 }
 
 #define TC_ASSERT_GT(api_name, var, ref) \
 {\
-    if (var <= ref)    {\
-            printf("\n[%s][Line : %d] FAIL, %s : Values (%s == 0x%x) is not greater than (%s == 0x%x)\n", __func__, __LINE__, api_name, #var, (int)var, #ref, (int)ref); \
-            total_fail++; \
-            return; \
-        }\
+       if (var <= ref)    {\
+               printf("\n[%s][Line : %d] FAIL, %s : Values (%s == 0x%x) is not greater than (%s == 0x%x)\n", __func__, __LINE__, api_name, #var, (int)var, #ref, (int)ref); \
+               total_fail++; \
+               return; \
+       } \
+}
+
+#define TC_ASSERT_GEQ_CLEANUP(api_name, var, ref, error, freeResource) \
+{\
+       if (var < ref) {\
+               printf("\n[%s][Line : %d] FAIL, %s : Values (%s == 0x%x) is not greater than or euqal to (%s == 0x%x)\n", __func__, __LINE__, api_name, error, #var); \
+               total_fail++; \
+               freeResource; \
+               return; \
+       } \
 }
 
 #define TC_ASSERT_GEQ(api_name, var, ref) \
 {\
-    if (var < ref) {\
-            printf("\n[%s][Line : %d] FAIL, %s : Values (%s == 0x%x) is not greater than or equal to (%s == 0x%x)\n", __func__, __LINE__, api_name, #var, (int)var, #ref, (int)ref); \
-            total_fail++; \
-            return; \
-        }\
+       if (var < ref) {\
+               printf("\n[%s][Line : %d] FAIL, %s : Values (%s == 0x%x) is not greater than or equal to (%s == 0x%x)\n", __func__, __LINE__, api_name, #var, (int)var, #ref, (int)ref); \
+               total_fail++; \
+               return; \
+       \
 }
 
 #define TC_ASSERT_LT(api_name, var, ref) \
 {\
-    if (var >= ref) {\
-            printf("\n[%s][Line : %d] FAIL, %s : Values (%s == 0x%x) is not lower than (%s == 0x%x)\n", __func__, __LINE__, api_name, #var, (int)var, #ref, (int)ref); \
-            total_fail++; \
-            return; \
-        }\
+       if (var >= ref) {\
+               printf("\n[%s][Line : %d] FAIL, %s : Values (%s == 0x%x) is not lower than (%s == 0x%x)\n", __func__, __LINE__, api_name, #var, (int)var, #ref, (int)ref); \
+               total_fail++; \
+               return; \
+       \
 }
 
 #define TC_ASSERT_LEQ(api_name, var, ref) \
 {\
-    if (var > ref) {\
-            printf("\n[%s][Line : %d] FAIL, %s : Values (%s == 0x%x) is not lower than or equal to (%s == 0x%x)\n", __func__, __LINE__, api_name, #var, (int)var, #ref, (int)ref); \
-            total_fail++; \
-            return; \
-        }\
+       if (var > ref) {\
+               printf("\n[%s][Line : %d] FAIL, %s : Values (%s == 0x%x) is not lower than or equal to (%s == 0x%x)\n", __func__, __LINE__, api_name, #var, (int)var, #ref, (int)ref); \
+               total_fail++; \
+               return; \
+       \
 }
 
 #define TC_ASSERT_NOT_NULL(api_name, handle) \
 {\
-    if (handle == NULL) {\
-            printf("\n[%s][Line : %d] FAIL , %s : API returned NULL ", __func__, __LINE__, api_name); \
-            total_fail++; \
-            return; \
-        }\
+       if (handle == NULL) {\
+               printf("\n[%s][Line : %d] FAIL , %s : API returned NULL ", __func__, __LINE__, api_name); \
+               total_fail++; \
+               return; \
+       \
 }
 
 #define TC_SUCCESS_RESULT() \
 {\
-    printf("\n[%s] PASS \n", __func__); \
-    total_pass++; \
+       printf("\n[%s] PASS \n", __func__); \
+       total_pass++; \
 }
 
 #define TC_FREE_MEMORY(buffer) \
 {\
-    if (buffer != NULL) {\
-            free(buffer); \
-            buffer = NULL; \
-        }\
+       if (buffer != NULL) {\
+               free(buffer); \
+               buffer = NULL; \
+       \
 }
 
 #endif