diff --git a/apps/examples/testcase/le_tc/kernel/itc_environ.c b/apps/examples/testcase/le_tc/kernel/itc_environ.c index e056324ca9..b3bbf6dba7 100644 --- a/apps/examples/testcase/le_tc/kernel/itc_environ.c +++ b/apps/examples/testcase/le_tc/kernel/itc_environ.c @@ -45,7 +45,7 @@ * Preconditions :none * Postconditions :none */ -static void itc_environ_setenv_p(void) +static void itc_environ_setenv_pos(void) { char *buffer = ""; char *result; @@ -74,7 +74,7 @@ static void itc_environ_setenv_p(void) * Preconditions :none * Postconditions :none */ -static void itc_environ_getenv_n(void) +static void itc_environ_getenv_neg(void) { int exec_index; char var_buf[BUFF_LEN]; @@ -103,8 +103,8 @@ static void itc_environ_getenv_n(void) int itc_environ_main(void) { - itc_environ_setenv_p(); - itc_environ_getenv_n(); + itc_environ_setenv_pos(); + itc_environ_getenv_neg(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/itc_libc_semaphore.c b/apps/examples/testcase/le_tc/kernel/itc_libc_semaphore.c index 388776f39a..66bb91a365 100644 --- a/apps/examples/testcase/le_tc/kernel/itc_libc_semaphore.c +++ b/apps/examples/testcase/le_tc/kernel/itc_libc_semaphore.c @@ -41,7 +41,7 @@ * @Preconditions :NA * @Postconditions :NA */ -static void itc_libc_semaphore_getprotocol_n_no_sem_init(void) +static void itc_libc_semaphore_getprotocol_no_sem_init_neg(void) { sem_t sem; int protocol; @@ -62,6 +62,6 @@ static void itc_libc_semaphore_getprotocol_n_no_sem_init(void) int itc_libc_semaphore_main(void) { - itc_libc_semaphore_getprotocol_n_no_sem_init(); + itc_libc_semaphore_getprotocol_no_sem_init_neg(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/itc_pthread.c b/apps/examples/testcase/le_tc/kernel/itc_pthread.c index 86979b1fde..6614ee30ba 100644 --- a/apps/examples/testcase/le_tc/kernel/itc_pthread.c +++ b/apps/examples/testcase/le_tc/kernel/itc_pthread.c @@ -175,7 +175,7 @@ static void *task_thread(void *param) * Preconditions :none * Postconditions :none */ -static void itc_pthread_pthread_kill_n_rekill(void) +static void itc_pthread_pthread_kill_rekill_neg(void) { int ret_chk; pthread_t thread; @@ -208,7 +208,7 @@ static void itc_pthread_pthread_kill_n_rekill(void) * Preconditions :none * Postconditions :none */ -static void itc_pthread_pthread_cond_init_destroy_n(void) +static void itc_pthread_pthread_cond_init_destroy_neg(void) { int ret_chk; pthread_condattr_t attr; @@ -242,7 +242,7 @@ static void itc_pthread_pthread_cond_init_destroy_n(void) * Preconditions :none * Postconditions :none */ -static void itc_pthread_setgetname_np_p_reset_name(void) +static void itc_pthread_setgetname_np_reset_name_pos(void) { int ret_chk; int exec_index; @@ -280,7 +280,7 @@ static void itc_pthread_setgetname_np_p_reset_name(void) * Preconditions :none * Postconditions :none */ -static void itc_pthread_equal_pthread_self_p(void) +static void itc_pthread_equal_pthread_self_pos(void) { int ret_chk; @@ -304,7 +304,7 @@ static void itc_pthread_equal_pthread_self_p(void) * Preconditions :none * Postconditions :none */ -static void itc_pthread_mutex_init_destroy_p_multitime(void) +static void itc_pthread_mutex_init_destroy_multitime_pos(void) { pthread_mutexattr_t attr; int ret_chk; @@ -342,7 +342,7 @@ static void itc_pthread_mutex_init_destroy_p_multitime(void) * Preconditions :pthread_key_create * Postconditions :none */ -static void itc_pthread_key_create_set_get_delete_specific_p_multitime(void) +static void itc_pthread_key_create_set_get_delete_specific_multitime_pos(void) { int ret_chk; g_flag = false; @@ -363,11 +363,11 @@ static void itc_pthread_key_create_set_get_delete_specific_p_multitime(void) int itc_pthread_main(void) { - itc_pthread_pthread_kill_n_rekill(); - itc_pthread_pthread_cond_init_destroy_n(); - itc_pthread_setgetname_np_p_reset_name(); - itc_pthread_equal_pthread_self_p(); - itc_pthread_mutex_init_destroy_p_multitime(); - itc_pthread_key_create_set_get_delete_specific_p_multitime(); + itc_pthread_pthread_kill_rekill_neg(); + itc_pthread_pthread_cond_init_destroy_neg(); + itc_pthread_setgetname_np_reset_name_pos(); + itc_pthread_equal_pthread_self_pos(); + itc_pthread_mutex_init_destroy_multitime_pos(); + itc_pthread_key_create_set_get_delete_specific_multitime_pos(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/itc_sched.c b/apps/examples/testcase/le_tc/kernel/itc_sched.c index ad9caccae9..09541a48b4 100644 --- a/apps/examples/testcase/le_tc/kernel/itc_sched.c +++ b/apps/examples/testcase/le_tc/kernel/itc_sched.c @@ -92,7 +92,7 @@ static void thread_cleanup(pthread_t* array, int thread_cnt) * Preconditions :none * Postconditions :none */ -static void itc_sched_setget_scheduler_param_p_all_priority(void) +static void itc_sched_setget_scheduler_param_all_priority_pos(void) { int ret_chk = ERROR; struct sched_param st_setparam; @@ -140,6 +140,35 @@ static void itc_sched_setget_scheduler_param_p_all_priority(void) TC_SUCCESS_RESULT(); } +static void itc_sched_set_scheduler_invalid_pid_neg(void) +{ + int ret_chk = ERROR; + pid_t pid = -1; + struct sched_param st_setparam; + int policy = SCHED_FIFO; + + + ret_chk = sched_setscheduler(pid, policy, &st_setparam); + TC_ASSERT_NEQ("sched_setscheduler", ret_chk, ESRCH); + + TC_SUCCESS_RESULT(); +} + +static void itc_sched_set_scheduler_invalid_policy_neg(void) +{ + int ret_chk = ERROR; + struct sched_param *st_setparam = NULL; + int policy = -1; + + + ret_chk = sched_setscheduler(getpid(), policy, st_setparam); + TC_ASSERT_NEQ("sched_setscheduler", ret_chk, ESRCH); + + TC_SUCCESS_RESULT(); +} + + + /** * @fn :itc_sched_self_p * @brief :Return current thread tcb @@ -148,7 +177,7 @@ static void itc_sched_setget_scheduler_param_p_all_priority(void) * Preconditions :none * Postconditions :none */ -static void itc_sched_self_p(void) +static void itc_sched_self_pos(void) { pthread_t thread_id[THREAD_CNT]; int ret_chk; @@ -171,8 +200,10 @@ static void itc_sched_self_p(void) int itc_sched_main(void) { - itc_sched_setget_scheduler_param_p_all_priority(); - itc_sched_self_p(); + itc_sched_setget_scheduler_param_all_priority_pos(); + itc_sched_set_scheduler_invalid_policy_neg(); + itc_sched_set_scheduler_invalid_pid_neg(); + itc_sched_self_pos(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/itc_semaphore.c b/apps/examples/testcase/le_tc/kernel/itc_semaphore.c index 32bb2cf211..cf44d9dcf8 100644 --- a/apps/examples/testcase/le_tc/kernel/itc_semaphore.c +++ b/apps/examples/testcase/le_tc/kernel/itc_semaphore.c @@ -38,7 +38,7 @@ * Preconditions :none * Postconditions :none */ -static void itc_semaphore_sem_init_destroy_p_multitime(void) +static void itc_semaphore_sem_init_destroy_multitime_pos(void) { sem_t sem; int ret_chk; @@ -62,7 +62,7 @@ static void itc_semaphore_sem_init_destroy_p_multitime(void) int itc_semaphore_main(void) { - itc_semaphore_sem_init_destroy_p_multitime(); + itc_semaphore_sem_init_destroy_multitime_pos(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/itc_timer.c b/apps/examples/testcase/le_tc/kernel/itc_timer.c index 290501d8d3..0b854ed21c 100644 --- a/apps/examples/testcase/le_tc/kernel/itc_timer.c +++ b/apps/examples/testcase/le_tc/kernel/itc_timer.c @@ -35,7 +35,7 @@ * Preconditions :Creation of timer_id(timer_create) * Postconditions :none */ -static void itc_timer_set_time_n_after_delete(void) +static void itc_timer_set_time_after_delete_neg(void) { int ret_chk = ERROR; clockid_t clockid = CLOCK_REALTIME; @@ -72,7 +72,7 @@ static void itc_timer_set_time_n_after_delete(void) * Preconditions :Creation of timer_id(timer_create) * Postconditions :none */ -static void itc_timer_get_time_n_after_delete(void) +static void itc_timer_get_time_after_delete_neg(void) { int ret_chk = ERROR; clockid_t clockid = CLOCK_REALTIME; @@ -111,8 +111,8 @@ static void itc_timer_get_time_n_after_delete(void) int itc_timer_main(void) { - itc_timer_set_time_n_after_delete(); - itc_timer_get_time_n_after_delete(); + itc_timer_set_time_after_delete_neg(); + itc_timer_get_time_after_delete_neg(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_clock.c b/apps/examples/testcase/le_tc/kernel/tc_clock.c index 1a5bb5c54a..5d8c955e95 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_clock.c +++ b/apps/examples/testcase/le_tc/kernel/tc_clock.c @@ -33,7 +33,7 @@ const long double l_day = 86400; extern struct timespec g_basetime; - +#define CLOCK_NEG -1 #define CLOCK_ERR 2 #define SEC_PER_MIN ((time_t)60) #define SEC_PER_HOUR ((time_t)60 * SEC_PER_MIN) @@ -52,7 +52,7 @@ extern struct timespec g_basetime; * Postconditions :none * @return :void */ -static void tc_clock_clock_getres(void) +static void tc_clock_clock_getres_pos(void) { int ret_chk; struct timespec st_res; @@ -66,6 +66,14 @@ static void tc_clock_clock_getres(void) 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(); +} + +static void tc_clock_clock_getres_neg(void) +{ + int ret_chk; + struct timespec st_res; + ret_chk = clock_getres(33 , &st_res); TC_ASSERT_EQ("clock_getres", ret_chk, ERROR); @@ -81,15 +89,25 @@ static void tc_clock_clock_getres(void) * Postconditions :none * @return :void */ -static void tc_clock_clock_set_get_time(void) + + +static void tc_clock_clock_get_time_pos(void) { int ret_chk; struct timespec stime; struct timespec gtime; - ret_chk = clock_gettime(CLOCK_ERR, &stime); - TC_ASSERT_EQ("clock_gettime", ret_chk, ERROR); - TC_ASSERT_EQ("clock_gettime", errno, EINVAL); + ret_chk = clock_gettime(CLOCK_REALTIME, &stime); + TC_ASSERT_EQ("clock_gettime", ret_chk, OK); + + TC_SUCCESS_RESULT(); +} + +static void tc_clock_clock_set_time_pos(void) +{ + int ret_chk; + struct timespec stime; + struct timespec gtime; ret_chk = clock_gettime(CLOCK_REALTIME, &stime); TC_ASSERT_EQ("clock_gettime", ret_chk, OK); @@ -111,16 +129,47 @@ static void tc_clock_clock_set_get_time(void) stime.tv_sec -= l_day; /* Setting original time to system */ + ret_chk = clock_settime(CLOCK_REALTIME, &stime); + TC_ASSERT_EQ("clock_setime", ret_chk, OK); + + TC_SUCCESS_RESULT(); +} + +static void tc_clock_clock_set_time_neg(void) +{ + int ret_chk; + struct timespec stime; + ret_chk = clock_settime(CLOCK_ERR, &stime); - TC_ASSERT_EQ("clock_settime", ret_chk, ERROR); TC_ASSERT_EQ("clock_settime", errno, EINVAL); - ret_chk = clock_settime(CLOCK_REALTIME, &stime); - TC_ASSERT_EQ("clock_setime", ret_chk, OK); + TC_SUCCESS_RESULT(); +} + +static void tc_clock_clock_set_time_nclock_neg(void) +{ + int ret_chk; + struct timespec stime; + + ret_chk = clock_settime(CLOCK_NEG, &stime); + TC_ASSERT_EQ("clock_settime", errno, EINVAL); + + TC_SUCCESS_RESULT(); +} + +static void tc_clock_clock_get_time_invalid_clock_neg(void) +{ + int ret_chk; + struct timespec stime; + + ret_chk = clock_gettime(CLOCK_ERR, &stime); + TC_ASSERT_EQ("clock_gettime", errno, EINVAL); TC_SUCCESS_RESULT(); } + + /** * @fn :tc_clock_clock_gettimeofday * @brief :get the time as well as a timezone @@ -130,7 +179,7 @@ static void tc_clock_clock_set_get_time(void) * Postconditions :none * @return :void */ -static void tc_clock_clock_gettimeofday(void) +static void tc_clock_clock_gettimeofday_pos(void) { int ret_chk; struct timeval tv1; @@ -148,6 +197,15 @@ static void tc_clock_clock_gettimeofday(void) if (tv2.tv_sec == tv1.tv_sec + SEC_2) { TC_ASSERT_GEQ("gettimeofday", tv2.tv_usec, tv1.tv_usec); } + + TC_SUCCESS_RESULT(); +} + + +static void tc_clock_clock_gettimeofday_neg(void) +{ + int ret_chk; + #ifdef CONFIG_DEBUG ret_chk = gettimeofday(NULL, NULL); TC_ASSERT_EQ("gettimeofday", ret_chk, ERROR); @@ -165,7 +223,7 @@ static void tc_clock_clock_gettimeofday(void) * Postconditions :none * @return :void */ -static void tc_clock_clock_abstime2ticks(void) +static void tc_clock_clock_abstime2ticks_pos(void) { int fd; int ret; @@ -184,10 +242,15 @@ static void tc_clock_clock_abstime2ticks(void) int clock_main(void) { - tc_clock_clock_gettimeofday(); - tc_clock_clock_set_get_time(); - tc_clock_clock_getres(); - tc_clock_clock_abstime2ticks(); - + tc_clock_clock_gettimeofday_pos(); + tc_clock_clock_gettimeofday_neg(); + tc_clock_clock_get_time_invalid_clock_neg(); + tc_clock_clock_get_time_pos(); + tc_clock_clock_set_time_pos(); + tc_clock_clock_set_time_nclock_neg(); + tc_clock_clock_set_time_neg(); + tc_clock_clock_getres_pos(); + tc_clock_clock_getres_neg(); + tc_clock_clock_abstime2ticks_pos(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_environ.c b/apps/examples/testcase/le_tc/kernel/tc_environ.c index a5f950ff5e..49911d8036 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_environ.c +++ b/apps/examples/testcase/le_tc/kernel/tc_environ.c @@ -45,7 +45,7 @@ * @failcase :When setenv function returns non zero value or getenv return different value which was set or unsetenv function returns non zero value. * @Preconditions :NA */ -static void tc_environ_setenv_getenv_unsetenv(void) +static void tc_environ_setenv_getenv_unsetenv_pos(void) { int ret_chk = ERROR; const char *psz_name = "abc"; @@ -56,8 +56,6 @@ static void tc_environ_setenv_getenv_unsetenv(void) ret_chk = setenv(psz_name, psz_value, 1); TC_ASSERT_EQ_CLEANUP("setenv", ret_chk, OK, clearenv()); - psz_getvalue = getenv(NULL); - TC_ASSERT_EQ("getenv", psz_getvalue, NULL); psz_getvalue = getenv(psz_name); TC_ASSERT_NEQ_CLEANUP("getenv", psz_getvalue, NULL, clearenv()); @@ -75,23 +73,11 @@ static void tc_environ_setenv_getenv_unsetenv(void) TC_ASSERT_NEQ_CLEANUP("getenv", psz_getvalue, NULL, clearenv()); TC_ASSERT_NEQ_CLEANUP("getenv", strcmp(psz_getvalue, psz_value), 0, 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); TC_ASSERT_EQ("unsetenv", ret_chk, OK); - /* getvalue should be null */ - - psz_getvalue = getenv("arv"); - TC_ASSERT_EQ("getenv", psz_getvalue, NULL); - - ret_chk = setenv(NULL, psz_value, 0); - TC_ASSERT_EQ("setenv", ret_chk, ERROR); ret_chk = setenv(psz_name, NULL, 1); TC_ASSERT_EQ("setenv", ret_chk, OK); @@ -102,6 +88,44 @@ static void tc_environ_setenv_getenv_unsetenv(void) clearenv(); TC_SUCCESS_RESULT(); } +static void tc_environ_getenv_neg(void) +{ + char *psz_getvalue = NULL; + + /* random value, getenv should fail */ + + psz_getvalue = getenv("arv"); + TC_ASSERT_EQ_CLEANUP("getenv", psz_getvalue, NULL, clearenv()); + + TC_SUCCESS_RESULT(); +} + +static void tc_environ_setenv_name_null_neg(void) +{ + int ret_chk = ERROR; + const char *psz_value = "test"; + char *psz_getvalue = NULL; + + /*setting var name NULL should fail*/ + ret_chk = setenv(NULL, psz_value, 0); + TC_ASSERT_EQ_CLEANUP("setenv", ret_chk, ERROR, clearenv()); + + clearenv(); + TC_SUCCESS_RESULT(); +} + +static void tc_environ_setenv_empty_name_neg(void) +{ + int ret_chk = ERROR; + const char *psz_value = "pqr"; + + /*setting var empty string should fail*/ + ret_chk = setenv('\0', psz_value, 1); + TC_ASSERT_EQ_CLEANUP("setenv", ret_chk, ERROR, clearenv()); + + + TC_SUCCESS_RESULT(); +} /** * @fn :TC_clearenv @@ -113,7 +137,7 @@ static void tc_environ_setenv_getenv_unsetenv(void) * @failcase :When setenv function returns non zero value or clearenv function returns non zero value. * @Preconditions :setenv */ -static void tc_environ_clearenv(void) +static void tc_environ_clearenv_pos(void) { int ret_chk = ERROR; const char *psz_name = "abc"; @@ -143,7 +167,7 @@ static void tc_environ_clearenv(void) * @failcase :When putenv function returns non zero value. * @Preconditions :NA */ -static void tc_environ_putenv(void) +static void tc_environ_putenv_pos(void) { int ret_chk; char *psz_getvalue = NULL; @@ -165,6 +189,14 @@ static void tc_environ_putenv(void) TC_ASSERT_NEQ_CLEANUP("getenv", psz_getvalue, NULL, clearenv()); TC_ASSERT_EQ_CLEANUP("getenv", strcmp(psz_getvalue, "D:"), 0, clearenv()); + clearenv(); + TC_SUCCESS_RESULT(); +} + +static void tc_environ_putenv_null_neg(void) +{ + int ret_chk; + ret_chk = putenv(NULL); TC_ASSERT_EQ("putenv", ret_chk, ERROR); @@ -182,7 +214,7 @@ static void tc_environ_putenv(void) * @failcase :some variables are not matched. * @Preconditions :NA */ -static void tc_environ_get_environ_ptr(void) +static void tc_environ_get_environ_ptr_pos(void) { char env_arr[ENV_TEST_MAX_NUM][ENV_TEST_LEN * 2]; size_t env_size; @@ -228,10 +260,14 @@ static void tc_environ_get_environ_ptr(void) int environ_main(void) { - tc_environ_setenv_getenv_unsetenv(); - tc_environ_clearenv(); - tc_environ_putenv(); - tc_environ_get_environ_ptr(); + tc_environ_setenv_getenv_unsetenv_pos(); + tc_environ_getenv_neg(); + tc_environ_setenv_name_null_neg(); + tc_environ_setenv_empty_name_neg(); + tc_environ_clearenv_pos(); + tc_environ_putenv_pos(); + tc_environ_putenv_null_neg(); + tc_environ_get_environ_ptr_pos(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_errno.c b/apps/examples/testcase/le_tc/kernel/tc_errno.c index d1d29f0058..f99ea52c94 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_errno.c +++ b/apps/examples/testcase/le_tc/kernel/tc_errno.c @@ -38,7 +38,7 @@ * Postconditions :none * @return :void */ -static void tc_errno_set_get_errno(void) +static void tc_errno_set_get_errno_pos(void) { int ret_chk = 0; int errcode; @@ -76,7 +76,7 @@ static void tc_errno_set_get_errno(void) int errno_main(void) { - tc_errno_set_get_errno(); + tc_errno_set_get_errno_pos(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_group.c b/apps/examples/testcase/le_tc/kernel/tc_group.c index 1ed5c5f03a..12c98d8637 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_group.c +++ b/apps/examples/testcase/le_tc/kernel/tc_group.c @@ -38,7 +38,7 @@ * @return :void */ -static void tc_group_group_add_find_remove_child(void) +static void tc_group_group_add_find_remove_child_pos(void) { int fd; int ret_chk; @@ -57,7 +57,7 @@ static void tc_group_group_add_find_remove_child(void) * Preconditions :Callback (sched_self) should return valid tcb_s* * @return :void */ -static void tc_group_group_alloc_free_child(void) +static void tc_group_group_alloc_free_child_pos(void) { int fd; int ret_chk; @@ -77,7 +77,7 @@ static void tc_group_group_alloc_free_child(void) * @return :void */ -static void tc_group_group_exit_child(void) +static void tc_group_group_exit_child_pos(void) { int fd; int ret_chk; @@ -96,7 +96,7 @@ static void tc_group_group_exit_child(void) * Preconditions :Callback (sched_self) should return valid tcb_s* * @return :void */ -static void tc_group_group_removechildren(void) +static void tc_group_group_removechildren_pos(void) { int fd; int ret_chk; @@ -114,10 +114,10 @@ static void tc_group_group_removechildren(void) int group_main(void) { - tc_group_group_add_find_remove_child(); - tc_group_group_alloc_free_child(); - tc_group_group_exit_child(); - tc_group_group_removechildren(); + tc_group_group_add_find_remove_child_pos(); + tc_group_group_alloc_free_child_pos(); + tc_group_group_exit_child_pos(); + tc_group_group_removechildren_pos(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_irq.c b/apps/examples/testcase/le_tc/kernel/tc_irq.c index 9d1b6dc9c2..7274ed6bc5 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_irq.c +++ b/apps/examples/testcase/le_tc/kernel/tc_irq.c @@ -41,7 +41,7 @@ * @return :void */ -static void tc_irq_fin_wait(void) +static void tc_irq_fin_wait_pos(void) { struct timer_notify_s notify; notify.arg = NULL; @@ -77,7 +77,7 @@ static void tc_irq_fin_wait(void) int irq_main(void) { - tc_irq_fin_wait(); + tc_irq_fin_wait_pos(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_libc_sched.c b/apps/examples/testcase/le_tc/kernel/tc_libc_sched.c index ed03323689..6674c52d16 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_libc_sched.c +++ b/apps/examples/testcase/le_tc/kernel/tc_libc_sched.c @@ -41,13 +41,10 @@ * Postconditions :NA * @return :void */ -static void tc_libc_sched_sched_get_priority_max(void) +static void tc_libc_sched_sched_get_priority_max_pos(void) { int ret_chk; - ret_chk = sched_get_priority_max(SCHED_ERROR); - TC_ASSERT_EQ("sched_get_priority_max", ret_chk, ERROR); - ret_chk = sched_get_priority_max(SCHED_FIFO); TC_ASSERT_EQ("sched_get_priority_max", ret_chk, SCHED_PRIORITY_MAX); @@ -57,6 +54,18 @@ static void tc_libc_sched_sched_get_priority_max(void) TC_SUCCESS_RESULT(); } +static void tc_libc_sched_sched_get_priority_max_sch_error_neg(void) +{ + int ret_chk; + + ret_chk = sched_get_priority_max(SCHED_ERROR); + TC_ASSERT_EQ("sched_get_priority_max", ret_chk, ERROR); + + + + TC_SUCCESS_RESULT(); +} + /** * @fn :tc_libc_sched_sched_get_priority_min * @brief :returns the minimum priority value @@ -66,7 +75,7 @@ static void tc_libc_sched_sched_get_priority_max(void) * Postconditions :NA * @return :void */ -static void tc_libc_sched_sched_get_priority_min(void) +static void tc_libc_sched_sched_get_priority_min_pos(void) { int ret_chk; @@ -82,6 +91,17 @@ static void tc_libc_sched_sched_get_priority_min(void) TC_SUCCESS_RESULT(); } +static void tc_libc_sched_sched_get_priority_min_invalid_sched_neg(void) +{ + int ret_chk; + + ret_chk = sched_get_priority_min(SCHED_ERROR); + TC_ASSERT_EQ("sched_get_priority_min", ret_chk, ERROR); + + TC_SUCCESS_RESULT(); +} + + /** * @fn :tc_libc_sched_task_setcanceltype * @brief :This tc tests tc_libc_sched_task_setcanceltype() @@ -96,7 +116,7 @@ static void tc_libc_sched_sched_get_priority_min(void) * @return :void */ #ifndef CONFIG_CANCELLATION_POINTS -static void tc_libc_sched_task_setcanceltype(void) +static void tc_libc_sched_task_setcanceltype_pos(void) { int type; int oldtype; @@ -116,10 +136,12 @@ static void tc_libc_sched_task_setcanceltype(void) int libc_sched_main(void) { - tc_libc_sched_sched_get_priority_max(); - tc_libc_sched_sched_get_priority_min(); + tc_libc_sched_sched_get_priority_max_pos(); + tc_libc_sched_sched_get_priority_max_sch_error_neg(); + tc_libc_sched_sched_get_priority_min_pos(); + tc_libc_sched_sched_get_priority_min_invalid_sched_neg(); #ifndef CONFIG_CANCELLATION_POINTS - tc_libc_sched_task_setcanceltype(); + tc_libc_sched_task_setcanceltype_pos(); #endif return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_libc_semaphore.c b/apps/examples/testcase/le_tc/kernel/tc_libc_semaphore.c index eb1e981793..bf8da042db 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_libc_semaphore.c +++ b/apps/examples/testcase/le_tc/kernel/tc_libc_semaphore.c @@ -46,7 +46,7 @@ * Postconditions :NA * @return :total_pass on success. */ -static void tc_libc_semaphore_sem_init(void) +static void tc_libc_semaphore_sem_init_pos(void) { sem_t sem; unsigned int value = SEM_VALUE; @@ -55,17 +55,65 @@ static void tc_libc_semaphore_sem_init(void) uint8_t sem_flag; #endif + ret_chk = sem_init(&sem, PSHARED, value); + TC_ASSERT_EQ("sem_init", ret_chk, OK); + TC_ASSERT_EQ("sem_init", sem.semcount, value); +#ifdef CONFIG_PRIORITY_INHERITANCE + sem_flag = FLAGS_INITIALIZED; + sem_flag &= ~(PRIOINHERIT_FLAGS_DISABLE); + TC_ASSERT_EQ("sem_init", sem.flags, sem_flag); +#if CONFIG_SEM_PREALLOCHOLDERS > 0 + TC_ASSERT_EQ("sem_init", sem.hhead, NULL); +#else + TC_ASSERT_EQ("sem_init", sem.holder.htcb, NULL); + TC_ASSERT_EQ("sem_init", sem.holder.counts, 0); +#endif +#endif + + TC_SUCCESS_RESULT(); + return; +} + +static void tc_libc_semaphore_sem_init_null_sem_neg(void) +{ + sem_t sem; + int ret_chk; +#ifdef CONFIG_PRIORITY_INHERITANCE + uint8_t sem_flag; +#endif + ret_chk = sem_init(NULL, PSHARED, 0); TC_ASSERT_EQ("sem_init", ret_chk, ERROR); TC_ASSERT_EQ("sem_init", get_errno(), EINVAL); +#ifdef CONFIG_PRIORITY_INHERITANCE + sem_flag = FLAGS_INITIALIZED; + sem_flag &= ~(PRIOINHERIT_FLAGS_DISABLE); + TC_ASSERT_EQ("sem_init", sem.flags, sem_flag); +#if CONFIG_SEM_PREALLOCHOLDERS > 0 + TC_ASSERT_EQ("sem_init", sem.hhead, NULL); +#else + TC_ASSERT_EQ("sem_init", sem.holder.htcb, NULL); + TC_ASSERT_EQ("sem_init", sem.holder.counts, 0); +#endif +#endif + + TC_SUCCESS_RESULT(); + return; +} + +static void tc_libc_semaphore_sem_init_invalid_semvalue_neg(void) +{ + sem_t sem; + int ret_chk; +#ifdef CONFIG_PRIORITY_INHERITANCE + uint8_t sem_flag; +#endif + ret_chk = sem_init(&sem, PSHARED, SEM_VALUE_MAX + 1); TC_ASSERT_EQ("sem_init", ret_chk, ERROR); TC_ASSERT_EQ("sem_init", get_errno(), EINVAL); - - ret_chk = sem_init(&sem, PSHARED, value); - TC_ASSERT_EQ("sem_init", ret_chk, OK); - TC_ASSERT_EQ("sem_init", sem.semcount, value); + #ifdef CONFIG_PRIORITY_INHERITANCE sem_flag = FLAGS_INITIALIZED; sem_flag &= ~(PRIOINHERIT_FLAGS_DISABLE); @@ -93,7 +141,25 @@ static void tc_libc_semaphore_sem_init(void) * Postconditions :NA * @return :total_pass on success. */ -static void tc_libc_semaphore_sem_getvalue(void) +static void tc_libc_semaphore_sem_getvalue_pos(void) +{ + sem_t sem; + unsigned int value = SEM_VALUE; + int sval; + int ret_chk; + + ret_chk = sem_init(&sem, PSHARED, value); + TC_ASSERT_EQ("sem_init", ret_chk, OK); + + ret_chk = sem_getvalue(&sem, &sval); + TC_ASSERT_EQ("sem_getvalue", ret_chk, OK); + TC_ASSERT_EQ("sem_getvalue", sval, value); + + TC_SUCCESS_RESULT(); + return; +} + +static void tc_libc_semaphore_sem_getvalue_null_sempointer_neg(void) { sem_t sem; unsigned int value = SEM_VALUE; @@ -106,15 +172,24 @@ static void tc_libc_semaphore_sem_getvalue(void) ret_chk = sem_getvalue(NULL, &sval); TC_ASSERT_EQ("sem_getvalue", ret_chk, ERROR); TC_ASSERT_EQ("sem_getvalue", get_errno(), EINVAL); + TC_SUCCESS_RESULT(); + return; +} + + +static void tc_libc_semaphore_sem_getvalue_null_sval_neg(void) +{ + sem_t sem; + unsigned int value = SEM_VALUE; + int ret_chk; + + ret_chk = sem_init(&sem, PSHARED, value); + TC_ASSERT_EQ("sem_init", ret_chk, OK); ret_chk = sem_getvalue(&sem, NULL); TC_ASSERT_EQ("sem_getvalue", ret_chk, ERROR); TC_ASSERT_EQ("sem_getvalue", get_errno(), EINVAL); - - ret_chk = sem_getvalue(&sem, &sval); - TC_ASSERT_EQ("sem_getvalue", ret_chk, OK); - TC_ASSERT_EQ("sem_getvalue", sval, value); - + TC_SUCCESS_RESULT(); return; } @@ -128,7 +203,7 @@ static void tc_libc_semaphore_sem_getvalue(void) * Postconditions :NA * @return :total_pass on success. */ -static void tc_libc_semaphore_sem_getprotocol(void) +static void tc_libc_semaphore_sem_getprotocol_pos(void) { sem_t sem; unsigned int value = SEM_VALUE; @@ -151,9 +226,13 @@ static void tc_libc_semaphore_sem_getprotocol(void) int libc_semaphore_main(void) { - tc_libc_semaphore_sem_getvalue(); - tc_libc_semaphore_sem_getprotocol(); - tc_libc_semaphore_sem_init(); + tc_libc_semaphore_sem_getvalue_pos(); + tc_libc_semaphore_sem_getvalue_null_sempointer_neg(); + tc_libc_semaphore_sem_getvalue_null_sval_neg(); + tc_libc_semaphore_sem_getprotocol_pos(); + tc_libc_semaphore_sem_init_pos(); + tc_libc_semaphore_sem_init_null_sem_neg(); + tc_libc_semaphore_sem_init_invalid_semvalue_neg(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_libc_signal.c b/apps/examples/testcase/le_tc/kernel/tc_libc_signal.c index 46866ecd25..2f205d6aa3 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_libc_signal.c +++ b/apps/examples/testcase/le_tc/kernel/tc_libc_signal.c @@ -50,7 +50,7 @@ * Preconditions :none * @return :void */ -static void tc_libc_signal_sigemptyset(void) +static void tc_libc_signal_sigemptyset_pos(void) { int ret_chk; sigset_t sigset = ALL_SIGNAL_SET; @@ -71,7 +71,7 @@ static void tc_libc_signal_sigemptyset(void) * Preconditions :none * @return :void */ -static void tc_libc_signal_sigfillset(void) +static void tc_libc_signal_sigfillset_pos(void) { int ret_chk; sigset_t sigset = NULL_SIGNAL_SET; @@ -95,15 +95,12 @@ static void tc_libc_signal_sigfillset(void) * Preconditions :none * @return :void */ -static void tc_libc_signal_sigaddset(void) +static void tc_libc_signal_sigaddset_pos(void) { int ret_chk; sigset_t sigset = NULL_SIGNAL_SET; sigset_t sigset_expected = NULL_SIGNAL_SET | SIGNO2SET(SIG1); - ret_chk = sigaddset(&sigset, MAX_SIGNO + 1); - TC_ASSERT_EQ("sigaddset", ret_chk, ERROR); - ret_chk = sigaddset(&sigset, SIG1); TC_ASSERT_EQ("sigaddset", ret_chk, OK); TC_ASSERT_EQ("sigaddset", sigset, sigset_expected); @@ -111,6 +108,19 @@ static void tc_libc_signal_sigaddset(void) TC_SUCCESS_RESULT(); } +static void tc_libc_signal_sigaddset_neg(void) +{ + int ret_chk; + sigset_t sigset = NULL_SIGNAL_SET; + sigset_t sigset_expected = NULL_SIGNAL_SET | SIGNO2SET(SIG1); + + ret_chk = sigaddset(&sigset, MAX_SIGNO + 1); + TC_ASSERT_EQ("sigaddset", ret_chk, ERROR); + + TC_SUCCESS_RESULT(); +} + + /** * @fn :tc_libc_signal_sigdelset * @brief :tc_libc_signal_sigdelset test sigdelset function @@ -121,15 +131,12 @@ static void tc_libc_signal_sigaddset(void) * Preconditions :none * @return :void */ -static void tc_libc_signal_sigdelset(void) +static void tc_libc_signal_sigdelset_pos(void) { int ret_chk; sigset_t sigset = ALL_SIGNAL_SET; sigset_t sigset_expected = ALL_SIGNAL_SET & (~(SIGNO2SET(SIG1))); - ret_chk = sigdelset(&sigset, MAX_SIGNO + 1); - TC_ASSERT_EQ("sigdelset", ret_chk, ERROR); - ret_chk = sigdelset(&sigset, SIG1); TC_ASSERT_EQ("sigdelset", ret_chk, OK); TC_ASSERT_EQ("sigdelset", sigset, sigset_expected); @@ -137,6 +144,19 @@ static void tc_libc_signal_sigdelset(void) TC_SUCCESS_RESULT(); } +static void tc_libc_signal_sigdelset_neg(void) +{ + int ret_chk; + sigset_t sigset = ALL_SIGNAL_SET; + sigset_t sigset_expected = ALL_SIGNAL_SET & (~(SIGNO2SET(SIG1))); + + ret_chk = sigdelset(&sigset, MAX_SIGNO + 1); + TC_ASSERT_EQ("sigdelset", ret_chk, ERROR); + + TC_SUCCESS_RESULT(); +} + + /** * @fn :tc_libc_signal_sigismember * @brief :tc_libc_signal_sigismember test sigismember function @@ -149,14 +169,11 @@ static void tc_libc_signal_sigdelset(void) * @return :void */ -static void tc_libc_signal_sigismember(void) +static void tc_libc_signal_sigismember_pos(void) { int ret_chk; sigset_t sigset = NULL_SIGNAL_SET | SIGNO2SET(SIG1); - ret_chk = sigismember(&sigset, MAX_SIGNO + 1); - TC_ASSERT_EQ("sigismember", ret_chk, ERROR); - ret_chk = sigismember(&sigset, SIG1); TC_ASSERT_EQ("sigismember", ret_chk, true); @@ -166,6 +183,19 @@ static void tc_libc_signal_sigismember(void) TC_SUCCESS_RESULT(); } + +static void tc_libc_signal_sigismember_neg(void) +{ + int ret_chk; + sigset_t sigset = NULL_SIGNAL_SET | SIGNO2SET(SIG1); + + ret_chk = sigismember(&sigset, MAX_SIGNO + 1); + TC_ASSERT_EQ("sigismember", ret_chk, ERROR); + + TC_SUCCESS_RESULT(); +} + + /** * @fn :tc_libc_signal_sigignore * @brief :tc_libc_signal_sigignore test sigignore function @@ -177,13 +207,10 @@ static void tc_libc_signal_sigismember(void) * @return :void */ -static void tc_libc_signal_sigignore(void) +static void tc_libc_signal_sigignore_pos(void) { int ret_chk; - ret_chk = sigignore(MAX_SIGNO + 1); - TC_ASSERT_EQ("sigignore", ret_chk, ERROR); - ret_chk = sigignore(SIG1); TC_ASSERT_EQ("sigignore", ret_chk, OK); @@ -193,6 +220,17 @@ static void tc_libc_signal_sigignore(void) TC_SUCCESS_RESULT(); } +static void tc_libc_signal_sigignore_neg(void) +{ + int ret_chk; + + ret_chk = sigignore(MAX_SIGNO + 1); + TC_ASSERT_EQ("sigignore", ret_chk, ERROR); + + TC_SUCCESS_RESULT(); +} + + #ifndef CONFIG_DISABLE_POSIX_TIMERS /** * @fn :tc_libc_signal_sigpause @@ -206,7 +244,7 @@ static void tc_libc_signal_sigignore(void) * @return :void */ -static void tc_libc_signal_sigpause(void) +static void tc_libc_signal_sigpause_pos(void) { int ret_chk; timer_t timer_id; @@ -214,9 +252,6 @@ static void tc_libc_signal_sigpause(void) struct sigevent st_sigevent; struct itimerspec st_timer_spec_val; - ret_chk = sigpause(MAX_SIGNO + 1); - TC_ASSERT_EQ("sigpause", ret_chk, ERROR); - /* Set and enable alarm */ st_sigevent.sigev_notify = 1; /*SIGEV_SIGNAL*/ st_sigevent.sigev_signo = SIGRTMIN; @@ -242,6 +277,17 @@ static void tc_libc_signal_sigpause(void) timer_delete(timer_id); TC_SUCCESS_RESULT(); } + + +static void tc_libc_signal_sigpause_neg(void) +{ + int ret_chk; + ret_chk = sigpause(MAX_SIGNO + 1); + TC_ASSERT_EQ("sigpause", ret_chk, ERROR); + + + TC_SUCCESS_RESULT(); +} #endif /** @@ -255,13 +301,10 @@ static void tc_libc_signal_sigpause(void) * @return :void */ -static void tc_libc_signal_sigset(void) +static void tc_libc_signal_sigset_pos(void) { int ret_chk; - ret_chk = (int)sigset(MAX_SIGNO + 1, SIG_DFL); - TC_ASSERT_EQ("sigset", ret_chk, ERROR); - ret_chk = (int)sigset(SIG1, SIG_DFL); TC_ASSERT_EQ("sigset", ret_chk, OK); @@ -271,6 +314,16 @@ static void tc_libc_signal_sigset(void) TC_SUCCESS_RESULT(); } +static void tc_libc_signal_sigset_neg(void) +{ + int ret_chk; + + ret_chk = (int)sigset(MAX_SIGNO + 1, SIG_DFL); + TC_ASSERT_EQ("sigset", ret_chk, ERROR); + + TC_SUCCESS_RESULT(); +} + /** * @fn :tc_libc_signal_signal * @brief :tc_libc_signal_signal test signal function @@ -282,13 +335,10 @@ static void tc_libc_signal_sigset(void) * @return :void */ -static void tc_libc_signal_signal(void) +static void tc_libc_signal_signal_pos(void) { int ret_chk; - ret_chk = (int)signal(MAX_SIGNO + 1, SIG_DFL); - TC_ASSERT_EQ("signal", ret_chk, ERROR); - ret_chk = (int)signal(SIG1, SIG_DFL); TC_ASSERT_EQ("signal", ret_chk, OK); @@ -298,6 +348,18 @@ static void tc_libc_signal_signal(void) TC_SUCCESS_RESULT(); } + +static void tc_libc_signal_signal_neg(void) +{ + int ret_chk; + + ret_chk = (int)signal(MAX_SIGNO + 1, SIG_DFL); + TC_ASSERT_EQ("signal", ret_chk, ERROR); + + TC_SUCCESS_RESULT(); +} + + /** * @fn :tc_libc_signal_raise * @brief :tc_libc_signal_raise test sigraise function @@ -309,13 +371,10 @@ static void tc_libc_signal_signal(void) * @return :void */ -static void tc_libc_signal_raise(void) +static void tc_libc_signal_raise_pos(void) { int ret_chk; - ret_chk = raise(MAX_SIGNO + 1); - TC_ASSERT_EQ("raise", ret_chk, ERROR); - ret_chk = raise(SIG1); TC_ASSERT_EQ("raise", ret_chk, OK); @@ -325,6 +384,19 @@ static void tc_libc_signal_raise(void) TC_SUCCESS_RESULT(); } + +static void tc_libc_signal_raise_neg(void) +{ + int ret_chk; + + ret_chk = raise(MAX_SIGNO + 1); + TC_ASSERT_EQ("raise", ret_chk, ERROR); + + TC_SUCCESS_RESULT(); +} + + + /** * @fn :tc_libc_signal_psignal * @brief :tc_libc_signal_psignal test sigpsignal function @@ -337,7 +409,7 @@ static void tc_libc_signal_raise(void) * @return :void */ -static void tc_libc_signal_psignal(void) +static void tc_libc_signal_psignal_neg(void) { siginfo_t siginfo; siginfo.si_signo = SIG1; @@ -384,7 +456,7 @@ static int sigwait_sender(int argc, FAR char *arvg[]) return kill(atoi(arvg[argc - 1]), SIG3); } -static void tc_libc_signal_sigwait(void) +static void tc_libc_signal_sigwait_pos(void) { int recv_pid; int snd_pid; @@ -427,20 +499,28 @@ static void tc_libc_signal_sigwait(void) int libc_signal_main(void) { - tc_libc_signal_psignal(); - tc_libc_signal_raise(); - tc_libc_signal_sigaddset(); - tc_libc_signal_sigdelset(); - tc_libc_signal_sigemptyset(); - tc_libc_signal_sigfillset(); - tc_libc_signal_sigignore(); - tc_libc_signal_sigismember(); - tc_libc_signal_signal(); + tc_libc_signal_psignal_neg(); + tc_libc_signal_raise_pos(); + tc_libc_signal_raise_neg(); + tc_libc_signal_sigaddset_pos(); + tc_libc_signal_sigaddset_neg(); + tc_libc_signal_sigdelset_pos(); + tc_libc_signal_sigdelset_neg(); + tc_libc_signal_sigemptyset_pos(); + tc_libc_signal_sigfillset_pos(); + tc_libc_signal_sigignore_pos(); + tc_libc_signal_sigismember_pos(); + tc_libc_signal_sigismember_neg(); + tc_libc_signal_signal_pos(); + tc_libc_signal_signal_neg(); + #ifndef CONFIG_DISABLE_POSIX_TIMERS - tc_libc_signal_sigpause(); + tc_libc_signal_sigpause_pos(); + tc_libc_signal_sigpause_neg(); #endif - tc_libc_signal_sigset(); - tc_libc_signal_sigwait(); + tc_libc_signal_sigset_pos(); + tc_libc_signal_sigset_neg(); + tc_libc_signal_sigwait_pos(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_libc_stdlib.c b/apps/examples/testcase/le_tc/kernel/tc_libc_stdlib.c index 84d69e579a..6bc7d49fea 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_libc_stdlib.c +++ b/apps/examples/testcase/le_tc/kernel/tc_libc_stdlib.c @@ -79,7 +79,7 @@ static int compare(const void *a, const void *b) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_abs_labs_llabs(void) +static void tc_libc_stdlib_abs_labs_llabs_pos(void) { int val; int ret_chk; @@ -137,7 +137,7 @@ static void tc_libc_stdlib_abs_labs_llabs(void) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_itoa(void) +static void tc_libc_stdlib_itoa_pos(void) { /* ITOA_VAL = 12 */ @@ -175,7 +175,7 @@ static void tc_libc_stdlib_itoa(void) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_qsort(void) +static void tc_libc_stdlib_qsort_pos(void) { /* qsort checks that the number of data is greater than 7 or not. So tc checks with 7 data and 40 data for magic numbers. */ @@ -228,7 +228,7 @@ static void tc_libc_stdlib_qsort(void) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_rand(void) +static void tc_libc_stdlib_rand_pos(void) { int ret_chk = ERROR; @@ -256,7 +256,7 @@ static void tc_libc_stdlib_rand(void) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_random(void) +static void tc_libc_stdlib_random_pos(void) { long int ret_chk = ERROR; @@ -285,7 +285,7 @@ static void tc_libc_stdlib_random(void) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_strtol(void) +static void tc_libc_stdlib_strtol_pos(void) { /* random string used for conversion */ char str_lnum[] = "+2001 60c0c0 -1101110100110100100000 0x6fffff"; @@ -324,7 +324,7 @@ static void tc_libc_stdlib_strtol(void) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_strtoll(void) +static void tc_libc_stdlib_strtoll_pos(void) { char str_llnum[] = "+1856892505 17b00a12b -01100011010110000010001101100 0x6fffff"; char *end_ptr; @@ -363,7 +363,7 @@ static void tc_libc_stdlib_strtoll(void) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_strtoul(void) +static void tc_libc_stdlib_strtoul_pos(void) { char str_ulnum[] = "201 0x60 1100 0x6f"; char *end_ptr; @@ -401,7 +401,7 @@ static void tc_libc_stdlib_strtoul(void) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_strtoull(void) +static void tc_libc_stdlib_strtoull_pos(void) { char str_ullnum[] = "250068492 7b06af00 1100011011110101010001100000 0x6fffff"; char *end_ptr; @@ -439,7 +439,7 @@ static void tc_libc_stdlib_strtoull(void) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_strtod(void) +static void tc_libc_stdlib_strtod_pos(void) { char *pos = NULL; double ret_chk = 0; @@ -484,7 +484,7 @@ static void tc_libc_stdlib_strtod(void) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_atoi(void) +static void tc_libc_stdlib_atoi_pos(void) { /* random string used for conversion */ char str_lnum[] = "2016"; @@ -505,7 +505,7 @@ static void tc_libc_stdlib_atoi(void) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_atol(void) +static void tc_libc_stdlib_atol_pos(void) { /* random string used for conversion */ char str_lnum[] = "20162015"; @@ -526,7 +526,7 @@ static void tc_libc_stdlib_atol(void) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_atoll(void) +static void tc_libc_stdlib_atoll_pos(void) { /* random string used for conversion */ char str_lnum[] = "201620152014"; @@ -547,7 +547,7 @@ static void tc_libc_stdlib_atoll(void) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_srand(void) +static void tc_libc_stdlib_srand_pos(void) { unsigned int test_num = 1234; int first_result[3]; @@ -580,7 +580,7 @@ static void tc_libc_stdlib_srand(void) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_srandom(void) +static void tc_libc_stdlib_srandom_pos(void) { unsigned int test_num = 1234; int first_result[3]; @@ -613,7 +613,7 @@ static void tc_libc_stdlib_srandom(void) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_atof(void) +static void tc_libc_stdlib_atof_pos(void) { char target[100] = "1234.56abcd"; double ret_chk = 0; @@ -633,7 +633,7 @@ static void tc_libc_stdlib_atof(void) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_bsearch(void) +static void tc_libc_stdlib_bsearch_pos(void) { /* bsearch can find the result when data is ordered. So now using ordered data. */ int test_data[BSEARCH_ARRSIZE] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; @@ -653,6 +653,22 @@ static void tc_libc_stdlib_bsearch(void) TC_SUCCESS_RESULT(); } +static void tc_libc_stdlib_bsearch_invalid_key_neg(void) +{ + /* bsearch can find the result when data is ordered. So now using ordered data. */ + int test_data[BSEARCH_ARRSIZE] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + int key; + int *search_result; + + /* check with invalid key */ + key = 11; + search_result = (int *)bsearch(&key, test_data, BSEARCH_ARRSIZE, sizeof(test_data[0]), compare); + TC_ASSERT_EQ("bsearch", search_result, NULL); + + TC_SUCCESS_RESULT(); +} + + /** * @fn :tc_libc_stdlib_abort * @brief :Cause abnormal process termination @@ -662,7 +678,7 @@ static void tc_libc_stdlib_bsearch(void) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_abort(void) +static void tc_libc_stdlib_abort_pos(void) { pthread_t th_id; int ret_chk; @@ -685,7 +701,7 @@ static void tc_libc_stdlib_abort(void) * Postconditions :None * @return :void */ -static void tc_libc_stdlib_div(void) +static void tc_libc_stdlib_div_pos(void) { int num = 2147483647; int denom = 28672; @@ -715,25 +731,26 @@ static void tc_libc_stdlib_div(void) ****************************************************************************/ int libc_stdlib_main(void) { - tc_libc_stdlib_abort(); - tc_libc_stdlib_abs_labs_llabs(); - tc_libc_stdlib_atof(); - tc_libc_stdlib_atoi(); - tc_libc_stdlib_atol(); - tc_libc_stdlib_atoll(); - tc_libc_stdlib_bsearch(); - tc_libc_stdlib_div(); - tc_libc_stdlib_itoa(); - tc_libc_stdlib_qsort(); - tc_libc_stdlib_rand(); - tc_libc_stdlib_random(); - tc_libc_stdlib_strtol(); - tc_libc_stdlib_strtoll(); - tc_libc_stdlib_strtoull(); - tc_libc_stdlib_strtoul(); - tc_libc_stdlib_strtod(); - tc_libc_stdlib_srand(); - tc_libc_stdlib_srandom(); + tc_libc_stdlib_abort_pos(); + tc_libc_stdlib_abs_labs_llabs_pos(); + tc_libc_stdlib_atof_pos(); + tc_libc_stdlib_atoi_pos(); + tc_libc_stdlib_atol_pos(); + tc_libc_stdlib_atoll_pos(); + tc_libc_stdlib_bsearch_pos(); + tc_libc_stdlib_bsearch_invalid_key_neg(); + tc_libc_stdlib_div_pos(); + tc_libc_stdlib_itoa_pos(); + tc_libc_stdlib_qsort_pos(); + tc_libc_stdlib_rand_pos(); + tc_libc_stdlib_random_pos(); + tc_libc_stdlib_strtol_pos(); + tc_libc_stdlib_strtoll_pos(); + tc_libc_stdlib_strtoull_pos(); + tc_libc_stdlib_strtoul_pos(); + tc_libc_stdlib_strtod_pos(); + tc_libc_stdlib_srand_pos(); + tc_libc_stdlib_srandom_pos(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_libc_syslog.c b/apps/examples/testcase/le_tc/kernel/tc_libc_syslog.c index 419f695f6f..048f1abb88 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_libc_syslog.c +++ b/apps/examples/testcase/le_tc/kernel/tc_libc_syslog.c @@ -46,7 +46,7 @@ char g_syslogmsg[MAX_SYSLOG_MSG + 1]; * Postconditions :none * @return :void */ -static void tc_libc_syslog_setlogmask(void) +static void tc_libc_syslog_setlogmask_pos(void) { int oldmask, newmask, mask_chk; setlogmask(LOG_ALL); @@ -81,7 +81,7 @@ static void tc_libc_syslog_setlogmask(void) * Postconditions :none * @return :void */ -static void tc_libc_syslog_syslog(void) +static void tc_libc_syslog_syslog_pos(void) { int ret_chk; int i; @@ -122,7 +122,7 @@ static int vsyslogFunc(int priority, FAR const char *msg, ...) * Postconditions :none * @return :void */ -static void tc_libc_syslog_vsyslog(void) +static void tc_libc_syslog_vsyslog_pos(void) { int ret_chk; int i; @@ -148,7 +148,7 @@ static void tc_libc_syslog_vsyslog(void) * Postconditions :none * @return :void */ -static void tc_libc_syslog_lowsyslog(void) +static void tc_libc_syslog_lowsyslog_pos(void) { int ret_chk; int i; @@ -189,7 +189,7 @@ static int lowvsyslogFunc(int priority, FAR const char *msg, ...) * Postconditions :none * @return :void */ -static void tc_libc_syslog_lowvsyslog(void) +static void tc_libc_syslog_lowvsyslog_pos(void) { int ret_chk; int i; @@ -213,13 +213,13 @@ static void tc_libc_syslog_lowvsyslog(void) int libc_syslog_main(void) { - tc_libc_syslog_setlogmask(); - tc_libc_syslog_syslog(); - tc_libc_syslog_vsyslog(); + tc_libc_syslog_setlogmask_pos(); + tc_libc_syslog_syslog_pos(); + tc_libc_syslog_vsyslog_pos(); #ifndef CONFIG_BUILD_PROTECTED #if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_SYSLOG) - tc_libc_syslog_lowsyslog(); - tc_libc_syslog_lowvsyslog(); + tc_libc_syslog_lowsyslog_pos(); + tc_libc_syslog_lowvsyslog_pos(); #endif #endif return 0; diff --git a/apps/examples/testcase/le_tc/kernel/tc_libc_timer.c b/apps/examples/testcase/le_tc/kernel/tc_libc_timer.c index e8f9012019..4e383a4396 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_libc_timer.c +++ b/apps/examples/testcase/le_tc/kernel/tc_libc_timer.c @@ -54,7 +54,7 @@ * Postconditions :none * @return :void */ -static void tc_libc_timer_clock_calendar2utc(void) +static void tc_libc_timer_clock_calendar2utc_pos(void) { int time1; int time2; @@ -87,7 +87,7 @@ static void tc_libc_timer_clock_calendar2utc(void) * Postconditions :none * @return :void */ -static void tc_libc_timer_gmtime_r(void) +static void tc_libc_timer_gmtime_r_pos(void) { time_t test_time; int today; @@ -125,7 +125,7 @@ static void tc_libc_timer_gmtime_r(void) * Postconditions :none * @return :void */ -static void tc_libc_timer_gmtime(void) +static void tc_libc_timer_gmtime_pos(void) { int ret_chk = 0; struct tm *st_rettime = NULL; @@ -172,7 +172,7 @@ static void tc_libc_timer_gmtime(void) * Postconditions :none * @return :void */ -static void tc_libc_timer_clock_isleapyear(void) +static void tc_libc_timer_clock_isleapyear_pos(void) { int ret_chk = ERROR; int year; @@ -183,6 +183,14 @@ static void tc_libc_timer_clock_isleapyear(void) ret_chk = clock_isleapyear(year); TC_ASSERT_EQ("clock_isleapyear", ret_chk, 1); + TC_SUCCESS_RESULT(); +} + +static void tc_libc_timer_clock_isleapyear_neg(void) +{ + int ret_chk = ERROR; + int year; + /*Entered year is not a leap year */ year = ISNOTLEAPYEAR; @@ -204,7 +212,7 @@ static void tc_libc_timer_clock_isleapyear(void) * Postconditions :none * @return :void */ -static void tc_libc_timer_localtime(void) +static void tc_libc_timer_localtime_pos(void) { time_t test_time; struct tm *st_rettime = NULL; @@ -234,7 +242,7 @@ static void tc_libc_timer_localtime(void) * Postconditions :none * @return :void */ -static void tc_libc_timer_localtime_r(void) +static void tc_libc_timer_localtime_r_pos(void) { struct tm *st_rettime = NULL; struct tm st_time; @@ -270,7 +278,7 @@ static void tc_libc_timer_localtime_r(void) * Postconditions :none * @return :void */ -static void tc_libc_timer_mktime(void) +static void tc_libc_timer_mktime_pos(void) { time_t cur_day; time_t after_5days; @@ -309,7 +317,7 @@ static void tc_libc_timer_mktime(void) * Postconditions :none * @return :void */ -static void tc_libc_timer_strftime(void) +static void tc_libc_timer_strftime_pos(void) { struct tm st_time; char buffer[BUFF_SIZE]; @@ -450,7 +458,7 @@ static void tc_libc_timer_strftime(void) * Postconditions :none * @return :void */ -static void tc_libc_timer_strptime(void) +static void tc_libc_timer_strptime_pos(void) { struct tm sp_tm; struct tm sf_tm; @@ -687,7 +695,7 @@ static void tc_libc_timer_strptime(void) * Postconditions :none * @return :void */ -static void tc_libc_timer_time(void) +static void tc_libc_timer_time_pos(void) { time_t get_time = 0; time_t ret_time = 0; @@ -716,7 +724,7 @@ static void tc_libc_timer_time(void) * Postconditions :none * @return :void */ -static void tc_libc_timer_clock_daysbeforemonth(void) +static void tc_libc_timer_clock_daysbeforemonth_pos(void) { int prev_month; int cur_month; @@ -757,7 +765,7 @@ static void tc_libc_timer_clock_daysbeforemonth(void) * If the processor time used is not available or its value cannot * be represented, the function returns the value (clock_t) -1. */ -static void tc_libc_timer_clock(void) +static void tc_libc_timer_clock_pos(void) { clock_t ret_time = ERROR; @@ -768,7 +776,7 @@ static void tc_libc_timer_clock(void) } #ifdef CONFIG_LIBM -static void tc_libc_timer_difftime(void) +static void tc_libc_timer_difftime_pos(void) { time_t t0; time_t t1; @@ -801,21 +809,22 @@ static void tc_libc_timer_difftime(void) int libc_timer_main(void) { - tc_libc_timer_clock(); - tc_libc_timer_clock_calendar2utc(); - tc_libc_timer_clock_daysbeforemonth(); - tc_libc_timer_clock_isleapyear(); + tc_libc_timer_clock_pos(); + tc_libc_timer_clock_calendar2utc_pos(); + tc_libc_timer_clock_daysbeforemonth_pos(); + tc_libc_timer_clock_isleapyear_pos(); + tc_libc_timer_clock_isleapyear_neg(); #ifdef CONFIG_LIBM - tc_libc_timer_difftime(); + tc_libc_timer_difftime_pos(); #endif - tc_libc_timer_gmtime(); - tc_libc_timer_gmtime_r(); - tc_libc_timer_localtime(); - tc_libc_timer_localtime_r(); - tc_libc_timer_mktime(); - tc_libc_timer_strftime(); - tc_libc_timer_strptime(); - tc_libc_timer_time(); + tc_libc_timer_gmtime_pos(); + tc_libc_timer_gmtime_r_pos(); + tc_libc_timer_localtime_pos(); + tc_libc_timer_localtime_r_pos(); + tc_libc_timer_mktime_pos(); + tc_libc_timer_strftime_pos(); + tc_libc_timer_strptime_pos(); + tc_libc_timer_time_pos(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_libc_unistd.c b/apps/examples/testcase/le_tc/kernel/tc_libc_unistd.c index 831ffb6739..940da8d44c 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_libc_unistd.c +++ b/apps/examples/testcase/le_tc/kernel/tc_libc_unistd.c @@ -85,7 +85,7 @@ static void *pipe_rx_func(void *arg) * Postconditions :none * @return :void */ -static void tc_libc_unistd_access(void) +static void tc_libc_unistd_access_pos(void) { int ret_chk; char path[BUFFSIZE + 1]; @@ -110,7 +110,7 @@ static void tc_libc_unistd_access(void) * Postconditions :none * @return :void */ -static void tc_libc_unistd_chdir_getcwd(void) +static void tc_libc_unistd_chdir_getcwd_pos(void) { char *cwd; @@ -124,19 +124,65 @@ static void tc_libc_unistd_chdir_getcwd(void) cwd = getcwd(buff, BUFFSIZE); TC_ASSERT_EQ("getcwd", strcmp(directory, cwd), 0); + TC_SUCCESS_RESULT(); +} + +static void tc_libc_unistd_chdir_getcwd_invalid_strlen_neg(void) +{ + char *cwd; + char buff[BUFFSIZE]; + char *directory = "/dev"; + int ret_chk; + + ret_chk = chdir(directory); + TC_ASSERT_EQ("chdir", ret_chk, OK); + /* Failure case: size less than strlen(buff) or invalid size */ cwd = getcwd(buff, 1); TC_ASSERT_EQ("getcwd", cwd, NULL); + + TC_SUCCESS_RESULT(); +} + +static void tc_libc_unistd_chdir_getcwd_pwd_neg(void) +{ + char *cwd; + char buff[BUFFSIZE]; + char *directory = "/dev"; + int ret_chk; + + ret_chk = chdir(directory); + TC_ASSERT_EQ("chdir", ret_chk, OK); + /* Failure case: when "PWD" is not defined*/ unsetenv("PWD"); cwd = getcwd(buff, BUFFSIZE); TC_ASSERT_NEQ("getcwd", strcmp(directory, cwd), 0); + TC_SUCCESS_RESULT(); +} + + +static void tc_libc_unistd_chdir_null_directory_neg(void) +{ + + char *directory = "/dev"; + int ret_chk; + directory = NULL; ret_chk = chdir(directory); TC_ASSERT_EQ("chdir", ret_chk, ERROR); + TC_SUCCESS_RESULT(); +} + +static void tc_libc_unistd_chdir_invalid_directory_neg(void) +{ + + char *directory = "/dev"; + int ret_chk; + /* Failure case: path is not a directory */ directory = "NOTDIR"; ret_chk = chdir(directory); @@ -144,6 +190,7 @@ static void tc_libc_unistd_chdir_getcwd(void) TC_SUCCESS_RESULT(); } + #endif /** @@ -156,7 +203,7 @@ static void tc_libc_unistd_chdir_getcwd(void) * Postconditions :none * @return :void */ -static void tc_libc_unistd_getopt(void) +static void tc_libc_unistd_getopt_pos(void) { int flag_a = 0; int flag_b = 0; @@ -198,6 +245,82 @@ static void tc_libc_unistd_getopt(void) TC_SUCCESS_RESULT(); } +static void tc_libc_unistd_getopt_null_optstring_neg(void) +{ + int flag_a = 0; + int flag_b = 0; + int ret = -1; + int argc = ARG_COUNT; + char *sz_argv[] = { "arg0", "-a2", "-b", "-c", "-a", "-:" }; + char **arg; + int *opt; + int *idx; + + optind = -1; + while ((ret = getopt(argc, sz_argv, ":a:b")) != ERROR) + switch (ret) { + case 'a': + flag_a = 1; + arg = getoptargp(); + vdbg("getoptargp: optarg = %s\n", *arg); + break; + case 'b': + flag_b = 1; + idx = getoptindp(); + vdbg("getoptindp: optind = %d\n", *idx); + break; + default: + opt = getoptoptp(); + vdbg("getoptoptp: optopt = %c\n", *opt); + break; + } + + ret = getopt(argc, sz_argv, NULL); + TC_ASSERT_EQ("getopt", ret, ERROR); + + TC_SUCCESS_RESULT(); +} + +static void tc_libc_unistd_getopt_neg(void) +{ + int flag_a = 0; + int flag_b = 0; + int ret = -1; + int argc = ARG_COUNT; + char *sz_argv[] = { "arg0", "-a2", "-b", "-c", "-a", "-:" }; + char **arg; + int *opt; + int *idx; + + optind = -1; + while ((ret = getopt(argc, sz_argv, ":a:b")) != ERROR) + switch (ret) { + case 'a': + flag_a = 1; + arg = getoptargp(); + vdbg("getoptargp: optarg = %s\n", *arg); + break; + case 'b': + flag_b = 1; + idx = getoptindp(); + vdbg("getoptindp: optind = %d\n", *idx); + break; + default: + opt = getoptoptp(); + vdbg("getoptoptp: optopt = %c\n", *opt); + break; + } + TC_ASSERT_EQ("getopt", flag_a, 1); + TC_ASSERT_EQ("getopt", flag_b, 1); + + sz_argv[1] = "a"; + ret = getopt(argc, sz_argv, ":a:b"); + TC_ASSERT_EQ("getopt", ret, ERROR); + + TC_SUCCESS_RESULT(); +} + + #ifndef CONFIG_DISABLE_SIGNALS /** * @fn :tc_libc_unistd_sleep @@ -209,7 +332,7 @@ static void tc_libc_unistd_getopt(void) * Postconditions :none * @return :void */ -static void tc_libc_unistd_sleep(void) +static void tc_libc_unistd_sleep_pos(void) { int ret_chk; struct timespec st_init_time; @@ -235,7 +358,7 @@ static void tc_libc_unistd_sleep(void) * Postconditions :none * @return :void */ -static void tc_libc_unistd_usleep(void) +static void tc_libc_unistd_usleep_pos(void) { int ret_chk; struct timespec st_init_time; @@ -262,7 +385,7 @@ static void tc_libc_unistd_usleep(void) * Postconditions :none * @return :void */ -static void tc_libc_unistd_pipe(void) +static void tc_libc_unistd_pipe_pos(void) { int ret_chk; pthread_t th_id[2]; @@ -301,16 +424,22 @@ static void tc_libc_unistd_pipe(void) int libc_unistd_main(void) { #ifndef CONFIG_DISABLE_ENVIRON - tc_libc_unistd_access(); - tc_libc_unistd_chdir_getcwd(); + tc_libc_unistd_access_pos(); + tc_libc_unistd_chdir_getcwd_pos(); + tc_libc_unistd_chdir_getcwd_pwd_neg(); + tc_libc_unistd_chdir_invalid_directory_neg(); + tc_libc_unistd_chdir_null_directory_neg(); + tc_libc_unistd_chdir_getcwd_invalid_strlen_neg(); #endif - tc_libc_unistd_getopt(); + tc_libc_unistd_getopt_pos(); + tc_libc_unistd_getopt_neg(); + tc_libc_unistd_getopt_null_optstring_neg(); #ifdef CONFIG_PIPES - tc_libc_unistd_pipe(); + tc_libc_unistd_pipe_pos(); #endif #ifndef CONFIG_DISABLE_SIGNALS - tc_libc_unistd_sleep(); - tc_libc_unistd_usleep(); + tc_libc_unistd_sleep_pos(); + tc_libc_unistd_usleep_pos(); #endif return 0; diff --git a/apps/examples/testcase/le_tc/kernel/tc_memory_safety.c b/apps/examples/testcase/le_tc/kernel/tc_memory_safety.c index ba0cf2f8a9..74e176df91 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_memory_safety.c +++ b/apps/examples/testcase/le_tc/kernel/tc_memory_safety.c @@ -268,7 +268,7 @@ static void *infiniteloop(void *arg) * Postconditions :none * @return :void */ -static void tc_memory_safety_with_mqueue(void) +static void tc_memory_safety_with_mqueue_pos(void) { pthread_t sender; pthread_t receiver; @@ -404,6 +404,6 @@ static void tc_memory_safety_with_mqueue(void) ****************************************************************************/ int memory_safety_main(void) { - tc_memory_safety_with_mqueue(); + tc_memory_safety_with_mqueue_pos(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_mqueue.c b/apps/examples/testcase/le_tc/kernel/tc_mqueue.c index a850d00e36..834cfb1a3b 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_mqueue.c +++ b/apps/examples/testcase/le_tc/kernel/tc_mqueue.c @@ -562,7 +562,7 @@ static void *receiver_thread(void *arg) * Postconditions :none * @return :void */ -static void tc_mqueue_mq_open_close_send_receive(void) +static void tc_mqueue_mq_open_close_send_receive_pos(void) { pthread_t sender; pthread_t receiver; @@ -664,7 +664,9 @@ static void tc_mqueue_mq_open_close_send_receive(void) TC_SUCCESS_RESULT(); } -static void tc_mqueue_mq_notify(void) + + +static void tc_mqueue_mq_notify_pos(void) { mqd_t mqdes; const char s_msg_ptr[15] = "test message\n"; @@ -699,20 +701,12 @@ static void tc_mqueue_mq_notify(void) sa.sa_flags = 0; sigaction(SIGUSR1, &sa, NULL); - /* Null Message queue descriptor check */ - TC_ASSERT_EQ_ERROR_CLEANUP("mq_notify", mq_notify(NULL, ¬ification), ERROR, get_errno(), goto cleanup); - - /* Invalid signal number check */ - notification.sigev_signo = 33; - TC_ASSERT_EQ_ERROR_CLEANUP("mq_notify", mq_notify(mqdes, ¬ification), ERROR, get_errno(), goto cleanup); /* Valid signal number check */ notification.sigev_signo = SIGUSR1; TC_ASSERT_EQ_ERROR_CLEANUP("mq_notify", mq_notify(mqdes, ¬ification), OK, get_errno(), goto cleanup); TC_ASSERT_EQ_ERROR_CLEANUP("mq_notify", mq_notify(mqdes, ¬ification), ERROR, get_errno(), goto cleanup); - /* Detaching the notification */ - TC_ASSERT_EQ_ERROR_CLEANUP("mq_notify", mq_notify(mqdes, NULL), OK, get_errno(), goto cleanup); mq_close(mqdes); mq_unlink("noti_queue"); @@ -720,11 +714,88 @@ static void tc_mqueue_mq_notify(void) TC_SUCCESS_RESULT(); return; cleanup: + + mq_close(mqdes); + mq_unlink("noti_queue"); +} + + +static void tc_mqueue_mq_notify_null_mqdes_neg(void) +{ + mqd_t mqdes; + const char s_msg_ptr[15] = "test message\n"; + struct sigevent notification; + struct sigaction sa; + unsigned int prio = 1; + + mqdes = mq_open("noti_queue", O_CREAT | O_RDWR, 0666, 0); + 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); + + /* Null Message queue descriptor check */ + TC_ASSERT_EQ_ERROR_CLEANUP("mq_notify", mq_notify(NULL, ¬ification), ERROR, get_errno(), goto cleanup); + + mq_close(mqdes); + mq_unlink("noti_queue"); + + TC_SUCCESS_RESULT(); + return; +cleanup: + mq_close(mqdes); + mq_unlink("noti_queue"); +} + + +static void tc_mqueue_mq_notify_invalid_signal_neg(void) +{ + mqd_t mqdes; + const char s_msg_ptr[15] = "test message\n"; + struct sigevent notification; + struct sigaction sa; + unsigned int prio = 1; + + mqdes = mq_open("noti_queue", O_CREAT | O_RDWR, 0666, 0); + 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; + sa.sa_mask = 0; + sigaction(SIGUSR1, &sa, NULL); + + mqdes = mq_open("noti_queue", O_CREAT | O_RDWR, 0666, 0); + 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); + + /* Invalid signal number check */ + notification.sigev_signo = 33; + TC_ASSERT_EQ_ERROR_CLEANUP("mq_notify", mq_notify(mqdes, ¬ification), ERROR, get_errno(), goto cleanup); + + + mq_close(mqdes); + mq_unlink("noti_queue"); + + TC_SUCCESS_RESULT(); + return; +cleanup: + mq_close(mqdes); mq_unlink("noti_queue"); } -static void tc_mqueue_mq_timedsend_timedreceive(void) + +static void tc_mqueue_mq_timedsend_timedreceive_pos(void) { int ret_chk = OK; @@ -739,7 +810,23 @@ static void tc_mqueue_mq_timedsend_timedreceive(void) TC_SUCCESS_RESULT(); } -static void tc_mqueue_mq_unlink(void) +static void tc_mqueue_mq_unlink_pos(void) +{ + int ret; + mqd_t mqdes; + + mqdes = mq_open("mqunlink", O_CREAT | O_RDWR, 0666, 0); + TC_ASSERT_NEQ("mq_open", mqdes, (mqd_t)-1); + + mq_close(mqdes); + + ret = mq_unlink("mqunlink"); + TC_ASSERT_EQ("mq_unlink", ret, OK); + + TC_SUCCESS_RESULT(); +} + +static void tc_mqueue_mq_unlink_neg(void) { int ret; mqd_t mqdes; @@ -764,7 +851,7 @@ static void tc_mqueue_mq_unlink(void) * @description :Function for tc_mqueue_mq_timedsend_timedreceive corner case checks * @return :void* */ -static void tc_mqueue_mq_timedsend_timedreceive_failurechecks(void) +static void tc_mqueue_mq_timedsend_timedreceive_neg(void) { char msg_buffer[TEST_MSGLEN]; struct mq_attr attr; @@ -861,7 +948,39 @@ static void tc_mqueue_mq_timedsend_timedreceive_failurechecks(void) } -static void tc_mqueue_mq_getattr(void) +static void tc_mqueue_mq_getattr_pos(void) +{ + mqd_t mqdes; + struct mq_attr attr; + struct mq_attr mq_stat; + int ret_chk; + + /* Fill in attributes for message queue */ + + attr.mq_maxmsg = 20; + attr.mq_msgsize = TEST_MSGLEN; + + mqdes = mq_open("mqgetattr", O_CREAT | O_RDWR, 0666, &attr); + TC_ASSERT_NEQ("mq_open", mqdes, (mqd_t)ERROR); + + + ret_chk = mq_getattr(mqdes, &mq_stat); + TC_ASSERT_EQ_CLEANUP("mq_getattr", ret_chk, OK, goto errout); + TC_ASSERT_EQ_CLEANUP("mq_getattr", mq_stat.mq_maxmsg, attr.mq_maxmsg, goto errout); + TC_ASSERT_EQ_CLEANUP("mq_getattr", mq_stat.mq_msgsize, attr.mq_msgsize, goto errout); + + mq_close(mqdes); + mq_unlink("mqgetattr"); + TC_SUCCESS_RESULT(); + return; + +errout: + mq_close(mqdes); + mq_unlink("mqgetattr"); +} + + +static void tc_mqueue_mq_getattr_null_mqdes_neg(void) { mqd_t mqdes; struct mq_attr attr; @@ -878,12 +997,38 @@ static void tc_mqueue_mq_getattr(void) ret_chk = mq_getattr(NULL, &mq_stat); TC_ASSERT_EQ_CLEANUP("mq_getattr", ret_chk, ERROR, goto errout); + //TC_ASSERT_EQ_CLEANUP("mq_getattr", mq_stat.mq_maxmsg, attr.mq_maxmsg, goto errout); + //TC_ASSERT_EQ_CLEANUP("mq_getattr", mq_stat.mq_msgsize, attr.mq_msgsize, goto errout); + + mq_close(mqdes); + mq_unlink("mqgetattr"); + TC_SUCCESS_RESULT(); + return; + +errout: + mq_close(mqdes); + mq_unlink("mqgetattr"); +} + + + +static void tc_mqueue_mq_getattr_null_attr_neg(void) +{ + mqd_t mqdes; + struct mq_attr attr; + struct mq_attr mq_stat; + int ret_chk; + + /* Fill in attributes for message queue */ + + attr.mq_maxmsg = 20; + attr.mq_msgsize = TEST_MSGLEN; + + mqdes = mq_open("mqgetattr", O_CREAT | O_RDWR, 0666, &attr); + TC_ASSERT_NEQ("mq_open", mqdes, (mqd_t)ERROR); ret_chk = mq_getattr(mqdes, NULL); TC_ASSERT_EQ_CLEANUP("mq_getattr", ret_chk, ERROR, goto errout); - - ret_chk = mq_getattr(mqdes, &mq_stat); - TC_ASSERT_EQ_CLEANUP("mq_getattr", ret_chk, OK, goto errout); TC_ASSERT_EQ_CLEANUP("mq_getattr", mq_stat.mq_maxmsg, attr.mq_maxmsg, goto errout); TC_ASSERT_EQ_CLEANUP("mq_getattr", mq_stat.mq_msgsize, attr.mq_msgsize, goto errout); @@ -897,7 +1042,8 @@ static void tc_mqueue_mq_getattr(void) mq_unlink("mqgetattr"); } -static void tc_mqueue_mq_setattr(void) + +static void tc_mqueue_mq_setattr_pos(void) { mqd_t mqdes; struct mq_attr mq_stat; @@ -910,12 +1056,49 @@ static void tc_mqueue_mq_setattr(void) ret_chk = mq_getattr(mqdes, &mq_stat); TC_ASSERT_EQ_CLEANUP("mq_getattr", ret_chk, OK, goto errout); - ret_chk = mq_setattr(NULL, &mq_stat, &oldstat); - TC_ASSERT_EQ_CLEANUP("mq_setattr", ret_chk, ERROR, goto errout); + ret_chk = mq_setattr(mqdes, &mq_stat, &oldstat); + TC_ASSERT_EQ_CLEANUP("mq_setattr", ret_chk, OK, goto errout); + + + if (mq_stat.mq_flags & O_NONBLOCK) { + mq_stat.mq_flags = mq_stat.mq_flags & (~O_NONBLOCK); + ret_chk = mq_setattr(mqdes, &mq_stat, &oldstat); + TC_ASSERT_EQ_CLEANUP("mq_setattr", ret_chk, OK, goto errout); + TC_ASSERT_EQ_CLEANUP("mq_setattr", oldstat.mq_flags & O_NONBLOCK, O_NONBLOCK, goto errout); + } else { + mq_stat.mq_flags = mq_stat.mq_flags | O_NONBLOCK; + ret_chk = mq_setattr(mqdes, &mq_stat, &oldstat); + TC_ASSERT_EQ_CLEANUP("mq_setattr", ret_chk, OK, goto errout); + TC_ASSERT_EQ_CLEANUP("mq_setattr", oldstat.mq_flags & O_NONBLOCK, 0, goto errout); + } - ret_chk = mq_setattr(mqdes, NULL, &oldstat); + mq_close(mqdes); + mq_unlink("mqsetattr"); + TC_SUCCESS_RESULT(); + return; + +errout: + mq_close(mqdes); + mq_unlink("mqsetattr"); +} + +static void tc_mqueue_mq_setattr_null_mqdes_neg(void) +{ + mqd_t mqdes; + struct mq_attr mq_stat; + struct mq_attr oldstat; + int ret_chk; + + mqdes = mq_open("mqsetattr", O_CREAT | O_RDWR, 0666, 0); + TC_ASSERT_NEQ("mq_open", mqdes, (mqd_t)ERROR); + + ret_chk = mq_getattr(mqdes, &mq_stat); + TC_ASSERT_EQ_CLEANUP("mq_getattr", ret_chk, OK, goto errout); + + ret_chk = mq_setattr(NULL, &mq_stat, &oldstat); TC_ASSERT_EQ_CLEANUP("mq_setattr", ret_chk, ERROR, goto errout); + if (mq_stat.mq_flags & O_NONBLOCK) { mq_stat.mq_flags = mq_stat.mq_flags & (~O_NONBLOCK); ret_chk = mq_setattr(mqdes, &mq_stat, &oldstat); @@ -939,19 +1122,25 @@ static void tc_mqueue_mq_setattr(void) } + /**************************************************************************** * Name: mqueue ****************************************************************************/ int mqueue_main(void) { - tc_mqueue_mq_open_close_send_receive(); - tc_mqueue_mq_notify(); - tc_mqueue_mq_timedsend_timedreceive(); - tc_mqueue_mq_timedsend_timedreceive_failurechecks(); - tc_mqueue_mq_unlink(); - - tc_mqueue_mq_getattr(); - tc_mqueue_mq_setattr(); + tc_mqueue_mq_open_close_send_receive_pos(); + tc_mqueue_mq_notify_pos(); + tc_mqueue_mq_notify_null_mqdes_neg(); + tc_mqueue_mq_notify_invalid_signal_neg(); + tc_mqueue_mq_timedsend_timedreceive_pos(); + tc_mqueue_mq_timedsend_timedreceive_neg(); + tc_mqueue_mq_unlink_pos(); + tc_mqueue_mq_unlink_neg(); + tc_mqueue_mq_getattr_pos(); + tc_mqueue_mq_getattr_null_mqdes_neg(); + tc_mqueue_mq_getattr_null_attr_neg(); + tc_mqueue_mq_setattr_pos(); + tc_mqueue_mq_setattr_null_mqdes_neg(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_pthread.c b/apps/examples/testcase/le_tc/kernel/tc_pthread.c index f8b8793148..381f45e3d3 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_pthread.c +++ b/apps/examples/testcase/le_tc/kernel/tc_pthread.c @@ -574,7 +574,7 @@ static void *thread_mutex_lock_exit_without_unlock(void *param) * Postconditions :none * @return :void */ -static void tc_pthread_pthread_barrier_init_destroy_wait(void) +static void tc_pthread_pthread_barrier_init_destroy_wait_pos(void) { int ret_chk; int ithread = PTHREAD_CNT; @@ -632,7 +632,24 @@ static int infinite_sleep(int argc, char *argv[]) * Postconditions :none * @return :void */ -static void tc_pthread_pthread_create_exit_join(void) +static void tc_pthread_pthread_create_exit_join_pos(void) +{ + int ret_chk; + pthread_t pthread; + int task_pid; + void *p_value = 0; + + ret_chk = pthread_create(&pthread, NULL, self_pthread_join_n_exit, NULL); + TC_ASSERT_EQ("pthread create", ret_chk, OK); + + ret_chk = pthread_join(pthread, &p_value); + TC_ASSERT_EQ("pthread_join", ret_chk, OK); + TC_ASSERT_EQ("pthread_exit", p_value, (void *)EDEADLK); + + TC_SUCCESS_RESULT(); +} + +static void tc_pthread_pthread_create_exit_join_neg(void) { int ret_chk; pthread_t pthread; @@ -648,13 +665,40 @@ static void tc_pthread_pthread_create_exit_join(void) /* Wait to release the above pthread resource */ sleep(1); - + ret_chk = pthread_join(pthread, NULL); TC_ASSERT_EQ("pthread_join", ret_chk, ESRCH); - ret_chk = pthread_join(INVALID_PID, NULL); + TC_SUCCESS_RESULT(); +} + +static void tc_pthread_pthread_create_exit_join_invalid_pid_neg(void) +{ + int ret_chk; + pthread_t pthread; + int task_pid; + void *p_value = 0; + + ret_chk = pthread_create(&pthread, NULL, self_pthread_join_n_exit, NULL); + TC_ASSERT_EQ("pthread create", ret_chk, OK); + + + ret_chk = pthread_join(-1, NULL); TC_ASSERT_EQ("pthread_join", ret_chk, ESRCH); + TC_SUCCESS_RESULT(); +} + +static void tc_pthread_pthread_create_exit_join_invalid_task_neg(void) +{ + int ret_chk; + pthread_t pthread; + int task_pid; + void *p_value = 0; + + ret_chk = pthread_create(&pthread, NULL, self_pthread_join_n_exit, NULL); + TC_ASSERT_EQ("pthread create", ret_chk, OK); + task_pid = task_create("inval_test_task", 100, 1024, infinite_sleep, NULL); TC_ASSERT_GT("task_create", task_pid, 0); @@ -666,6 +710,8 @@ static void tc_pthread_pthread_create_exit_join(void) TC_SUCCESS_RESULT(); } + + /** * @fn :tc_pthread_pthread_tryjoin_np * @brief :test the pthread_tryjoin_np function @@ -678,7 +724,7 @@ static void tc_pthread_pthread_create_exit_join(void) * Postconditions :none * @return :void */ -static void tc_pthread_pthread_tryjoin_np(void) +static void tc_pthread_pthread_tryjoin_np_pos(void) { int ret_chk; pthread_t pid; @@ -726,7 +772,7 @@ static void tc_pthread_pthread_tryjoin_np(void) * Postconditions :none * @return :void */ -static void tc_pthread_pthread_kill(void) +static void tc_pthread_pthread_kill_pos(void) { int ret_chk; g_bpthreadcallback = false; @@ -756,7 +802,7 @@ static void tc_pthread_pthread_kill(void) * Postconditions :pthread_cond_destroy * @return :void */ -static void tc_pthread_pthread_cond_broadcast(void) +static void tc_pthread_pthread_cond_broadcast_pos(void) { int ret_chk; int ipthread_id = 0; @@ -829,7 +875,7 @@ static void tc_pthread_pthread_cond_broadcast(void) * Postconditions :none * @return :void */ -static void tc_pthread_pthread_cond_init_destroy(void) +static void tc_pthread_pthread_cond_init_destroy_pos(void) { int ret_chk; pthread_condattr_t attr; @@ -870,7 +916,7 @@ static void tc_pthread_pthread_cond_init_destroy(void) * Postconditions :none * @return :void */ -static void tc_pthread_pthread_set_get_schedparam(void) +static void tc_pthread_pthread_set_get_schedparam_pos(void) { int ret_chk; struct sched_param st_setparam; @@ -915,7 +961,7 @@ static void tc_pthread_pthread_set_get_schedparam(void) * Postconditions :none * @return :void */ -static void tc_pthread_pthread_key_create_delete_set_getspecific(void) +static void tc_pthread_pthread_key_create_delete_set_getspecific_pos(void) { int ret_chk; g_bpthreadcallback = false; @@ -945,7 +991,7 @@ static void tc_pthread_pthread_key_create_delete_set_getspecific(void) * Postconditions :none * @return :void */ -static void tc_pthread_pthread_cancel_setcancelstate(void) +static void tc_pthread_pthread_cancel_setcancelstate_pos(void) { int ret_chk; g_bpthreadcallback = false; @@ -976,7 +1022,7 @@ static void tc_pthread_pthread_cancel_setcancelstate(void) * Postconditions :none * @return :void */ -static void tc_pthread_pthread_timed_wait(void) +static void tc_pthread_pthread_timed_wait_pos(void) { int ret_chk; pthread_t waiter; @@ -1032,7 +1078,7 @@ static void tc_pthread_pthread_timed_wait(void) * Postconditions :pthread_mutex_destroy * @return :void */ -static void tc_pthread_pthread_mutex_lock_unlock_trylock(void) +static void tc_pthread_pthread_mutex_lock_unlock_trylock_pos(void) { int ret_chk; pthread_mutexattr_t attr; @@ -1099,6 +1145,7 @@ static void tc_pthread_pthread_mutex_lock_unlock_trylock(void) TC_SUCCESS_RESULT(); } + /** * @fn :tc_pthread_pthread_mutex_init * @brief :this tc test pthread_mutex_init @@ -1110,7 +1157,7 @@ static void tc_pthread_pthread_mutex_lock_unlock_trylock(void) * @return :void */ -static void tc_pthread_pthread_mutex_init(void) +static void tc_pthread_pthread_mutex_init_neg(void) { pthread_mutexattr_t attr; pthread_mutex_t mutex; @@ -1119,9 +1166,6 @@ static void tc_pthread_pthread_mutex_init(void) ret_chk = pthread_mutexattr_init(&attr); TC_ASSERT_EQ("pthread_mutexattr_init", ret_chk, OK); - ret_chk = pthread_mutex_init(NULL, &attr); - TC_ASSERT_EQ("pthread_mutex_init", ret_chk, EINVAL); - ret_chk = pthread_mutex_init(&mutex, &attr); TC_ASSERT_EQ("pthread_mutex_init", ret_chk, OK); TC_ASSERT_EQ("pthread_mutex_init", mutex.pid, -1); @@ -1137,6 +1181,22 @@ static void tc_pthread_pthread_mutex_init(void) TC_SUCCESS_RESULT(); } +static void tc_pthread_pthread_mutex_init_null_mutex_neg(void) +{ + pthread_mutexattr_t attr; + pthread_mutex_t mutex; + int ret_chk; + + ret_chk = pthread_mutexattr_init(&attr); + TC_ASSERT_EQ("pthread_mutexattr_init", ret_chk, OK); + + ret_chk = pthread_mutex_init(NULL, &attr); + TC_ASSERT_EQ("pthread_mutex_init", ret_chk, EINVAL); + + + TC_SUCCESS_RESULT(); +} + /** * @fn :tc_pthread_pthread_mutex_destroy * @brief :this tc test pthread_mutex_destroy @@ -1150,7 +1210,7 @@ static void tc_pthread_pthread_mutex_init(void) * @return :void */ -static void tc_pthread_pthread_mutex_destroy(void) +static void tc_pthread_pthread_mutex_destroy_pos(void) { pthread_mutexattr_t attr; pthread_t pid; @@ -1162,12 +1222,37 @@ static void tc_pthread_pthread_mutex_destroy(void) ret_chk = pthread_mutex_init(&g_mutex, &attr); TC_ASSERT_EQ("pthread_mutex_init", ret_chk, OK); -#ifndef CONFIG_DEBUG - /* test NULL case. ASSERT will rise when debug is enabled */ + /* try ptherad_mutex_destroy when dead thread hold mutex */ - ret_chk = pthread_mutex_destroy(NULL); - TC_ASSERT_EQ("pthread_mutex_destroy", ret_chk, EINVAL); -#endif + ret_chk = pthread_create(&pid, NULL, thread_mutex_lock_exit_without_unlock, NULL); + TC_ASSERT_EQ("pthread_create", ret_chk, OK); + + ret_chk = pthread_join(pid, NULL); + TC_ASSERT_EQ("pthread_join", ret_chk, OK); + + ret_chk = pthread_mutex_destroy(&g_mutex); + TC_ASSERT_EQ("pthread_mutex_destroy", ret_chk, OK); + TC_ASSERT_EQ("pthread_mutex_destroy", g_mutex.pid, -1); + + /* test revisit case */ + + ret_chk = pthread_mutex_destroy(&g_mutex); + TC_ASSERT_EQ("pthread_mutex_destroy", ret_chk, OK); + + TC_SUCCESS_RESULT(); +} + +static void tc_pthread_pthread_mutex_destroy_mutex_busy_neg(void) +{ + pthread_mutexattr_t attr; + pthread_t pid; + int ret_chk; + + ret_chk = pthread_mutexattr_init(&attr); + TC_ASSERT_EQ("pthread_mutexattr_init", ret_chk, OK); + + ret_chk = pthread_mutex_init(&g_mutex, &attr); + TC_ASSERT_EQ("pthread_mutex_init", ret_chk, OK); /* try pthread_mutex_destroy while mutex is used */ @@ -1180,22 +1265,24 @@ static void tc_pthread_pthread_mutex_destroy(void) ret_chk = pthread_mutex_unlock(&g_mutex); TC_ASSERT_EQ("pthread_mutex_unlock", ret_chk, OK); - /* try ptherad_mutex_destroy when dead thread hold mutex */ + TC_SUCCESS_RESULT(); +} - ret_chk = pthread_create(&pid, NULL, thread_mutex_lock_exit_without_unlock, NULL); - TC_ASSERT_EQ("pthread_create", ret_chk, OK); - ret_chk = pthread_join(pid, NULL); - TC_ASSERT_EQ("pthread_join", ret_chk, OK); - ret_chk = pthread_mutex_destroy(&g_mutex); - TC_ASSERT_EQ("pthread_mutex_destroy", ret_chk, OK); - TC_ASSERT_EQ("pthread_mutex_destroy", g_mutex.pid, -1); +static void tc_pthread_pthread_mutex_destroy_null_mutex_neg(void) +{ + pthread_mutexattr_t attr; + pthread_t pid; + int ret_chk; - /* test revisit case */ - ret_chk = pthread_mutex_destroy(&g_mutex); - TC_ASSERT_EQ("pthread_mutex_destroy", ret_chk, OK); +#ifndef CONFIG_DEBUG + /* test NULL case. ASSERT will rise when debug is enabled */ + + ret_chk = pthread_mutex_destroy(NULL); + TC_ASSERT_EQ("pthread_mutex_destroy", ret_chk, EINVAL); +#endif TC_SUCCESS_RESULT(); } @@ -1211,7 +1298,7 @@ static void tc_pthread_pthread_mutex_destroy(void) * Postconditions :none * @return :void */ -static void tc_pthread_pthread_once(void) +static void tc_pthread_pthread_once_pos(void) { int ret_chk; @@ -1219,28 +1306,52 @@ static void tc_pthread_pthread_once(void) g_once = PTHREAD_ONCE_INIT; - /* Test NULL case */ + /* g_bpthreadcallback will be toggled only once */ g_bpthreadcallback = false; - ret_chk = pthread_once(NULL, &run_once); - TC_ASSERT_EQ("pthread_once", ret_chk, EINVAL); + ret_chk = pthread_once(&g_once, &run_once); + TC_ASSERT_EQ("pthread_once", ret_chk, OK); + TC_ASSERT_EQ("pthread_once", g_bpthreadcallback, true); + + g_bpthreadcallback = false; + ret_chk = pthread_once(&g_once, &run_once); + TC_ASSERT_EQ("pthread_once", ret_chk, OK); TC_ASSERT_EQ("pthread_once", g_bpthreadcallback, false); + TC_SUCCESS_RESULT(); +} + +static void tc_pthread_pthread_once_null_opaque_neg(void) +{ + int ret_chk; + + /* Initialize g_once */ + + g_once = PTHREAD_ONCE_INIT; + + /* Test NULL case */ + g_bpthreadcallback = false; - ret_chk = pthread_once(&g_once, NULL); + ret_chk = pthread_once(NULL, &run_once); TC_ASSERT_EQ("pthread_once", ret_chk, EINVAL); TC_ASSERT_EQ("pthread_once", g_bpthreadcallback, false); - /* g_bpthreadcallback will be toggled only once */ + TC_SUCCESS_RESULT(); +} - g_bpthreadcallback = false; - ret_chk = pthread_once(&g_once, &run_once); - TC_ASSERT_EQ("pthread_once", ret_chk, OK); - TC_ASSERT_EQ("pthread_once", g_bpthreadcallback, true); +static void tc_pthread_pthread_once_null_callback_neg(void) +{ + int ret_chk; + + /* Initialize g_once */ + + g_once = PTHREAD_ONCE_INIT; + + /* Test NULL case */ g_bpthreadcallback = false; - ret_chk = pthread_once(&g_once, &run_once); - TC_ASSERT_EQ("pthread_once", ret_chk, OK); + ret_chk = pthread_once(&g_once, NULL); + TC_ASSERT_EQ("pthread_once", ret_chk, EINVAL); TC_ASSERT_EQ("pthread_once", g_bpthreadcallback, false); TC_SUCCESS_RESULT(); @@ -1258,7 +1369,7 @@ static void tc_pthread_pthread_once(void) * @return :void */ -static void tc_pthread_pthread_yield(void) +static void tc_pthread_pthread_yield_pos(void) { int ret_chk = 0; g_bpthreadcallback = false; @@ -1296,7 +1407,7 @@ static void tc_pthread_pthread_yield(void) * Postconditions :none * @return :void */ -static void tc_pthread_pthread_cond_signal_wait(void) +static void tc_pthread_pthread_cond_signal_wait_pos(void) { pthread_t pthread_waiter; int ret_chk = ERROR; @@ -1425,7 +1536,41 @@ static void tc_pthread_pthread_sigmask(void) TC_SUCCESS_RESULT(); } -static void tc_pthread_pthread_self(void) + +static void tc_pthread_pthread_sigmask_invalid_signal_neg(void) +{ + int ret_chk; + pid_t pid = getpid(); + + sigset_t st_newmask; + sigset_t st_oldmask; + sigset_t st_pendmask; + struct timespec st_timespec; + struct sigaction st_act; + struct sigaction st_oact; + + g_sig_handle = false; + + st_timespec.tv_sec = SEC_5; + st_timespec.tv_nsec = 0; + + memset(&st_act, 0, sizeof(st_act)); + st_act.sa_handler = sigmask_handler; + + 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(NOSIG, &st_newmask, &st_oldmask); + TC_ASSERT_EQ("pthread_sigmask", ret_chk, EINVAL); + + + TC_SUCCESS_RESULT(); +} + +static void tc_pthread_pthread_self_pos(void) { int ret_chk; pthread_t tcb_pid; @@ -1439,7 +1584,7 @@ static void tc_pthread_pthread_self(void) TC_SUCCESS_RESULT(); } -static void tc_pthread_pthread_equal(void) +static void tc_pthread_pthread_equal_neg(void) { int ret_chk; pthread_t first_th; @@ -1461,7 +1606,8 @@ static void tc_pthread_pthread_equal(void) TC_SUCCESS_RESULT(); } -static void tc_pthread_pthread_setschedprio(void) + +static void tc_pthread_pthread_setschedprio_pos(void) { int ret_chk; pthread_t set_th; @@ -1481,7 +1627,28 @@ static void tc_pthread_pthread_setschedprio(void) TC_SUCCESS_RESULT(); } -static void tc_pthread_pthread_setgetname_np(void) +static void tc_pthread_pthread_setschedprio_invalid_prio_neg(void) +{ + int ret_chk; + pthread_t set_th; + uint8_t set_prio = -1; + + 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_chk = pthread_setschedprio(set_th, SCHED_PRIORITY_MAX+1); + TC_ASSERT_EQ_CLEANUP("pthread_setschedprio", ret_chk, ERROR, pthread_detach(set_th)); + + ret_chk = pthread_join(set_th, NULL); + TC_ASSERT_EQ_CLEANUP("pthread_join", ret_chk, OK, pthread_detach(set_th)); + TC_ASSERT_EQ("pthread_setschedprio", check_prio, set_prio); + + TC_SUCCESS_RESULT(); +} + + +static void tc_pthread_pthread_setgetname_np_pos(void) { int ret_chk; pthread_t name_th; @@ -1507,6 +1674,30 @@ static void tc_pthread_pthread_setgetname_np(void) TC_SUCCESS_RESULT(); } + +static void tc_pthread_pthread_setgetname_np_null_name_neg(void) +{ + int ret_chk; + pthread_t name_th; + char *thread_name = "NameThread"; + char get_name[32]; + + ret_chk = pthread_create(&name_th, NULL, infinite_loop_thread, NULL); + TC_ASSERT_EQ("pthread_create", ret_chk, OK); + + ret_chk = pthread_setname_np(name_th,NULL); + TC_ASSERT_EQ("pthread_setname_np", ret_chk, ERROR); + + ret_chk = pthread_cancel(name_th); + TC_ASSERT_EQ("pthread_cancel", ret_chk, OK); + + ret_chk = pthread_join(name_th, NULL); + TC_ASSERT_EQ("pthread_join", ret_chk, OK); + + TC_SUCCESS_RESULT(); +} + + /** * @fn :tc_pthread_pthread_setcanceltype * @brief :This tc tests pthread_setcanceltype() @@ -1520,7 +1711,7 @@ static void tc_pthread_pthread_setgetname_np(void) * @return :void */ #ifdef CONFIG_CANCELLATION_POINTS -static void tc_pthread_pthread_setcanceltype(void) +static void tc_pthread_pthread_setcanceltype_pos(void) { int type; int oldtype; @@ -1530,6 +1721,15 @@ static void tc_pthread_pthread_setcanceltype(void) ret_chk = pthread_setcanceltype(type, &oldtype); TC_ASSERT_EQ("pthread_setcanceltype", ret_chk, OK); + + TC_SUCCESS_RESULT(); +} +static void tc_pthread_pthread_setcanceltype_invalid_type_neg(void) +{ + int type; + int oldtype; + int ret_chk; + type = PTHREAD_CANCEL_DEFERRED; ret_chk = pthread_setcanceltype(type, &oldtype); TC_ASSERT_EQ("pthread_setcanceltype", ret_chk, ENOSYS); @@ -1566,7 +1766,7 @@ static void *test_mutex_consistent(void *param) * @Postconditions :none * @return :void */ -static void tc_pthread_pthread_mutex_consistent(void) +static void tc_pthread_pthread_mutex_consistent_pos(void) { int ret; void *status; @@ -1611,35 +1811,44 @@ static void tc_pthread_pthread_mutex_consistent(void) int pthread_main(void) { - tc_pthread_pthread_barrier_init_destroy_wait(); - tc_pthread_pthread_create_exit_join(); - tc_pthread_pthread_tryjoin_np(); - tc_pthread_pthread_kill(); - tc_pthread_pthread_cond_broadcast(); - tc_pthread_pthread_cond_init_destroy(); - tc_pthread_pthread_set_get_schedparam(); + tc_pthread_pthread_barrier_init_destroy_wait_pos(); + tc_pthread_pthread_create_exit_join_pos(); + tc_pthread_pthread_create_exit_join_neg(); + tc_pthread_pthread_create_exit_join_invalid_pid_neg(); + tc_pthread_pthread_create_exit_join_invalid_task_neg(); + tc_pthread_pthread_tryjoin_np_pos(); + tc_pthread_pthread_kill_pos(); + tc_pthread_pthread_cond_broadcast_pos(); + tc_pthread_pthread_cond_init_destroy_pos(); + tc_pthread_pthread_set_get_schedparam_pos(); #if CONFIG_NPTHREAD_KEYS > 0 - tc_pthread_pthread_key_create_delete_set_getspecific(); + tc_pthread_pthread_key_create_delete_set_getspecific_pos(); #endif - tc_pthread_pthread_cancel_setcancelstate(); - tc_pthread_pthread_setschedprio(); - tc_pthread_pthread_timed_wait(); - tc_pthread_pthread_mutex_init(); - tc_pthread_pthread_mutex_destroy(); - tc_pthread_pthread_mutex_lock_unlock_trylock(); + tc_pthread_pthread_cancel_setcancelstate_pos(); + tc_pthread_pthread_setschedprio_pos(); + tc_pthread_pthread_timed_wait_pos(); + tc_pthread_pthread_mutex_init_neg(); + tc_pthread_pthread_mutex_destroy_pos(); + tc_pthread_pthread_mutex_destroy_mutex_busy_neg(); + tc_pthread_pthread_mutex_lock_unlock_trylock_pos(); #ifndef CONFIG_PTHREAD_MUTEX_UNSAFE tc_pthread_pthread_mutex_consistent(); #endif - tc_pthread_pthread_once(); - tc_pthread_pthread_yield(); - tc_pthread_pthread_cond_signal_wait(); + tc_pthread_pthread_once_pos(); + tc_pthread_pthread_once_null_callback_neg(); + tc_pthread_pthread_once_null_opaque_neg(); + tc_pthread_pthread_yield_pos(); + tc_pthread_pthread_cond_signal_wait_pos(); tc_pthread_pthread_detach(); tc_pthread_pthread_sigmask(); - tc_pthread_pthread_self(); - tc_pthread_pthread_equal(); - tc_pthread_pthread_setgetname_np(); + tc_pthread_pthread_sigmask_invalid_signal_neg(); + tc_pthread_pthread_self_pos(); + tc_pthread_pthread_equal_neg(); + tc_pthread_pthread_setgetname_np_pos(); + tc_pthread_pthread_setgetname_np_null_name_neg(); #ifdef CONFIG_CANCELLATION_POINTS - tc_pthread_pthread_setcanceltype(); + tc_pthread_pthread_setcanceltype_pos(); + tc_pthread_pthread_setcanceltype_invalid_type_neg(); #endif return 0; diff --git a/apps/examples/testcase/le_tc/kernel/tc_sched.c b/apps/examples/testcase/le_tc/kernel/tc_sched.c index ceb4c37c21..918427067c 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_sched.c +++ b/apps/examples/testcase/le_tc/kernel/tc_sched.c @@ -109,7 +109,7 @@ static void *threadfunc_callback(void *param) * Postconditions :none * @return :void */ -static void tc_sched_sched_setget_scheduler_param(void) +static void tc_sched_sched_setget_scheduler_param_pos(void) { int ret_chk = ERROR; struct sched_param st_setparam; @@ -127,26 +127,6 @@ static void tc_sched_sched_setget_scheduler_param(void) scheduler_origin = sched_getscheduler(getpid()); TC_ASSERT_NEQ("sched_getscheduler", scheduler_origin, ERROR); - /* Check null priority parameter */ - - ret_chk = sched_setparam(getpid(), NULL); - TC_ASSERT_EQ_CLEANUP("sched_setparam", ret_chk, ERROR, sched_setparam(getpid(), &prio_origin)); - - ret_chk = sched_getparam(getpid(), NULL); - TC_ASSERT_EQ_CLEANUP("sched_getparam", ret_chk, ERROR, sched_setparam(getpid(), &prio_origin)); - - /* Check invalid priority parameter */ - - st_setparam.sched_priority = SCHED_OTHER; - ret_chk = sched_setscheduler(0, SCHED_OTHER, &st_setparam); - TC_ASSERT_EQ_CLEANUP("sched_setscheduler", ret_chk, ERROR, sched_setparam(getpid(), &prio_origin)); - - /* Check for invalid scheduling policy */ - - ret_chk = sched_setscheduler(0, SCHED_OTHER, &st_setparam); - TC_ASSERT_EQ_CLEANUP("sched_setscheduler", ret_chk, ERROR, sched_setparam(getpid(), &prio_origin)); - TC_ASSERT_EQ("sched_setscheduler", errno, EINVAL); - while (arr_idx < loop_cnt) { st_setparam.sched_priority = SCHED_PRIORITY; ret_chk = sched_setparam(getpid(), &st_setparam); @@ -172,6 +152,61 @@ static void tc_sched_sched_setget_scheduler_param(void) TC_SUCCESS_RESULT(); } + +static void tc_sched_sched_setget_scheduler_param_null_priority_neg(void) +{ + int ret_chk = ERROR; + struct sched_param prio_origin; + int scheduler_origin; + + /* get original priority and scheduler of task */ + ret_chk = sched_getparam(getpid(), &prio_origin); + TC_ASSERT_EQ("sched_getparam", ret_chk, OK); + + scheduler_origin = sched_getscheduler(getpid()); + TC_ASSERT_NEQ("sched_getscheduler", scheduler_origin, ERROR); + + /* Check null priority parameter */ + + ret_chk = sched_setparam(getpid(), NULL); + TC_ASSERT_EQ_CLEANUP("sched_setparam", ret_chk, ERROR, sched_setparam(getpid(), &prio_origin)); + + /* restore the task priority and scheduler as previous after testing */ + ret_chk = sched_setscheduler(getpid(), scheduler_origin, &prio_origin); + TC_ASSERT_NEQ("sched_setscheduler", ret_chk, ERROR); + + TC_SUCCESS_RESULT(); +} + +static void tc_sched_sched_setget_scheduler_param_invalid_priority_neg(void) +{ + int ret_chk = ERROR; + struct sched_param st_setparam; + struct sched_param prio_origin; + int scheduler_origin; + + /* get original priority and scheduler of task */ + ret_chk = sched_getparam(getpid(), &prio_origin); + TC_ASSERT_EQ("sched_getparam", ret_chk, OK); + + scheduler_origin = sched_getscheduler(getpid()); + TC_ASSERT_NEQ("sched_getscheduler", scheduler_origin, ERROR); + + /* Check invalid priority parameter */ + + st_setparam.sched_priority = SCHED_OTHER; + ret_chk = sched_setscheduler(0, SCHED_OTHER, &st_setparam); + TC_ASSERT_EQ_CLEANUP("sched_setscheduler", ret_chk, ERROR, sched_setparam(getpid(), &prio_origin)); + + /* restore the task priority and scheduler as previous after testing */ + ret_chk = sched_setscheduler(getpid(), scheduler_origin, &prio_origin); + TC_ASSERT_NEQ("sched_setscheduler", ret_chk, ERROR); + + TC_SUCCESS_RESULT(); +} + + + /** * @fn :tc_sched_sched_rr_get_interval * @brief :get the SCHED_RR interval for the named process @@ -181,16 +216,17 @@ static void tc_sched_sched_setget_scheduler_param(void) * Postconditions :none * @return :void */ -static void tc_sched_sched_rr_get_interval(void) + +static void tc_sched_sched_rr_get_interval_invalid_pid_neg(void) { int ret_chk; struct timespec st_timespec1; struct timespec st_timespec2; st_timespec1.tv_sec = 0; - st_timespec1.tv_nsec = -1; + st_timespec1.tv_nsec = 1; st_timespec2.tv_sec = 0; - st_timespec2.tv_nsec = -1; + st_timespec2.tv_nsec = 1; /* Check for invalid PID */ @@ -198,6 +234,21 @@ static void tc_sched_sched_rr_get_interval(void) TC_ASSERT_EQ("sched_rr_get_interval", ret_chk, ERROR); TC_ASSERT_EQ("sched_rr_get_interval", errno, EINVAL); + + TC_SUCCESS_RESULT(); +} + +static void tc_sched_sched_rr_get_interval_invalid_time_neg(void) +{ + int ret_chk; + struct timespec st_timespec1; + struct timespec st_timespec2; + st_timespec1.tv_sec = 0; + st_timespec1.tv_nsec = -1; + + 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_chk = sched_rr_get_interval(0, &st_timespec1); @@ -215,6 +266,14 @@ static void tc_sched_sched_rr_get_interval(void) 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); + + TC_SUCCESS_RESULT(); +} + +static void tc_sched_sched_rr_get_interval_null_interval_neg(void) +{ + int ret_chk; + /* Check for NULL interval */ ret_chk = sched_rr_get_interval(getpid(), NULL); @@ -234,7 +293,7 @@ static void tc_sched_sched_rr_get_interval(void) * Postconditions :none * @return :void */ -static void tc_sched_sched_yield(void) +static void tc_sched_sched_yield_pos(void) { int ret_chk = 0; @@ -265,7 +324,7 @@ static void tc_sched_sched_yield(void) */ #ifdef CONFIG_SCHED_WAITPID #ifdef CONFIG_SCHED_HAVE_PARENT -static void tc_sched_wait(void) +static void tc_sched_wait_pos(void) { int ret_chk; pid_t child1_pid; @@ -302,19 +361,13 @@ static void tc_sched_wait(void) * @return :void */ -static void tc_sched_waitid(void) +static void tc_sched_waitid_pos(void) { int ret_chk; pid_t child1_pid; pid_t child2_pid; siginfo_t info; - /* Check for The TCB corresponding to this PID is not our child. */ - - ret_chk = waitid(P_PID, 0, &info, WEXITED); - TC_ASSERT_EQ("waitid", ret_chk, ERROR); - TC_ASSERT_EQ("waitid", errno, ECHILD); - child1_pid = task_create("tc_waitid", SCHED_PRIORITY_DEFAULT, TASK_STACKSIZE, sleep1sec_taskdel, (char * const *)NULL); TC_ASSERT_GT("task_create", child1_pid, 0); @@ -333,6 +386,32 @@ static void tc_sched_waitid(void) TC_ASSERT_NEQ("waitid", ret_chk, ERROR); TC_ASSERT_EQ("waitid", (info.si_pid == child1_pid) || (info.si_pid == child2_pid), true); + + TC_SUCCESS_RESULT(); +} + + +static void tc_sched_waitid_invalid_childpid_neg(void) +{ + int ret_chk; + siginfo_t info; + + /* Check for The TCB corresponding to this PID is not our child. */ + + ret_chk = waitid(P_PID, 0, &info, WEXITED); + TC_ASSERT_EQ("waitid", ret_chk, ERROR); + TC_ASSERT_EQ("waitid", errno, ECHILD); + + + TC_SUCCESS_RESULT(); +} + +static void tc_sched_waitid_invalid_id_neg(void) +{ + int ret_chk; + pid_t child1_pid; + siginfo_t info; + /* Check for other ID types that are not supported */ child1_pid = task_create("tc_waitid", SCHED_PRIORITY_DEFAULT, TASK_STACKSIZE, sleep1sec_taskdel, (char * const *)NULL); @@ -349,6 +428,23 @@ static void tc_sched_waitid(void) TC_SUCCESS_RESULT(); } + +static void tc_sched_waitid_invalid_processid_neg(void) +{ + int ret_chk; + pid_t child1_pid; + siginfo_t info; + idtype_t invalid_idtype = -1; + id_t child_id = getpid(); + + /* Check for other ID types that are not supported */ + + ret_chk = waitid(invalid_idtype, child_id, &info, WEXITED); + TC_ASSERT_EQ("waitid", ret_chk, ERROR); + + TC_SUCCESS_RESULT(); +} + #endif /** @@ -363,22 +459,44 @@ static void tc_sched_waitid(void) * @return :void */ -static void tc_sched_waitpid(void) +static void tc_sched_waitpid_pos(void) { int ret_chk; pid_t child_pid; int status; + child_pid = task_create("tc_waitpid", SCHED_PRIORITY_DEFAULT, TASK_STACKSIZE, sleep1sec_taskdel, (char * const *)NULL); + TC_ASSERT_GT("task_create", child_pid, 0); + + ret_chk = waitpid(child_pid, &status, 0); + TC_ASSERT_EQ("waitpid", ret_chk, child_pid); + + TC_SUCCESS_RESULT(); +} + +static void tc_sched_waitpid_invalid_pid_neg(void) +{ + int ret_chk; + int status; + /* Check for The TCB corresponding to this PID is not our child. */ ret_chk = waitpid(INVALID_PID, &status, 0); TC_ASSERT_EQ("waitpid", ret_chk, ERROR); TC_ASSERT_EQ("waitpid", errno, ECHILD); + TC_SUCCESS_RESULT(); +} + +static void tc_sched_waitpid_neg(void) +{ + int ret_chk; + pid_t child_pid; + int status; + + child_pid = task_create("tc_waitpid", SCHED_PRIORITY_DEFAULT, TASK_STACKSIZE, sleep1sec_taskdel, (char * const *)NULL); TC_ASSERT_GT("task_create", child_pid, 0); - ret_chk = waitpid(child_pid, &status, 0); - TC_ASSERT_EQ("waitpid", ret_chk, child_pid); /* None of the options are supported */ @@ -388,6 +506,8 @@ static void tc_sched_waitpid(void) TC_SUCCESS_RESULT(); } + + #endif /** @@ -401,7 +521,7 @@ static void tc_sched_waitpid(void) * @return :void */ -static void tc_sched_sched_lock_unlock(void) +static void tc_sched_sched_lock_unlock_pos(void) { int ret_chk = ERROR; int cntlock; @@ -467,7 +587,7 @@ static int pthread_sched_self(void *args) * @return :void */ -static void tc_sched_sched_self(void) +static void tc_sched_sched_self_pos(void) { int ret; int pid; @@ -492,7 +612,7 @@ static void tc_sched_sched_self(void) * Postconditions :none * @return :void */ -static void tc_sched_sched_foreach(void) +static void tc_sched_sched_foreach_pos(void) { g_callback = false; int fd; @@ -516,7 +636,7 @@ static void tc_sched_sched_foreach(void) * @return :void */ -static void tc_sched_sched_lockcount(void) +static void tc_sched_sched_lockcount_pos(void) { int ret_chk = ERROR; int prev_cnt; @@ -553,7 +673,7 @@ static void tc_sched_sched_lockcount(void) * @return :void */ -static void tc_sched_sched_getstreams(void) +static void tc_sched_sched_getstreams_pos(void) { struct streamlist *stream; @@ -576,7 +696,7 @@ static void tc_sched_sched_getstreams(void) * @return :void */ -static void tc_sched_task_setcancelstate(void) +static void tc_sched_task_setcancelstate_pos(void) { int noncancelable_flag; int originstate; @@ -587,12 +707,6 @@ static void tc_sched_task_setcancelstate(void) noncancelable_flag = tcb->flags & TCB_FLAG_NONCANCELABLE; originstate = noncancelable_flag == TCB_FLAG_NONCANCELABLE ? TASK_CANCEL_DISABLE : TASK_CANCEL_ENABLE; - /* Negative case with invalid mode. It will return ERROR & set errno EINVAL */ - ret_chk = task_setcancelstate(TASK_CANCEL_INVALID, &oldstate); - TC_ASSERT_EQ_CLEANUP("task_setcancelstate", ret_chk, ERROR, goto errout); - TC_ASSERT_EQ_CLEANUP("task_setcancelstate", get_errno(), EINVAL, goto errout); - TC_ASSERT_EQ_CLEANUP("task_setcancelstate", oldstate, originstate, goto errout); - /* Positive cases with valid mode. It will return OK */ ret_chk = task_setcancelstate(TASK_CANCEL_DISABLE, &oldstate); @@ -617,6 +731,38 @@ static void tc_sched_task_setcancelstate(void) tcb->flags |= noncancelable_flag; } +static void tc_sched_task_setcancelstate_invalid_mode_neg(void) +{ + int noncancelable_flag; + int originstate; + int oldstate; + struct tcb_s *tcb = sched_self(); + int ret_chk; + + noncancelable_flag = tcb->flags & TCB_FLAG_NONCANCELABLE; + originstate = noncancelable_flag == TCB_FLAG_NONCANCELABLE ? TASK_CANCEL_DISABLE : TASK_CANCEL_ENABLE; + + /* Negative case with invalid mode. It will return ERROR & set errno EINVAL */ + ret_chk = task_setcancelstate(TASK_CANCEL_INVALID, &oldstate); + TC_ASSERT_EQ_CLEANUP("task_setcancelstate", ret_chk, ERROR, goto errout); + TC_ASSERT_EQ_CLEANUP("task_setcancelstate", get_errno(), EINVAL, goto errout); + TC_ASSERT_EQ_CLEANUP("task_setcancelstate", oldstate, originstate, goto errout); + + /* restore the cancestate */ + + ret_chk = task_setcancelstate(originstate, NULL); + TC_ASSERT_EQ_CLEANUP("task_setcancelstate", ret_chk, OK, goto errout); + TC_ASSERT_EQ_CLEANUP("task_setcancelstate", tcb->flags & TCB_FLAG_NONCANCELABLE, noncancelable_flag, goto errout); + + TC_SUCCESS_RESULT(); + +errout: + tcb->flags |= noncancelable_flag; +} + + + + /** * @fn :tc_sched_task_setcanceltype * @brief :This tc tests tc_sched_task_setcanceltype() @@ -631,7 +777,7 @@ static void tc_sched_task_setcancelstate(void) * @return :void */ #ifdef CONFIG_CANCELLATION_POINTS -static void tc_sched_task_setcanceltype(void) +static void tc_sched_task_setcanceltype_pos(void) { int defferred_flag; int origintype; @@ -642,11 +788,6 @@ static void tc_sched_task_setcanceltype(void) defferred_flag = tcb->flags & TCB_FLAG_CANCEL_DEFERRED; origintype = defferred_flag == TCB_FLAG_CANCEL_DEFERRED ? TASK_CANCEL_DEFERRED : TASK_CANCEL_ASYNCHRONOUS; - /* Negative case with invalid mode. It will return EINVAL */ - ret_chk = task_setcanceltype(TASK_CANCEL_INVALID, &oldtype); - TC_ASSERT_EQ_CLEANUP("task_setcanceltype", ret_chk, EINVAL, goto errout); - TC_ASSERT_EQ_CLEANUP("task_setcanceltype", oldtype, origintype, goto errout); - /* Positive cases with valid mode. It will return OK */ ret_chk = task_setcanceltype(TASK_CANCEL_DEFERRED, &oldtype); @@ -670,6 +811,36 @@ static void tc_sched_task_setcanceltype(void) errout: tcb->flags |= defferred_flag; } + +static void tc_sched_task_setcanceltype_invalid_mode_neg(void) +{ + int defferred_flag; + int origintype; + int oldtype; + struct tcb_s *tcb = sched_self(); + int ret_chk; + + defferred_flag = tcb->flags & TCB_FLAG_CANCEL_DEFERRED; + origintype = defferred_flag == TCB_FLAG_CANCEL_DEFERRED ? TASK_CANCEL_DEFERRED : TASK_CANCEL_ASYNCHRONOUS; + + /* Negative case with invalid mode. It will return EINVAL */ + ret_chk = task_setcanceltype(TASK_CANCEL_INVALID, &oldtype); + TC_ASSERT_EQ_CLEANUP("task_setcanceltype", ret_chk, EINVAL, goto errout); + TC_ASSERT_EQ_CLEANUP("task_setcanceltype", oldtype, origintype, goto errout); + + /* restore the canceltype */ + + ret_chk = task_setcanceltype(origintype, NULL); + TC_ASSERT_EQ_CLEANUP("task_setcanceltype", ret_chk, OK, goto errout); + TC_ASSERT_EQ_CLEANUP("task_setcanceltype", tcb->flags & TCB_FLAG_CANCEL_DEFERRED, defferred_flag, goto errout); + + TC_SUCCESS_RESULT(); + +errout: + tcb->flags |= defferred_flag; +} + + #endif #endif @@ -680,25 +851,37 @@ int sched_main(void) { #ifdef CONFIG_SCHED_WAITPID #ifdef CONFIG_SCHED_HAVE_PARENT - tc_sched_wait(); - tc_sched_waitid(); + tc_sched_wait_pos(); + tc_sched_waitid_pos(); + tc_sched_waitid_invalid_childpid_neg(); + tc_sched_waitid_invalid_id_neg(); + tc_sched_waitid_invalid_processid_neg(); #endif - tc_sched_waitpid(); + tc_sched_waitpid_pos(); + tc_sched_waitpid_invalid_pid_neg(); + tc_sched_waitpid_neg(); #endif - tc_sched_sched_setget_scheduler_param(); - tc_sched_sched_rr_get_interval(); - tc_sched_sched_yield(); - tc_sched_sched_lock_unlock(); - tc_sched_sched_self(); - tc_sched_sched_foreach(); - tc_sched_sched_lockcount(); + tc_sched_sched_setget_scheduler_param_pos(); + tc_sched_sched_setget_scheduler_param_null_priority_neg(); + tc_sched_sched_setget_scheduler_param_invalid_priority_neg(); + tc_sched_sched_rr_get_interval_invalid_pid_neg(); + tc_sched_sched_rr_get_interval_invalid_time_neg(); + tc_sched_sched_rr_get_interval_null_interval_neg(); + tc_sched_sched_yield_pos(); + tc_sched_sched_lock_unlock_pos(); + tc_sched_sched_self_pos(); + tc_sched_sched_foreach_pos(); + tc_sched_sched_lockcount_pos(); #if CONFIG_NFILE_STREAMS > 0 - tc_sched_sched_getstreams(); + tc_sched_sched_getstreams_pos(); #endif #ifndef CONFIG_BUILD_PROTECTED - tc_sched_task_setcancelstate(); + tc_sched_task_setcancelstate_pos(); + tc_sched_task_setcancelstate_invalid_mode_neg(); #ifdef CONFIG_CANCELLATION_POINTS - tc_sched_task_setcanceltype(); + tc_sched_task_setcanceltype_pos(); + tc_sched_task_setcanceltype_invalid_mode_neg(); + #endif #endif diff --git a/apps/examples/testcase/le_tc/kernel/tc_semaphore.c b/apps/examples/testcase/le_tc/kernel/tc_semaphore.c index f8ac3af521..85353d752d 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_semaphore.c +++ b/apps/examples/testcase/le_tc/kernel/tc_semaphore.c @@ -120,27 +120,13 @@ static void *consumer_func(void *arg) * Postconditions :Semaphore should be destroyed. * @return :void */ -static void tc_semaphore_sem_post_wait(void) +static void tc_semaphore_sem_post_wait_pos(void) { pthread_addr_t pexit_value = NULL; pthread_t pid; pthread_t cid; int ret_chk; -#ifndef CONFIG_DEBUG - /* sem_wait test NULL case */ - - ret_chk = sem_wait(NULL); - TC_ASSERT_EQ("sem_wait", ret_chk, ERROR); - TC_ASSERT_EQ("sem_wait", get_errno(), EINVAL); -#endif - - /* sem_post test NULL case */ - - ret_chk = sem_post(NULL); - TC_ASSERT_EQ("sem_post", ret_chk, ERROR); - TC_ASSERT_EQ("sem_post", get_errno(), EINVAL); - /* sem_wait & sem post ping-pong test */ ret_chk = sem_init(&g_empty, PSHARED, 1); @@ -174,6 +160,65 @@ static void tc_semaphore_sem_post_wait(void) sem_destroy(&g_sem); } +static void tc_semaphore_sem_wait_neg(void) +{ + int ret_chk; + +#ifndef CONFIG_DEBUG + /* sem_wait test NULL case */ + + ret_chk = sem_wait(NULL); + TC_ASSERT_EQ("sem_wait", ret_chk, ERROR); + TC_ASSERT_EQ("sem_wait", get_errno(), EINVAL); +#endif + + TC_SUCCESS_RESULT(); + +cleanup: + sem_destroy(&g_empty); + sem_destroy(&g_full); + sem_destroy(&g_sem); +} + +static void tc_semaphore_sem_wait_nsem_neg(void) +{ + int ret_chk; + //static sem_t g_sem = -1; + +#ifndef CONFIG_DEBUG + /* sem_wait test NULL case */ + + ret_chk = sem_wait(-1); + TC_ASSERT_EQ("sem_wait", ret_chk, ERROR); + TC_ASSERT_EQ("sem_wait", get_errno(), EINVAL); +#endif + + TC_SUCCESS_RESULT(); + +cleanup: + sem_destroy(&g_empty); + sem_destroy(&g_full); + sem_destroy(&g_sem); +} + +static void tc_semaphore_sem_post_neg(void) +{ + int ret_chk; + + /* sem_post test NULL case */ + + ret_chk = sem_post(NULL); + TC_ASSERT_EQ("sem_post", ret_chk, ERROR); + TC_ASSERT_EQ("sem_post", get_errno(), EINVAL); + + TC_SUCCESS_RESULT(); + +cleanup: + sem_destroy(&g_empty); + sem_destroy(&g_full); + sem_destroy(&g_sem); +} + /** * @fn :tc_semaphore_sem_trywait @@ -187,11 +232,29 @@ static void tc_semaphore_sem_post_wait(void) * @return :void */ -static void tc_semaphore_sem_trywait(void) +static void tc_semaphore_sem_trywait_pos(void) { sem_t sem; int ret_chk; + /* sem_trywait can get sem */ + + ret_chk = sem_init(&sem, PSHARED, 1); + TC_ASSERT_EQ("sem_init", ret_chk, OK); + + ret_chk = sem_trywait(&sem); + TC_ASSERT_EQ("sem_trywait", ret_chk, OK); + + ret_chk = sem_destroy(&sem); + TC_ASSERT_EQ("sem_destroy", ret_chk, OK); + + TC_SUCCESS_RESULT(); +} + +static void tc_semaphore_sem_trywait_null_semid_neg(void) +{ + int ret_chk; + #ifndef CONFIG_DEBUG /* test NULL case */ @@ -200,6 +263,15 @@ static void tc_semaphore_sem_trywait(void) TC_ASSERT_EQ("sem_trywait", get_errno(), EINVAL); #endif + + TC_SUCCESS_RESULT(); +} + +static void tc_semaphore_sem_trywait_null_value_neg(void) +{ + sem_t sem; + int ret_chk; + /* sem_trywait can't get sem */ ret_chk = sem_init(&sem, PSHARED, 0); @@ -212,20 +284,10 @@ static void tc_semaphore_sem_trywait(void) ret_chk = sem_destroy(&sem); TC_ASSERT_EQ("sem_destroy", ret_chk, OK); - /* sem_trywait can get sem */ - - ret_chk = sem_init(&sem, PSHARED, 1); - TC_ASSERT_EQ("sem_init", ret_chk, OK); - - ret_chk = sem_trywait(&sem); - TC_ASSERT_EQ("sem_trywait", ret_chk, OK); - - ret_chk = sem_destroy(&sem); - TC_ASSERT_EQ("sem_destroy", ret_chk, OK); - TC_SUCCESS_RESULT(); } + /** * @fn :tc_semaphore_sem_timedwait * @brief :this tc tests sem_timedwait @@ -236,7 +298,7 @@ static void tc_semaphore_sem_trywait(void) * Postconditions :none * @return :void */ -static void tc_semaphore_sem_timedwait(void) +static void tc_semaphore_sem_timedwait_pos(void) { struct timespec abstime; struct timespec curtime; @@ -250,18 +312,6 @@ static void tc_semaphore_sem_timedwait(void) ret_chk = clock_gettime(CLOCK_REALTIME, &abstime); TC_ASSERT_EQ("clock_gettime", ret_chk, OK); -#ifdef CONFIG_DEBUG - /* NULL case test */ - - ret_chk = sem_timedwait(&sem, NULL); - TC_ASSERT_EQ("sem_timedwait", ret_chk, ERROR); - TC_ASSERT_EQ("sem_timedwait", get_errno(), EINVAL); - - ret_chk = sem_timedwait(NULL, &abstime); - TC_ASSERT_EQ("sem_timedwait", ret_chk, ERROR); - TC_ASSERT_EQ("sem_timedwait", get_errno(), EINVAL); -#endif - /* success to get sem case test */ ret_chk = clock_gettime(CLOCK_REALTIME, &abstime); @@ -283,6 +333,72 @@ static void tc_semaphore_sem_timedwait(void) ret_chk = sem_destroy(&sem); TC_ASSERT_EQ("sem_destroy", ret_chk, OK); + + TC_SUCCESS_RESULT(); +} + + +static void tc_semaphore_sem_timedwait_null_timespec_neg(void) +{ + struct timespec abstime; + sem_t sem; + int ret_chk; + + /* init sem count to 1 */ + + ret_chk = sem_init(&sem, PSHARED, 1); + TC_ASSERT_EQ("sem_init", ret_chk, OK); + ret_chk = clock_gettime(CLOCK_REALTIME, &abstime); + TC_ASSERT_EQ("clock_gettime", ret_chk, OK); + +#ifdef CONFIG_DEBUG + /* NULL case test */ + + ret_chk = sem_timedwait(&sem, NULL); + TC_ASSERT_EQ("sem_timedwait", ret_chk, ERROR); + TC_ASSERT_EQ("sem_timedwait", get_errno(), EINVAL); + +#endif + ret_chk = sem_destroy(&sem); + TC_ASSERT_EQ("sem_destroy", ret_chk, OK); + + TC_SUCCESS_RESULT(); +} + +static void tc_semaphore_sem_timedwait_null_semt_neg(void) +{ + struct timespec abstime; + sem_t sem; + int ret_chk; + + /* init sem count to 1 */ + + ret_chk = sem_init(&sem, PSHARED, 1); + TC_ASSERT_EQ("sem_init", ret_chk, OK); + ret_chk = clock_gettime(CLOCK_REALTIME, &abstime); + TC_ASSERT_EQ("clock_gettime", ret_chk, OK); + +#ifdef CONFIG_DEBUG + /* NULL case test */ + + ret_chk = sem_timedwait(NULL, &abstime); + TC_ASSERT_EQ("sem_timedwait", ret_chk, ERROR); + TC_ASSERT_EQ("sem_timedwait", get_errno(), EINVAL); +#endif + + ret_chk = sem_destroy(&sem); + TC_ASSERT_EQ("sem_destroy", ret_chk, OK); + + TC_SUCCESS_RESULT(); +} + + +static void tc_semaphore_sem_timedwait_neg_nsec_neg(void) +{ + struct timespec abstime; + sem_t sem; + int ret_chk; + /* init sem count to 0 */ ret_chk = sem_init(&sem, PSHARED, 0); @@ -295,42 +411,48 @@ static void tc_semaphore_sem_timedwait(void) TC_ASSERT_EQ("sem_timedwait", ret_chk, ERROR); TC_ASSERT_EQ("sem_timedwait", get_errno(), EINVAL); - abstime.tv_nsec = 1000000000; - ret_chk = sem_timedwait(&sem, &abstime); - TC_ASSERT_EQ("sem_timedwait", ret_chk, ERROR); - TC_ASSERT_EQ("sem_timedwait", get_errno(), EINVAL); + ret_chk = sem_destroy(&sem); + TC_ASSERT_EQ("sem_destroy", ret_chk, OK); - /* expired time test */ + TC_SUCCESS_RESULT(); +} + +static void tc_semaphore_sem_timedwait_nsec_neg(void) +{ + struct timespec abstime; + sem_t sem; + int ret_chk; + + /* init sem count to 1 */ + ret_chk = sem_init(&sem, PSHARED, 1); + TC_ASSERT_EQ("sem_init", ret_chk, OK); ret_chk = clock_gettime(CLOCK_REALTIME, &abstime); TC_ASSERT_EQ("clock_gettime", ret_chk, OK); + /*invalid nsec case for higer value*/ + + abstime.tv_nsec = 1000000000; ret_chk = sem_timedwait(&sem, &abstime); TC_ASSERT_EQ("sem_timedwait", ret_chk, ERROR); - TC_ASSERT_EQ("sem_timedwait", get_errno(), ETIMEDOUT); + TC_ASSERT_EQ("sem_timedwait", get_errno(), EINVAL); - /* fail to get sem case test */ + /* expired time test */ ret_chk = clock_gettime(CLOCK_REALTIME, &abstime); TC_ASSERT_EQ("clock_gettime", ret_chk, OK); - abstime.tv_sec = abstime.tv_sec + SEC_2; - abstime.tv_nsec = 0; - ret_chk = sem_timedwait(&sem, &abstime); TC_ASSERT_EQ("sem_timedwait", ret_chk, ERROR); TC_ASSERT_EQ("sem_timedwait", get_errno(), ETIMEDOUT); - ret_chk = clock_gettime(CLOCK_REALTIME, &curtime); - TC_ASSERT_EQ("clock_gettime", ret_chk, OK); - TC_ASSERT_EQ("sem_timedwait", abstime.tv_sec, curtime.tv_sec); - ret_chk = sem_destroy(&sem); TC_ASSERT_EQ("sem_destroy", ret_chk, OK); TC_SUCCESS_RESULT(); } + /** * @fn :tc_semaphore_sem_destroy * @brief :this tc tests sem_destroy function @@ -341,17 +463,11 @@ static void tc_semaphore_sem_timedwait(void) * Postconditions :none * @return :void */ -static void tc_semaphore_sem_destroy(void) +static void tc_semaphore_sem_destroy_pos(void) { sem_t sem; int ret_chk; - /* NULL parameter check */ - - ret_chk = sem_destroy(NULL); - TC_ASSERT_EQ("sem_destroy", ret_chk, ERROR); - TC_ASSERT_EQ("sem_destroy", get_errno(), EINVAL); - ret_chk = sem_init(&sem, PSHARED, 1); TC_ASSERT_EQ("sem_init", ret_chk, OK); @@ -362,6 +478,18 @@ static void tc_semaphore_sem_destroy(void) TC_SUCCESS_RESULT(); } +static void tc_semaphore_sem_destroy_neg(void) +{ + int ret_chk; + + /* NULL parameter check */ + + ret_chk = sem_destroy(NULL); + TC_ASSERT_EQ("sem_destroy", ret_chk, ERROR); + TC_ASSERT_EQ("sem_destroy", get_errno(), EINVAL); + + TC_SUCCESS_RESULT(); +} /** * @fn :tc_semaphore_sem_setprotocol * @brief :Set semaphore protocol attribute @@ -371,7 +499,7 @@ static void tc_semaphore_sem_destroy(void) * Postconditions :none * @return :void */ -static void tc_semaphore_sem_setprotocol(void) +static void tc_semaphore_sem_setprotocol_pos(void) { sem_t sem; int ret_chk; @@ -390,10 +518,40 @@ static void tc_semaphore_sem_setprotocol(void) TC_ASSERT_EQ("sem_setprotocol", errno, ENOSYS); #endif + ret_chk = sem_destroy(&sem); + TC_ASSERT_EQ("sem_destroy", ret_chk, OK); + TC_ASSERT_EQ("sem_destroy", sem.semcount, 1); + + TC_SUCCESS_RESULT(); +} + +static void tc_semaphore_sem_setprotocol_protect_protocol_neg(void) +{ + sem_t sem; + int ret_chk; + + ret_chk = sem_init(&sem, PSHARED, 1); + TC_ASSERT_EQ("sem_init", ret_chk, OK); + ret_chk = sem_setprotocol(&sem, SEM_PRIO_PROTECT); TC_ASSERT_EQ("sem_setprotocol", ret_chk, ERROR); TC_ASSERT_EQ("sem_setprotocol", errno, ENOSYS); + ret_chk = sem_destroy(&sem); + TC_ASSERT_EQ("sem_destroy", ret_chk, OK); + TC_ASSERT_EQ("sem_destroy", sem.semcount, 1); + + TC_SUCCESS_RESULT(); +} + +static void tc_semaphore_sem_setprotocol_default_protocol_neg(void) +{ + sem_t sem; + int ret_chk; + + ret_chk = sem_init(&sem, PSHARED, 1); + TC_ASSERT_EQ("sem_init", ret_chk, OK); + ret_chk = sem_setprotocol(&sem, SEM_PRIO_DEFAULT); TC_ASSERT_EQ("sem_setprotocol", ret_chk, ERROR); TC_ASSERT_EQ("sem_setprotocol", errno, EINVAL); @@ -405,6 +563,7 @@ static void tc_semaphore_sem_setprotocol(void) TC_SUCCESS_RESULT(); } + /** * @fn :tc_semaphore_sem_tickwait * @brief :lighter weight version of sem_timedwait() - will lock the semaphore referenced by sem as in the sem_wait() function @@ -415,7 +574,7 @@ static void tc_semaphore_sem_setprotocol(void) * Postconditions :none * @return :void */ -static void tc_semaphore_sem_tickwait(void) +static void tc_semaphore_sem_tickwait_pos(void) { int fd; int ret_chk; @@ -432,12 +591,28 @@ static void tc_semaphore_sem_tickwait(void) int semaphore_main(void) { - tc_semaphore_sem_destroy(); - tc_semaphore_sem_post_wait(); - tc_semaphore_sem_setprotocol(); - tc_semaphore_sem_tickwait(); - tc_semaphore_sem_trywait(); - tc_semaphore_sem_timedwait(); - + + tc_semaphore_sem_post_wait_pos(); + tc_semaphore_sem_post_neg(); + tc_semaphore_sem_wait_neg(); + + tc_semaphore_sem_setprotocol_pos(); + tc_semaphore_sem_setprotocol_protect_protocol_neg(); + tc_semaphore_sem_setprotocol_default_protocol_neg(); + + tc_semaphore_sem_tickwait_pos(); + tc_semaphore_sem_trywait_pos(); + tc_semaphore_sem_trywait_null_semid_neg(); + tc_semaphore_sem_trywait_null_value_neg(); + + tc_semaphore_sem_timedwait_pos(); + tc_semaphore_sem_timedwait_null_timespec_neg(); + tc_semaphore_sem_timedwait_null_semt_neg(); + tc_semaphore_sem_timedwait_neg_nsec_neg(); + + tc_semaphore_sem_destroy_pos(); + tc_semaphore_sem_destroy_neg(); + + return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_signal.c b/apps/examples/testcase/le_tc/kernel/tc_signal.c index 3dd65e5a9f..42714df9f1 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_signal.c +++ b/apps/examples/testcase/le_tc/kernel/tc_signal.c @@ -126,7 +126,7 @@ void sigaction_handler(int signo) * Postconditions :none * @return :void */ -static void tc_signal_sigwaitinfo(void) +static void tc_signal_sigwaitinfo_pos(void) { int ret_chk; struct siginfo value; @@ -157,7 +157,7 @@ static void tc_signal_sigwaitinfo(void) * Postconditions :none * @return :void */ -static void tc_signal_sigaction(void) +static void tc_signal_sigaction_pos(void) { int ret_chk = ERROR; struct sigaction st_act; @@ -192,6 +192,65 @@ static void tc_signal_sigaction(void) TC_SUCCESS_RESULT(); } +static void tc_signal_sigaction_neg_signal_neg(void) +{ + int ret_chk = ERROR; + struct sigaction st_act; + struct sigaction st_oact; + int fd; + fd = tc_get_drvfd(); + FAR sigactq_t *sigact_before; + FAR sigactq_t *sigact_after; + + ret_chk = sigaction(-1, &st_act, &st_oact); + TC_ASSERT_EQ("sigaction", ret_chk,ERROR); + + /* make sure action is not changed */ + sigact_after = (FAR sigactq_t *)ioctl(fd, TESTIOC_GET_SIG_FINDACTION_ADD, SIGINT); + TC_ASSERT_EQ("sig_findaction", sigact_after, NULL); + TC_ASSERT_EQ("sig_findaction", sigact_before, sigact_after); + + TC_SUCCESS_RESULT(); +} + +static void tc_signal_sigaction_invalid_signals_neg(void) +{ + int ret_chk = ERROR; + struct sigaction st_act; + struct sigaction st_oact; + FAR sigactq_t *sigact_before; + FAR sigactq_t *sigact_after; + int fd; + fd = tc_get_drvfd(); + + ret_chk = sigaction(33, &st_act, &st_oact); + TC_ASSERT_EQ("sigaction", ret_chk,ERROR); + + /* make sure action is not changed */ + sigact_after = (FAR sigactq_t *)ioctl(fd, TESTIOC_GET_SIG_FINDACTION_ADD, SIGINT); + TC_ASSERT_EQ("sig_findaction", sigact_after, NULL); + TC_ASSERT_EQ("sig_findaction", sigact_before, sigact_after); + + TC_SUCCESS_RESULT(); +} + +static void tc_signal_sigaction_null_action_neg(void) +{ + int ret_chk = ERROR; + struct sigaction *st_act = NULL; + struct sigaction st_oact; + int fd; + fd = tc_get_drvfd(); + + ret_chk = sigaction(SIGINT, st_act, &st_oact); + TC_ASSERT_EQ("sigaction", ret_chk, 0); + + + TC_SUCCESS_RESULT(); +} + + + static int kill_handler_task(int argc, char *argv[]) { /* This task will be finished because of kill signal from main task. */ @@ -220,7 +279,7 @@ static void *kill_handler_thread(void *param) * @return :void */ -static void tc_signal_kill(void) +static void tc_signal_kill_pos(void) { pid_t pid; int ret_chk = ERROR; @@ -265,6 +324,47 @@ static void tc_signal_kill(void) TC_SUCCESS_RESULT(); } +static void tc_signal_kill_invalid_pid_neg(void) +{ + pid_t pid = -1; + int ret_chk = ERROR; + + ret_chk = kill(pid, SIGTERM); + sleep(SEC_1); + TC_ASSERT_EQ("kill", ret_chk, ERROR); + + TC_SUCCESS_RESULT(); +} + +static void tc_signal_kill_invalid_signal_neg(void) +{ + pid_t pid ; + int ret_chk = ERROR; + pid = getpid(); + + if (pid != 0) { + ret_chk = kill(pid, SIGHUP); + sleep(SEC_1); + TC_ASSERT_NEQ("kill", ret_chk, ERROR); + + ret_chk = kill(pid, SIGINT); + sleep(SEC_1); + TC_ASSERT_NEQ("kill", ret_chk, ERROR); + + ret_chk = kill(pid, SIGQUIT); + sleep(SEC_1); + TC_ASSERT_NEQ("kill", ret_chk, ERROR); + } + + + ret_chk = kill(pid, 9999); + sleep(SEC_1); + TC_ASSERT_EQ("kill", ret_chk, ERROR); + + TC_SUCCESS_RESULT(); +} + + /** * @fn :tc_signal_nanosleep * @brief :Suspend the process for the time specified. @@ -275,7 +375,7 @@ static void tc_signal_kill(void) * @return :void */ -static void tc_signal_nanosleep(void) +static void tc_signal_nanosleep_neg(void) { struct timespec st_timespec; int ret_chk; @@ -292,8 +392,6 @@ static void tc_signal_nanosleep(void) ret_chk = nanosleep(&st_timespec, NULL); TC_ASSERT_NEQ("nanosleep", ret_chk, ERROR); - clock_gettime(clock_id, &st_final_timespec); - TC_ASSERT_EQ("clock_gettime", st_final_timespec.tv_sec - st_init_timespec.tv_sec, st_timespec.tv_sec); TC_SUCCESS_RESULT(); } @@ -306,7 +404,7 @@ static void tc_signal_nanosleep(void) * Postconditions :none * @return :void */ -static void tc_signal_pause(void) +static void tc_signal_pause_pos(void) { int ret_chk = ERROR; int fd; @@ -360,7 +458,7 @@ static void tc_signal_pause(void) * Postconditions :none * @return :void */ -static void tc_signal_sigsuspend(void) +static void tc_signal_sigsuspend_pos(void) { int ret_chk = ERROR; @@ -418,6 +516,8 @@ static void tc_signal_sigsuspend(void) return; } + + /** * @fn :tc_signal_sig_pending_procmask_emptyset_addset * @brief :Change the signal mask for the calling thread and retrieve the\ @@ -429,7 +529,7 @@ static void tc_signal_sigsuspend(void) * Postconditions :none * @return :void */ -static void tc_signal_sig_pending_procmask_emptyset_addset(void) +static void tc_signal_sig_pending_procmask_emptyset_addset_pos(void) { int ret_chk = ERROR; pid_t pid = getpid(); @@ -492,7 +592,7 @@ static void tc_signal_sig_pending_procmask_emptyset_addset(void) * @return :void */ -static void tc_signal_sigqueue(void) +static void tc_signal_sigqueue_pos(void) { struct sigaction st_act; struct sigaction st_oact; @@ -519,6 +619,28 @@ static void tc_signal_sigqueue(void) TC_SUCCESS_RESULT(); } +static void tc_signal_sigqueue_neg(void) +{ + struct sigaction st_act; + struct sigaction st_oact; + g_sig_handle = false; + + st_act.sa_sigaction = sigint_handler; + sigemptyset(&st_act.sa_mask); + /*information transfer switch */ + st_act.sa_flags = SA_SIGINFO; + TC_ASSERT_NEQ("sigaction", sigaction(SIGINT, &st_act, &st_oact), ERROR); + + sleep(SEC_2); + + union sigval mysigval; + mysigval.sival_int = VAL_100; + pid_t invalid_pid = -1; + TC_ASSERT_NEQ("sigqueue", sigqueue(invalid_pid, SIGINT, mysigval), OK); + + TC_SUCCESS_RESULT(); +} + /** * @fn :tc_signal_sigtimedwait * @brief :Create a task and suspends execution of the calling thread until one of the\ @@ -531,7 +653,7 @@ static void tc_signal_sigqueue(void) * @return :void */ -static void tc_signal_sigtimedwait(void) +static void tc_signal_sigtimedwait_pos(void) { int ret_chk; struct siginfo value; @@ -568,6 +690,21 @@ static void tc_signal_sigtimedwait(void) TC_SUCCESS_RESULT(); } +static void tc_signal_sigtimedwait_neg(void) +{ + int ret_chk; + struct siginfo value; + sigset_t sigset; + sigset_t oldset; + + ret_chk = sigtimedwait(&sigset, &value, NULL); + TC_ASSERT_EQ("sigtimedwait", ret_chk, ERROR); + TC_ASSERT_EQ_CLEANUP("sigtimedwait", ret_chk, ERROR, sigprocmask(SIG_SETMASK, &oldset, NULL)); + + + TC_SUCCESS_RESULT(); +} + /** * @fn :tc_signal_sighold_sigrelse * @brief :set and unset a specific signal @@ -576,7 +713,7 @@ static void tc_signal_sigtimedwait(void) * Postconditions :none * @return :void */ -static void tc_signal_sighold_sigrelse(void) +static void tc_signal_sighold_sigrelse_pos(void) { sigset_t org_set; sigset_t hold_set; @@ -617,16 +754,24 @@ static void tc_signal_sighold_sigrelse(void) int signal_main(void) { - tc_signal_kill(); - tc_signal_nanosleep(); - tc_signal_pause(); - tc_signal_sig_pending_procmask_emptyset_addset(); - tc_signal_sigaction(); - tc_signal_sigqueue(); - tc_signal_sigsuspend(); - tc_signal_sigtimedwait(); - tc_signal_sigwaitinfo(); - tc_signal_sighold_sigrelse(); + tc_signal_kill_pos(); + tc_signal_kill_invalid_pid_neg(); + tc_signal_kill_invalid_signal_neg(); + tc_signal_nanosleep_neg(); + tc_signal_pause_pos(); + tc_signal_sig_pending_procmask_emptyset_addset_pos(); + tc_signal_sigaction_pos(); + tc_signal_sigaction_neg_signal_neg(); + tc_signal_sigaction_invalid_signals_neg(); + tc_signal_sigaction_null_action_neg(); + tc_signal_sigqueue_pos(); + tc_signal_sigqueue_neg(); + tc_signal_sigsuspend_pos(); + tc_signal_sigtimedwait_pos(); + tc_signal_sigwaitinfo_pos(); + tc_signal_sighold_sigrelse_pos(); + tc_signal_sigtimedwait_neg(); + return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_sysdbg.c b/apps/examples/testcase/le_tc/kernel/tc_sysdbg.c index 139b3e75f8..4e49c15b01 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_sysdbg.c +++ b/apps/examples/testcase/le_tc/kernel/tc_sysdbg.c @@ -40,7 +40,7 @@ * Postconditions :none * @return :void */ -static void tc_debug_sysdbg_test(void) +static void tc_debug_sysdbg_test_pos(void) { int ret; char buffer[BUFLEN]; @@ -72,13 +72,53 @@ static void tc_debug_sysdbg_test(void) TC_SUCCESS_RESULT(); } +static void tc_debug_sysdbg_test_neg(void) +{ + int ret; + char buffer[BUFLEN]; + char *ret_chk; + + int fd = open(SYSDBG_PATH, O_WRONLY); + TC_ASSERT_GEQ("open", fd, 0); + + ret_chk=strncpy(NULL, "enable_monitor", 14); + + TC_ASSERT_EQ_CLEANUP("strncpy", ret_chk, NULL, close(fd)); + + + close(fd); + TC_SUCCESS_RESULT(); +} + +static void tc_debug_sysdbg_test_buffer_overrun_neg(void) +{ + int ret; + char buffer[BUFLEN]; + char *ret_chk; + + int fd = open(SYSDBG_PATH, O_WRONLY); + TC_ASSERT_GEQ("open", fd, 0); + + ret_chk=strncpy(buffer, "enable_monitor", 40); + + TC_ASSERT_EQ_CLEANUP("strncpy", ret_chk, NULL, close(fd)); + + + close(fd); + TC_SUCCESS_RESULT(); +} + + + /**************************************************************************** * Name: debug_main ****************************************************************************/ int debug_main(void) { - tc_debug_sysdbg_test(); + tc_debug_sysdbg_test_pos(); + tc_debug_sysdbg_test_neg(); + tc_debug_sysdbg_test_buffer_overrun_neg(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_tash_stackmonitor.c b/apps/examples/testcase/le_tc/kernel/tc_tash_stackmonitor.c index c2e1cadcdd..8dc12e76ff 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_tash_stackmonitor.c +++ b/apps/examples/testcase/le_tc/kernel/tc_tash_stackmonitor.c @@ -47,7 +47,7 @@ static void *stkmon_thread(void *arg) return NULL; } -static int tc_tash_stackmonitor(int argc, char *args[]) +static int tc_tash_stackmonitor_pos(int argc, char *args[]) { int ret = ERROR; pthread_t tc_thread; @@ -77,7 +77,7 @@ static int tc_tash_stackmonitor(int argc, char *args[]) int tash_stackmonitor_main(void) { - tash_cmd_install("tc-stkmon", tc_tash_stackmonitor, TASH_EXECMD_SYNC); + tash_cmd_install("tc-stkmon", tc_tash_stackmonitor_pos, TASH_EXECMD_SYNC); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_task.c b/apps/examples/testcase/le_tc/kernel/tc_task.c index ef3bb706ce..e53dd01698 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_task.c +++ b/apps/examples/testcase/le_tc/kernel/tc_task.c @@ -205,7 +205,7 @@ static int test_task_entry(int argc, char *argv[]) * Postconditions :none * @return :void */ -static void tc_task_task_create(void) +static void tc_task_task_create_pos(void) { int pid; const char *task_param[2] = { TEST_STRING, NULL }; @@ -226,6 +226,22 @@ static void tc_task_task_create(void) TC_SUCCESS_RESULT(); } + +static void tc_task_task_create_invalid_priority_neg(void) +{ + int pid; + const char *task_param[2] = { TEST_STRING, NULL }; + g_callback = ERROR; + + /* Inavlid priority value check */ + + pid = task_create("tc_task_create", SCHED_PRIORITY_MIN - 1, 1024, create_task, (char * const *)task_param); + TC_ASSERT_EQ("task_create", pid, ERROR); + TC_ASSERT_EQ("task_create", errno, EINVAL); + + TC_SUCCESS_RESULT(); +} + /** * @fn :tc_task_task_delete * @brief :Delete a task @@ -235,7 +251,7 @@ static void tc_task_task_create(void) * Postconditions :none * @return :void */ -static void tc_task_task_delete(void) +static void tc_task_task_delete_pos(void) { int pid; int ret_chk; @@ -251,6 +267,7 @@ static void tc_task_task_delete(void) TC_SUCCESS_RESULT(); } + /** * @fn :tc_task_task_restart * @brief :Restart a task @@ -260,7 +277,7 @@ static void tc_task_task_delete(void) * Postconditions :none * @return :void */ -static void tc_task_task_restart(void) +static void tc_task_task_restart_pos(void) { int pid; int ret_chk; @@ -295,6 +312,27 @@ static void tc_task_task_restart(void) TC_SUCCESS_RESULT(); } +static void tc_task_task_restart_null_pid_neg(void) +{ + int pid; + int ret_chk; + + /* Check for NULL pid parameter */ + + pid = task_create("tc_task_re", SCHED_PRIORITY_MAX - 1, 1024, restart_task, (char * const *)NULL); + TC_ASSERT_GT("task_create", pid, 0); + + g_callback = 0; + ret_chk = task_restart(0); + TC_ASSERT_EQ("task_restart", ret_chk, ERROR); + TC_ASSERT_EQ("task_restart", errno, ENOSYS); + TC_ASSERT_EQ("task_restart", g_callback, 0); + g_callback = 0; + + + TC_SUCCESS_RESULT(); +} + /** * @fn :tc_task_exit * @brief :exit function will terminate the task @@ -305,7 +343,7 @@ static void tc_task_task_restart(void) * Postconditions :none * @return :void */ -static void tc_task_exit(void) +static void tc_task_exit_pos(void) { int pid; g_callback = ERROR; @@ -325,7 +363,7 @@ static void tc_task_exit(void) * Postconditions :none * @return :return SUCCESS on success */ -static void tc_task_atexit(void) +static void tc_task_atexit_pos(void) { int pid; g_callback = ERROR; @@ -348,7 +386,7 @@ static void tc_task_atexit(void) * Postconditions :none * @return :void */ -static void tc_task_on_exit(void) +static void tc_task_on_exit_pos(void) { int pid; g_callback = ERROR; @@ -371,10 +409,9 @@ static void tc_task_on_exit(void) * Postconditions :none * @return :void */ -static void tc_task_prctl(void) + +static void tc_task_prctl_invalid_option_neg(void) { - const char *setname = "a Test program"; - char getname[CONFIG_TASK_NAME_SIZE + 1]; char oldname[CONFIG_TASK_NAME_SIZE + 1]; int ret_chk; pid_t mypid = getpid(); @@ -385,18 +422,50 @@ static void tc_task_prctl(void) TC_ASSERT_EQ("prctl", ret_chk, ERROR); TC_ASSERT_EQ("prctl", get_errno(), EINVAL); + + TC_SUCCESS_RESULT(); +} +static void tc_task_prctl_invalid_process_neg(void) +{ + char oldname[CONFIG_TASK_NAME_SIZE + 1]; + int ret_chk; + pid_t mypid = getpid(); + /* no such process case */ ret_chk = prctl(PR_GET_NAME_BYPID, oldname, PID_INVALID); TC_ASSERT_EQ("prctl", ret_chk, ERROR); TC_ASSERT_EQ("prctl", get_errno(), ESRCH); + + + TC_SUCCESS_RESULT(); +} + +static void tc_task_prctl_null_name_neg(void) +{ + int ret_chk; + pid_t mypid = getpid(); + /* no name case */ ret_chk = prctl(PR_GET_NAME_BYPID, NULL, mypid); TC_ASSERT_EQ("prctl", ret_chk, ERROR); TC_ASSERT_EQ("prctl", get_errno(), EFAULT); + + TC_SUCCESS_RESULT(); +} + + + +static void tc_task_prctl_set_get_taskname_pos(void) +{ + const char *setname = "a Test program"; + char getname[CONFIG_TASK_NAME_SIZE + 1]; + char oldname[CONFIG_TASK_NAME_SIZE + 1]; + int ret_chk; + pid_t mypid = getpid(); /* save taskname */ ret_chk = prctl(PR_GET_NAME_BYPID, oldname, mypid); @@ -454,7 +523,7 @@ static void tc_task_prctl(void) * Postconditions :none * @return :void */ -static void tc_task_getpid(void) +static void tc_task_getpid_pos(void) { int pid; g_callback = ERROR; @@ -503,7 +572,7 @@ static int parent_task(int argc, char *argv[]) * Postconditions :none * @return :void */ -static void tc_task_task_reparent(void) +static void tc_task_task_reparent_pos(void) { int pid; @@ -528,7 +597,7 @@ static void tc_task_task_reparent(void) * Postconditions :none * @return :void */ -static void tc_task_task_init(void) +static void tc_task_task_init_pos(void) { int ret = 0; @@ -554,21 +623,26 @@ static void tc_task_task_init(void) int task_main(void) { #ifdef CONFIG_SCHED_ATEXIT - tc_task_atexit(); + tc_task_atexit_pos(); #endif - tc_task_exit(); - tc_task_getpid(); + tc_task_exit_pos(); + tc_task_getpid_pos(); #ifdef CONFIG_SCHED_ONEXIT - tc_task_on_exit(); + tc_task_on_exit_pos(); #endif - tc_task_prctl(); - tc_task_task_create(); - tc_task_task_delete(); - tc_task_task_restart(); + tc_task_prctl_set_get_taskname_pos(); + tc_task_prctl_invalid_option_neg(); + tc_task_prctl_invalid_process_neg(); + tc_task_prctl_null_name_neg(); + tc_task_task_create_pos(); + tc_task_task_create_invalid_priority_neg(); + tc_task_task_delete_pos(); + tc_task_task_restart_pos(); + tc_task_task_restart_null_pid_neg(); #ifdef CONFIG_SCHED_HAVE_PARENT - tc_task_task_reparent(); + tc_task_task_reparent_pos(); #endif - tc_task_task_init(); + tc_task_task_init_pos(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_timer.c b/apps/examples/testcase/le_tc/kernel/tc_timer.c index 07c09c5f77..99707c0058 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_timer.c +++ b/apps/examples/testcase/le_tc/kernel/tc_timer.c @@ -40,11 +40,10 @@ static int sig_no = SIGRTMIN; * Postconditions :none * @return :void */ -static void tc_timer_timer_create_delete(void) +static void tc_timer_timer_create_neg(void) { int ret_chk = 0; timer_t timer_id; - timer_t gtimer_id; clockid_t clockid; #ifdef CONFIG_CLOCK_MONOTONIC clockid = CLOCK_MONOTONIC; @@ -58,32 +57,145 @@ static void tc_timer_timer_create_delete(void) st_sigevent.sigev_notify = SIGEV_SIGNAL; st_sigevent.sigev_signo = sig_no; st_sigevent.sigev_value.sival_ptr = &timer_id; + + clockid = CLOCK_REALTIME; - /* Check for clock ID != CLOCK_REALTIME */ + /* Check for NULL timer ID */ -#ifdef CONFIG_CLOCK_MONOTONIC - ret_chk = timer_create(clockid, &st_sigevent, &timer_id); - TC_ASSERT_EQ("timer_create", ret_chk, ERROR); + ret_chk = timer_create(clockid, &st_sigevent, NULL); TC_ASSERT_EQ("timer_create", errno, EINVAL); + + ret_chk = timer_delete(NULL); + TC_ASSERT_EQ("timer_delete", errno, EINVAL); + TC_SUCCESS_RESULT(); + +} + +static void tc_timer_timer_create_null_signal_neg(void) +{ + int ret_chk = 0; + clockid_t clockid; +#ifdef CONFIG_CLOCK_MONOTONIC + clockid = CLOCK_MONOTONIC; +#endif + clockid = CLOCK_REALTIME; + /* Check for NULL timer ID */ + + ret_chk = timer_create(clockid, NULL, NULL); + TC_ASSERT_EQ_CLEANUP("timer_create", ret_chk, ERROR, timer_delete(NULL)); + + TC_SUCCESS_RESULT(); + +} + +static void tc_timer_timer_create_negclockid_neg(void) +{ + int ret_chk = 0; + timer_t timer_id; + clockid_t clockid; +#ifdef CONFIG_CLOCK_MONOTONIC + clockid = CLOCK_MONOTONIC; +#endif + struct sigevent st_sigevent; + struct posix_timer_s *st_ret_prt; + struct itimerspec st_timer_spec_val; + + /* Set and enable alarm */ + + st_sigevent.sigev_notify = SIGEV_SIGNAL; + st_sigevent.sigev_signo = sig_no; + st_sigevent.sigev_value.sival_ptr = &timer_id; + + /* Check for negative clock ID */ + clockid = -1; + + ret_chk = timer_create(clockid,&st_sigevent, &timer_id); + TC_ASSERT_EQ_CLEANUP("timer_create", errno, EINVAL, timer_delete(timer_id)); + + TC_SUCCESS_RESULT(); + +} + +static void tc_timer_timer_create_invalid_clockid_neg(void) +{ + int ret_chk = 0; + timer_t timer_id; + clockid_t clockid; +#ifdef CONFIG_CLOCK_MONOTONIC + clockid = CLOCK_MONOTONIC; #endif + struct sigevent st_sigevent; + struct posix_timer_s *st_ret_prt; + struct itimerspec st_timer_spec_val; + /* Set and enable alarm */ + + st_sigevent.sigev_notify = SIGEV_SIGNAL; + st_sigevent.sigev_signo = sig_no; + st_sigevent.sigev_value.sival_ptr = &timer_id; + + /* Check for invalid clockid clock ID */ + + ret_chk = timer_create(12345,&st_sigevent, &timer_id); + + TC_ASSERT_EQ_CLEANUP("timer_create", errno, EINVAL, timer_delete(timer_id)); + + TC_SUCCESS_RESULT(); + +} + +static void tc_timer_timer_create_invalid_signo_neg(void) +{ + int ret_chk = 0; + timer_t timer_id; + clockid_t clockid; +#ifdef CONFIG_CLOCK_MONOTONIC + clockid = CLOCK_MONOTONIC; +#endif + struct sigevent st_sigevent; + struct posix_timer_s *st_ret_prt; + struct itimerspec st_timer_spec_val; + + /* Set and enable alarm */ + + st_sigevent.sigev_notify = SIGEV_SIGNAL; + st_sigevent.sigev_signo = -1; + st_sigevent.sigev_value.sival_ptr = &timer_id; + + /* Check for invalid clockid clock ID */ clockid = CLOCK_REALTIME; - /* Check for NULL timer ID */ + ret_chk = timer_create(&clockid,&st_sigevent, &timer_id); - ret_chk = timer_create(clockid, &st_sigevent, NULL); - TC_ASSERT_EQ("timer_create", ret_chk, ERROR); - TC_ASSERT_EQ("timer_create", errno, EINVAL); + TC_ASSERT_EQ_CLEANUP("timer_create", errno, EINVAL, timer_delete(timer_id)); - /* Check for NULL timer ID */ + TC_SUCCESS_RESULT(); + +} - ret_chk = timer_delete(NULL); - TC_ASSERT_EQ("timer_delete", ret_chk, ERROR); - TC_ASSERT_EQ("timer_delete", errno, EINVAL); +static void tc_timer_timer_create_delete_pos (void) +{ + int ret_chk = 0; + timer_t timer_id; + clockid_t clockid; +#ifdef CONFIG_CLOCK_MONOTONIC + clockid = CLOCK_MONOTONIC; +#endif + struct sigevent st_sigevent; + struct posix_timer_s *st_ret_prt; + struct itimerspec st_timer_spec_val; + + /* Set and enable alarm */ + + st_sigevent.sigev_notify = SIGEV_SIGNAL; + st_sigevent.sigev_signo = sig_no; + st_sigevent.sigev_value.sival_ptr = &timer_id; + + /* Check for clock ID != CLOCK_REALTIME */ + clockid = CLOCK_REALTIME; ret_chk = timer_create(clockid, &st_sigevent, &timer_id); TC_ASSERT_NEQ("timer_create", ret_chk, ERROR); - TC_ASSERT_NEQ("timer_create", timer_id, NULL); 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, timer_delete(timer_id)); @@ -103,7 +215,34 @@ static void tc_timer_timer_create_delete(void) ret_chk = timer_delete(timer_id); TC_ASSERT_NEQ("timer_delete", ret_chk, ERROR); + TC_SUCCESS_RESULT(); + + +} + + + +static void tc_timer_timer_create_realtime_pos(void) +{ + int ret_chk = 0; + timer_t timer_id; + timer_t gtimer_id; + clockid_t clockid; +#ifdef CONFIG_CLOCK_MONOTONIC + clockid = CLOCK_MONOTONIC; +#endif + struct sigevent st_sigevent; + struct posix_timer_s *st_ret_prt; + struct itimerspec st_timer_spec_val; + + /* Set and enable alarm */ + st_sigevent.sigev_notify = SIGEV_SIGNAL; + st_sigevent.sigev_signo = sig_no; + st_sigevent.sigev_value.sival_ptr = &timer_id; + + clockid = CLOCK_REALTIME; + ret_chk = timer_create(CLOCK_REALTIME, NULL, >imer_id); TC_ASSERT_NEQ("timer_create", ret_chk, ERROR); @@ -119,6 +258,8 @@ static void tc_timer_timer_create_delete(void) TC_SUCCESS_RESULT(); } + + #endif /* CONFIG_BUILD_PROTECTED */ #ifndef CONFIG_DISABLE_POSIX_TIMERS @@ -132,7 +273,7 @@ static void tc_timer_timer_create_delete(void) * Postconditions :none * @return :void */ -static void tc_timer_timer_getoverrun(void) +static void tc_timer_timer_getoverrun_pos(void) { int ret_chk = 0; timer_t timer_id; @@ -149,17 +290,16 @@ static void tc_timer_timer_getoverrun(void) ret_chk = timer_create(clockid, &st_sigevent, &timer_id); TC_ASSERT_NEQ("timer_create", ret_chk, ERROR); - TC_ASSERT_NEQ("timer_create", timer_id, NULL); ret_chk = timer_getoverrun(timer_id); TC_ASSERT_EQ_CLEANUP("timer_getoverrun", ret_chk, ERROR, timer_delete(timer_id)); - TC_ASSERT_EQ_CLEANUP("timer_getoverrun", errno, ENOSYS, timer_delete(timer_id)); ret_chk = timer_delete(timer_id); TC_ASSERT_NEQ("timer_delete", ret_chk, ERROR); TC_SUCCESS_RESULT(); } + #endif /** @@ -171,13 +311,12 @@ static void tc_timer_timer_getoverrun(void) * Postconditions :none * @return :void */ -static void tc_timer_timer_set_get_time(void) +static void tc_timer_timer_set_time_null_id_neg(void) { int ret_chk = ERROR; clockid_t clockid = CLOCK_REALTIME; struct sigevent st_sigevent; struct itimerspec st_timer_spec_set; - struct itimerspec st_timer_spec_get; timer_t timer_id; /* Set and enable alarm */ @@ -198,43 +337,205 @@ static void tc_timer_timer_set_get_time(void) /* Null timer ID check for timer_settime */ ret_chk = timer_settime(NULL, 0, &st_timer_spec_set, NULL); - TC_ASSERT_EQ_CLEANUP("timer_settime", ret_chk, ERROR, timer_delete(timer_id)); - TC_ASSERT_EQ_CLEANUP("timer_settime", errno, EINVAL, timer_delete(timer_id)); + TC_ASSERT_EQ_CLEANUP("timer_settime", errno, EINVAL, timer_delete(NULL)); + TC_SUCCESS_RESULT(); +} - /* Null timer value check for timer_settime */ +static void tc_timer_timer_set_time_invalid_flag_neg(void) +{ + int ret_chk = ERROR; + clockid_t clockid = CLOCK_REALTIME; + struct sigevent st_sigevent; + struct itimerspec st_timer_spec_set; + timer_t timer_id; + int flag = -1; - ret_chk = timer_settime(timer_id, 0, NULL, NULL); - TC_ASSERT_EQ_CLEANUP("timer_settime", ret_chk, ERROR, timer_delete(timer_id)); - TC_ASSERT_EQ_CLEANUP("timer_settime", errno, EINVAL, timer_delete(timer_id)); + /* Set and enable alarm */ + + st_sigevent.sigev_notify = SIGEV_SIGNAL; + st_sigevent.sigev_signo = sig_no; + st_sigevent.sigev_value.sival_ptr = &timer_id; + ret_chk = timer_create(clockid, &st_sigevent, &timer_id); + TC_ASSERT_NEQ("timer_create", ret_chk, ERROR); + + st_timer_spec_set.it_interval.tv_sec = 1; + st_timer_spec_set.it_interval.tv_nsec = 0; /* interval; */ + st_timer_spec_set.it_value.tv_sec = 1; + st_timer_spec_set.it_value.tv_nsec = 0; /* expire; */ + /* Null it_value parameter check for timer_settime */ st_timer_spec_set.it_value.tv_sec = 0; - ret_chk = timer_settime(timer_id, 0, &st_timer_spec_set, NULL); + ret_chk = timer_settime(timer_id,flag, &st_timer_spec_set, NULL); TC_ASSERT_EQ_CLEANUP("timer_settime", ret_chk, OK, timer_delete(timer_id)); + timer_delete(timer_id); + TC_SUCCESS_RESULT(); +} + + +static void tc_timer_timer_set_time_pos(void) +{ + int ret_chk = ERROR; + clockid_t clockid = CLOCK_REALTIME; + struct sigevent st_sigevent; + struct itimerspec st_timer_spec_set; + struct itimerspec st_timer_spec_get; + timer_t timer_id; + + /* Set and enable alarm */ + + st_sigevent.sigev_notify = SIGEV_SIGNAL; + st_sigevent.sigev_signo = sig_no; + st_sigevent.sigev_value.sival_ptr = &timer_id; + + ret_chk = timer_create(clockid, &st_sigevent, &timer_id); + TC_ASSERT_NEQ("timer_create", ret_chk, ERROR); + st_timer_spec_set.it_interval.tv_sec = 1; + st_timer_spec_set.it_interval.tv_nsec = 0; /* interval; */ + st_timer_spec_set.it_value.tv_sec = 1; + st_timer_spec_set.it_value.tv_nsec = 0; /* expire; */ + /* Null it_value parameter check for timer_settime */ - st_timer_spec_set.it_value.tv_sec = -1; + st_timer_spec_set.it_value.tv_sec = 0; ret_chk = timer_settime(timer_id, 0, &st_timer_spec_set, NULL); TC_ASSERT_EQ_CLEANUP("timer_settime", ret_chk, OK, timer_delete(timer_id)); + //timer_delete(timer_id); + TC_SUCCESS_RESULT(); +} + +static void tc_timer_timer_set_time_null_timespec_neg(void) +{ + int ret_chk = ERROR; + clockid_t clockid = CLOCK_REALTIME; + struct sigevent st_sigevent; + struct itimerspec st_timer_spec_set; + timer_t timer_id; + + /* Set and enable alarm */ + + st_sigevent.sigev_notify = SIGEV_SIGNAL; + st_sigevent.sigev_signo = sig_no; + st_sigevent.sigev_value.sival_ptr = &timer_id; + + ret_chk = timer_create(clockid, &st_sigevent, &timer_id); + TC_ASSERT_NEQ("timer_create", ret_chk, ERROR); + TC_ASSERT_NEQ("timer_create", timer_id, NULL); + + st_timer_spec_set.it_interval.tv_sec = 1; + st_timer_spec_set.it_interval.tv_nsec = 0; /* interval; */ st_timer_spec_set.it_value.tv_sec = 1; + st_timer_spec_set.it_value.tv_nsec = 0; /* expire; */ + + + /* Null timer value check for timer_settime */ + + ret_chk = timer_settime(timer_id, 0, NULL, NULL); + TC_ASSERT_EQ_CLEANUP("timer_settime", errno, EINVAL, timer_delete(timer_id)); + + + + timer_delete(timer_id); + TC_SUCCESS_RESULT(); +} + +static void tc_timer_timer_set_abs_time_pos(void) +{ + int ret_chk = ERROR; + clockid_t clockid = CLOCK_REALTIME; + struct sigevent st_sigevent; + struct itimerspec st_timer_spec_set; + struct itimerspec st_timer_spec_get; + timer_t timer_id; + /* Set and enable alarm */ + + st_sigevent.sigev_notify = SIGEV_SIGNAL; + st_sigevent.sigev_signo = sig_no; + st_sigevent.sigev_value.sival_ptr = &timer_id; + + ret_chk = timer_create(clockid, &st_sigevent, &timer_id); + TC_ASSERT_NEQ("timer_create", ret_chk, ERROR); + TC_ASSERT_NEQ("timer_create", timer_id, NULL); + + st_timer_spec_set.it_interval.tv_sec = 1; + st_timer_spec_set.it_interval.tv_nsec = 0; /* interval; */ + st_timer_spec_set.it_value.tv_sec = 1; + st_timer_spec_set.it_value.tv_nsec = 0; /* expire; */ + /* Check if TIMER_ABSTIME (Flag = 1) is selected */ ret_chk = timer_settime(timer_id, 1, &st_timer_spec_set, NULL); TC_ASSERT_EQ_CLEANUP("timer_settime", ret_chk, OK, timer_delete(timer_id)); +// timer_delete(timer_id); + TC_SUCCESS_RESULT(); + +} - ret_chk = timer_settime(timer_id, 0, &st_timer_spec_set, NULL); /* Flag =1 :TIMER_ABSTIME */ - TC_ASSERT_EQ_ERROR_CLEANUP("timer_settime", ret_chk, OK, errno, timer_delete(timer_id)); +static void tc_timer_timer_set_abs_time_neg(void) +{ + int ret_chk = ERROR; + clockid_t clockid = CLOCK_REALTIME; + struct sigevent st_sigevent; + struct itimerspec st_timer_spec_set; + struct itimerspec st_timer_spec_get; + timer_t timer_id; - usleep(USECINT); + /* Set and enable alarm */ - /* Null timer ID check for timer_gettime */ + st_sigevent.sigev_notify = SIGEV_SIGNAL; + st_sigevent.sigev_signo = sig_no; + st_sigevent.sigev_value.sival_ptr = &timer_id; + + ret_chk = timer_create(clockid, &st_sigevent, &timer_id); + TC_ASSERT_NEQ("timer_create", ret_chk, ERROR); + TC_ASSERT_NEQ("timer_create", timer_id, NULL); + + st_timer_spec_set.it_interval.tv_sec = 1; + st_timer_spec_set.it_interval.tv_nsec = 0; /* interval; */ + st_timer_spec_set.it_value.tv_sec = 1; + st_timer_spec_set.it_value.tv_nsec = 0; /* expire; */ + + /* Check if TIMER_ABSTIME (Flag = 1) is selected */ + + ret_chk = timer_settime(timer_id, 0, &st_timer_spec_set, NULL); + TC_ASSERT_EQ_CLEANUP("timer_settime", ret_chk, OK, timer_delete(timer_id)); + timer_delete(timer_id); + TC_SUCCESS_RESULT(); + +} - ret_chk = timer_gettime(NULL, &st_timer_spec_get); - TC_ASSERT_EQ("timer_gettime", ret_chk, ERROR); - TC_ASSERT_EQ("timer_gettime", errno, EINVAL); + +static void tc_timer_timer_get_time_pos(void) +{ + int ret_chk = ERROR; + clockid_t clockid = CLOCK_REALTIME; + struct sigevent st_sigevent; + struct itimerspec st_timer_spec_set; + struct itimerspec st_timer_spec_get; + timer_t timer_id; + + /* Set and enable alarm */ + + st_sigevent.sigev_notify = SIGEV_SIGNAL; + st_sigevent.sigev_signo = sig_no; + st_sigevent.sigev_value.sival_ptr = &timer_id; + + ret_chk = timer_create(clockid, &st_sigevent, &timer_id); + TC_ASSERT_NEQ("timer_create", ret_chk, ERROR); + TC_ASSERT_NEQ("timer_create", timer_id, NULL); + + st_timer_spec_set.it_interval.tv_sec = 1; + st_timer_spec_set.it_interval.tv_nsec = 0; /* interval; */ + st_timer_spec_set.it_value.tv_sec = 1; + st_timer_spec_set.it_value.tv_nsec = -1; /* expire; */ + + /* Check if TIMER_ABSTIME (Flag = 1) is selected */ + + ret_chk = timer_settime(timer_id, 1, &st_timer_spec_set, NULL); + TC_ASSERT_NEQ("timer_settime", ret_chk, ERROR); ret_chk = timer_gettime(timer_id, &st_timer_spec_get); TC_ASSERT_EQ_ERROR_CLEANUP("timer_gettime", ret_chk, OK, errno, timer_delete(timer_id)); @@ -247,6 +548,46 @@ static void tc_timer_timer_set_get_time(void) TC_SUCCESS_RESULT(); } +static void tc_timer_timer_set_get_time_neg(void) +{ + int ret_chk = ERROR; + clockid_t clockid = CLOCK_REALTIME; + struct sigevent st_sigevent; + struct itimerspec st_timer_spec_set; + struct itimerspec st_timer_spec_get; + timer_t timer_id; + + /* Set and enable alarm */ + + st_sigevent.sigev_notify = SIGEV_SIGNAL; + st_sigevent.sigev_signo = sig_no; + st_sigevent.sigev_value.sival_ptr = &timer_id; + + ret_chk = timer_create(clockid, &st_sigevent, &timer_id); + TC_ASSERT_NEQ("timer_create", ret_chk, ERROR); + TC_ASSERT_NEQ("timer_create", timer_id, NULL); + + st_timer_spec_set.it_interval.tv_sec = 1; + st_timer_spec_set.it_interval.tv_nsec = 0; /* interval; */ + st_timer_spec_set.it_value.tv_sec = 1; + st_timer_spec_set.it_value.tv_nsec = 0; /* expire; */ + + + /* Check if TIMER_ABSTIME (Flag = 1) is selected */ + + ret_chk = timer_settime(timer_id, 1, &st_timer_spec_set, NULL); + TC_ASSERT_NEQ("timer_settime", ret_chk, ERROR); + /* Null timer ID check for timer_gettime */ + + ret_chk = timer_gettime(NULL, &st_timer_spec_get); + TC_ASSERT_EQ("timer_gettime", ret_chk, ERROR); + TC_ASSERT_EQ("timer_gettime", errno, EINVAL); + + TC_ASSERT_EQ_ERROR_CLEANUP("timer_gettime", ret_chk, OK, errno, timer_delete(timer_id)); + + TC_SUCCESS_RESULT(); +} + /** * @fn :tc_timer_timer_initialize * @brief :Boot up configuration of the POSIX timer facility. @@ -256,7 +597,7 @@ static void tc_timer_timer_set_get_time(void) * Postconditions :none * @return :void */ -static void tc_timer_timer_initialize(void) +static void tc_timer_timer_initialize_pos(void) { int fd; int ret_chk; @@ -275,14 +616,24 @@ static void tc_timer_timer_initialize(void) int timer_tc_main(void) { #ifndef CONFIG_BUILD_PROTECTED - tc_timer_timer_create_delete(); + tc_timer_timer_create_neg(); + tc_timer_timer_create_delete_pos (); + tc_timer_timer_create_null_signal_neg(); + tc_timer_timer_create_invalid_clockid_neg(); + tc_timer_timer_create_negclockid_neg(); + tc_timer_timer_create_invalid_signo_neg(); #endif #ifndef CONFIG_DISABLE_POSIX_TIMERS - tc_timer_timer_getoverrun(); + tc_timer_timer_getoverrun_pos(); #endif /* CONFIG_DISABLE_POSIX_TIMERS */ - tc_timer_timer_set_get_time(); - tc_timer_timer_initialize(); + tc_timer_timer_set_time_pos(); + tc_timer_timer_set_time_null_id_neg(); + tc_timer_timer_set_time_invalid_flag_neg(); + + tc_timer_timer_set_abs_time_neg(); + tc_timer_timer_set_abs_time_pos(); + tc_timer_timer_initialize_pos(); return 0; } diff --git a/apps/examples/testcase/le_tc/kernel/tc_umm_heap.c b/apps/examples/testcase/le_tc/kernel/tc_umm_heap.c index e120a29935..4321e3ebfe 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_umm_heap.c +++ b/apps/examples/testcase/le_tc/kernel/tc_umm_heap.c @@ -69,7 +69,7 @@ static void mem_deallocate_func(int *mem_arr[], int dealloc_size) * @Preconditions :NA */ -static void tc_umm_heap_malloc_free(void) +static void tc_umm_heap_malloc_free_pos(void) { int *mem_ptr[ALLOC_FREE_TIMES] = { NULL }; int n_alloc; @@ -135,7 +135,7 @@ static void tc_umm_heap_malloc_free(void) * @failcase :When calloc function returns null memory. * @Preconditions :NA */ -static void tc_umm_heap_calloc(void) +static void tc_umm_heap_calloc_pos(void) { int *mem_ptr[ALLOC_FREE_TIMES] = { NULL }; int n_alloc; @@ -189,7 +189,7 @@ static void tc_umm_heap_calloc(void) * @failcase :When realloc function returns null memory. * @Preconditions :malloc */ -static void tc_umm_heap_realloc(void) +static void tc_umm_heap_realloc_pos(void) { int *mem_ptr[ALLOC_FREE_TIMES] = { NULL }; int *prev_mem = NULL; @@ -320,7 +320,7 @@ static void tc_umm_heap_realloc(void) * @failcase :When memalign function returns null memory. * @Preconditions :NA */ -static void tc_umm_heap_memalign(void) +static void tc_umm_heap_memalign_pos(void) { int *mem_ptr[ALLOC_FREE_TIMES] = { NULL }; int n_alloc; @@ -374,7 +374,7 @@ static void tc_umm_heap_memalign(void) * @failcase :When malloc function returns null memory or mallinfo gives null information. * @Preconditions :malloc */ -static void tc_umm_heap_mallinfo(void) +static void tc_umm_heap_mallinfo_pos(void) { int *mem_ptr = NULL; int n_test_iter; @@ -422,7 +422,7 @@ static void tc_umm_heap_mallinfo(void) TC_SUCCESS_RESULT(); } -static void tc_umm_heap_zalloc(void) +static void tc_umm_heap_zalloc_pos(void) { int *mem_ptr[ALLOC_FREE_TIMES] = { NULL }; int n_alloc; @@ -472,7 +472,7 @@ static void tc_umm_heap_zalloc(void) TC_SUCCESS_RESULT(); } #ifdef CONFIG_DEBUG_MM_HEAPINFO -static void tc_umm_heap_get_heap_free_size(void) +static void tc_umm_heap_get_heap_free_size_pos(void) { size_t free_size = umm_get_heap_free_size(); struct mallinfo info; @@ -487,7 +487,7 @@ static void tc_umm_heap_get_heap_free_size(void) TC_SUCCESS_RESULT(); } -static void tc_umm_heap_get_largest_freenode_size(void) +static void tc_umm_heap_get_largest_freenode_size_pos(void) { size_t largest_size = umm_get_largest_freenode_size(); struct mallinfo info; @@ -506,15 +506,15 @@ static int umm_test(int argc, char *argv[]) { sched_lock(); // To prevent other thread allocation mixing in mallinfo - tc_umm_heap_malloc_free(); - tc_umm_heap_calloc(); - tc_umm_heap_realloc(); - tc_umm_heap_memalign(); - tc_umm_heap_mallinfo(); - tc_umm_heap_zalloc(); + tc_umm_heap_malloc_free_pos(); + tc_umm_heap_calloc_pos(); + tc_umm_heap_realloc_pos(); + tc_umm_heap_memalign_pos(); + tc_umm_heap_mallinfo_pos(); + tc_umm_heap_zalloc_pos(); #ifdef CONFIG_DEBUG_MM_HEAPINFO - tc_umm_heap_get_heap_free_size(); - tc_umm_heap_get_largest_freenode_size(); + tc_umm_heap_get_heap_free_size_pos(); + tc_umm_heap_get_largest_freenode_size_pos(); #endif sched_unlock(); diff --git a/apps/examples/testcase/le_tc/kernel/tc_wqueue.c b/apps/examples/testcase/le_tc/kernel/tc_wqueue.c index 39ab56e033..c5847b1ef9 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_wqueue.c +++ b/apps/examples/testcase/le_tc/kernel/tc_wqueue.c @@ -68,7 +68,7 @@ static void wq_test3(void *arg) * Public Functions **************************************************************************/ #if defined(CONFIG_SCHED_HPWORK) || defined(CONFIG_SCHED_LPWORK) -static void tc_wqueue_work_queue_cancel(void) +static void tc_wqueue_work_queue_cancel_pos(void) { int result; struct work_s *test_work1; @@ -114,7 +114,7 @@ static void tc_wqueue_work_queue_cancel(void) int wqueue_main(void) { #if defined(CONFIG_SCHED_HPWORK) || defined(CONFIG_SCHED_LPWORK) - tc_wqueue_work_queue_cancel(); + tc_wqueue_work_queue_cancel_pos(); #endif return 0; }