diff --git a/components/shell/src/cmds/task_shellcmd.c b/components/shell/src/cmds/task_shellcmd.c index 79768eb5..08c20488 100755 --- a/components/shell/src/cmds/task_shellcmd.c +++ b/components/shell/src/cmds/task_shellcmd.c @@ -39,27 +39,6 @@ #define OS_INVALID_SEM_ID 0xFFFFFFFF #define OS_ALL_TASK_MASK 0xFFFFFFFF -LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellCmdConvertTskStatus(UINT16 taskStatus) -{ - if (taskStatus & OS_TASK_STATUS_RUNNING) { - return (UINT8 *)"Running"; - } else if (taskStatus & OS_TASK_STATUS_READY) { - return (UINT8 *)"Ready"; - } else { - if (taskStatus & OS_TASK_STATUS_DELAY) { - return (UINT8 *)"Delay"; - } else if (taskStatus & OS_TASK_STATUS_PEND_TIME) { - return (UINT8 *)"PendTime"; - } else if (taskStatus & OS_TASK_STATUS_PEND) { - return (UINT8 *)"Pend"; - } else if (taskStatus & OS_TASK_STATUS_SUSPEND) { - return (UINT8 *)"Suspend"; - } - } - - return (UINT8 *)"Invalid"; -} - LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoTitle(VOID) { PRINTK("Name TaskEntryAddr TID "); @@ -119,11 +98,11 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoData(const LosTaskCB *allTas PRINTK("%-23s%-20p0x%-5x", taskCB->taskName, taskCB->taskEntry, taskCB->taskID); #if (LOSCFG_TASK_MEM_USED == 1) PRINTK("%-11u%-13s0x%-11x 0x%-11x 0x%-8x 0x%-10x ", taskCB->priority, - OsShellCmdConvertTskStatus(taskCB->taskStatus), getUsedSizeArray[loop], taskCB->stackSize, + OsConvertTskStatus(taskCB->taskStatus), getUsedSizeArray[loop], taskCB->stackSize, taskCB->stackPointer, taskCB->topOfStack, semId); #else PRINTK("%-11u%-13s0x%-11x 0x%-8x 0x%-10x ", taskCB->priority, - OsShellCmdConvertTskStatus(taskCB->taskStatus), taskCB->stackSize, + OsConvertTskStatus(taskCB->taskStatus), taskCB->stackSize, taskCB->stackPointer, taskCB->topOfStack, semId); #endif PRINTK("\n"); diff --git a/kal/cmsis/cmsis_liteos2.c b/kal/cmsis/cmsis_liteos2.c index 19f11903..5d762cbd 100644 --- a/kal/cmsis/cmsis_liteos2.c +++ b/kal/cmsis/cmsis_liteos2.c @@ -299,7 +299,9 @@ osThreadId_t osThreadNew(osThreadFunc_t func, void *argument, const osThreadAttr stTskInitParam.uwStackSize = attr ? attr->stack_size : LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; stTskInitParam.pcName = (CHAR *)(attr ? attr->name : "[NULL]"); stTskInitParam.usTaskPrio = usPriority; - + if (attr->attr_bits == osThreadJoinable) { + stTskInitParam.uwResved = LOS_TASK_ATTR_JOINABLE; + } uwRet = LOS_TaskCreate(&uwTid, &stTskInitParam); if (LOS_OK != uwRet) { @@ -576,6 +578,46 @@ osStatus_t osThreadResume(osThreadId_t thread_id) } +osStatus_t osThreadDetach(osThreadId_t thread_id) +{ + UINT32 ret; + LosTaskCB *taskCB = (LosTaskCB *)thread_id; + + if (thread_id == NULL) { + return osErrorParameter; + } + + ret = LOS_TaskDetach(taskCB->taskID); + if (ret == LOS_ERRNO_TSK_NOT_ALLOW_IN_INT) { + return osErrorISR; + } else if (ret != LOS_OK) { + return osErrorResource; + } + + return osOK; +} + + +osStatus_t osThreadJoin(osThreadId_t thread_id) +{ + UINT32 ret; + LosTaskCB *taskCB = (LosTaskCB *)thread_id; + + if (thread_id == NULL) { + return osErrorParameter; + } + + ret = LOS_TaskJoin(taskCB->taskID, NULL); + if (ret == LOS_ERRNO_TSK_NOT_ALLOW_IN_INT) { + return osErrorISR; + } else if (ret != LOS_OK) { + return osErrorResource; + } + + return osOK; +} + + osStatus_t osThreadTerminate(osThreadId_t thread_id) { UINT32 uwRet; diff --git a/kal/posix/src/pthread.c b/kal/posix/src/pthread.c index d87d773e..e1263921 100644 --- a/kal/posix/src/pthread.c +++ b/kal/posix/src/pthread.c @@ -75,9 +75,6 @@ static int PthreadCreateAttrInit(const pthread_attr_t *attr, void *(*startRoutin threadAttr = &attrTmp; } - if (threadAttr->detachstate == PTHREAD_CREATE_DETACHED) { - return ENOTSUP; - } if (threadAttr->stackaddr_set != 0) { return ENOTSUP; } @@ -100,12 +97,14 @@ static int PthreadCreateAttrInit(const pthread_attr_t *attr, void *(*startRoutin return ENOMEM; } - pthreadData->startRoutine = startRoutine; - pthreadData->param = arg; + pthreadData->startRoutine = startRoutine; + pthreadData->param = arg; taskInitParam->pcName = pthreadData->name; taskInitParam->pfnTaskEntry = PthreadEntry; taskInitParam->uwArg = (UINT32)(UINTPTR)pthreadData; - + if (threadAttr->detachstate != PTHREAD_CREATE_DETACHED) { + taskInitParam->uwResved = LOS_TASK_ATTR_JOINABLE; + } return 0; } @@ -192,43 +191,38 @@ int pthread_cancel(pthread_t thread) int pthread_join(pthread_t thread, void **retval) { - UINT32 taskStatus; - - if (!IsPthread(thread)) { + UINTPTR result; + UINT32 ret = LOS_TaskJoin((UINT32)thread, &result); + if (ret == LOS_ERRNO_TSK_NOT_JOIN_SELF) { + return EDEADLK; + } else if (ret != LOS_OK) { return EINVAL; } - if (retval) { - /* retrieve thread exit code is not supported currently */ - return ENOTSUP; + if (retval != NULL) { + *retval = (VOID *)result; } - - if (thread == pthread_self()) { - return EDEADLK; - } - - while (LOS_TaskStatusGet((UINT32)thread, &taskStatus) == LOS_OK) { - (void)LOS_TaskDelay(10); /* 10: Waiting for the end of thread execution. */ - } - return 0; } int pthread_detach(pthread_t thread) { - if (!IsPthread(thread)) { + UINT32 ret = LOS_TaskDetach((UINT32)thread); + if (ret == LOS_ERRNO_TSK_NOT_JOIN) { + return ESRCH; + } else if (ret != LOS_OK) { return EINVAL; } - return ENOSYS; + return 0; } void pthread_exit(void *retVal) { - (void)retVal; LosTaskCB *tcb = OS_TCB_FROM_TID(LOS_CurTaskIDGet()); + tcb->joinRetval = (UINTPTR)retVal; free((PthreadData *)(UINTPTR)tcb->arg); - (void)LOS_TaskDelete(LOS_CurTaskIDGet()); + (void)LOS_TaskDelete(tcb->taskID); } int pthread_setname_np(pthread_t thread, const char *name) diff --git a/kernel/include/los_task.h b/kernel/include/los_task.h index 0e587535..20c910b3 100644 --- a/kernel/include/los_task.h +++ b/kernel/include/los_task.h @@ -369,8 +369,66 @@ extern "C" { */ #define LOS_ERRNO_TSK_OPERATE_SWTMR LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x22) +/** + * @ingroup los_task + * Task error code: Task timeout. + * + * Value: 0x02000223 + * + * Solution: Check whether the waiting time and timeout are reasonable. + */ #define LOS_ERRNO_TSK_TIMEOUT LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x23) +/** + * @ingroup los_task + * Task error code: This task cannot wait for other tasks to finish. + * + * Value: 0x02000224 + * + * Solution: Check the task properties and whether it is waiting for other tasks to finish. + */ +#define LOS_ERRNO_TSK_NOT_JOIN LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x24) + +/** + * @ingroup los_task + * Task error code: Tasks can't join himself. + * + * Value: 0x02000225 + * + * Solution: Check whether the task ID is the current running task. + */ +#define LOS_ERRNO_TSK_NOT_JOIN_SELF LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x25) + +/** + * @ingroup los_task + * Task error code: This task operation is not allowed to be performed in an interrupt. + * + * Value: 0x02000226 + * + * Solution: Check whether the interface is used in interrupts. + */ +#define LOS_ERRNO_TSK_NOT_ALLOW_IN_INT LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x26) + +/** + * @ingroup los_task + * Task error code: An exited task cannot be deleted. + * + * Value: 0x02000227 + * + * Solution: Check whether a Joinable task exists. If so, call LOS_TaskJoin to reclaim resources. + */ +#define LOS_ERRNO_TSK_ALREADY_EXIT LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x27) + +/** + * @ingroup los_task + * Task error code: Locked scheduling does not allow tasks to be blocked. + * + * Value: 0x02000228 + * + * Solution: Check for faulty lock scheduling logic. + */ +#define LOS_ERRNO_TSK_SCHED_LOCKED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x28) + /** * @ingroup los_task * Define the type of the task entry function. @@ -393,17 +451,21 @@ typedef struct tagTskInitParam { UINT32 uwResved; /**< Reserved */ } TSK_INIT_PARAM_S; +/** + * @ingroup los_task + * Task detach attribute. + */ +#define LOS_TASK_ATTR_JOINABLE 0x80000000 + /** * @ingroup los_task * Task name length - * */ #define LOS_TASK_NAMELEN 32 /** * @ingroup los_task * Task information structure. - * */ typedef struct tagTskInfo { CHAR acName[LOS_TASK_NAMELEN]; /**< Task entrance function */ @@ -1088,6 +1150,45 @@ extern CHAR* LOS_TaskNameGet(UINT32 taskID); */ extern VOID LOS_UDelay(UINT64 microseconds); +/* * + * @ingroup los_task + * @brief: cpu delay. + * + * @par Description: + * This API is used to wait for the subtask to finish and reclaim the resource. + * + * @attention: + * + * + * @param taskID [IN] task ID. + * @param retval [IN] Value returned when the task is complete. + * + * @retval: None. + * @par Dependency: + * + * @see LOS_TaskDetach. + */ +extern UINT32 LOS_TaskJoin(UINT32 taskID, UINTPTR *retval); + +/* * + * @ingroup los_task + * @brief: Modify the task attributes to detach. + * + * @par Description: + * This API is used to modify the attribute of the specified task to detach. + * + * @attention: + * + * + * @param taskID [IN] task ID. + * + * @retval: None. + * @par Dependency: + * + * @see LOS_TaskJoin. + */ +extern UINT32 LOS_TaskDetach(UINT32 taskID); + /** * @ingroup los_task * Null task ID @@ -1175,6 +1276,14 @@ extern VOID LOS_UDelay(UINT64 microseconds); */ #define OS_TASK_STATUS_PEND_TIME 0x0080 +/** + * @ingroup los_task + * Flag that indicates the task or task control block status. + * + * The task exits and waits for the parent thread to reclaim the resource. + */ +#define OS_TASK_STATUS_EXIT 0x0100 + /** * @ingroup los_task * Flag that indicates the task or task control block status. @@ -1185,11 +1294,12 @@ extern VOID LOS_UDelay(UINT64 microseconds); /** * @ingroup los_task - * Flag that indicates the task is in userspace. + * Flag that indicates the task or task control block status. * - * The task is a user task. + * Task join properties, The parent thread needs to reclaim + * the resource after the task ends. */ -#define OS_TASK_STATUS_USERSPACE 0x8000 +#define OS_TASK_FLAG_JOINABLE 0x8000 /** * @ingroup los_task @@ -1354,6 +1464,8 @@ typedef struct { CHAR *taskName; /**< Task name */ LOS_DL_LIST pendList; LOS_DL_LIST timerList; + LOS_DL_LIST joinList; + UINTPTR joinRetval; /**< Return value of the end of the task, If the task does not exit by itself, the ID of the task that killed the task is recorded. */ EVENT_CB_S event; UINT32 eventMask; /**< Event mask */ UINT32 eventMode; /**< Event mode */ diff --git a/kernel/src/los_sched.c b/kernel/src/los_sched.c index b0d72d6d..f97fa929 100644 --- a/kernel/src/los_sched.c +++ b/kernel/src/los_sched.c @@ -50,6 +50,9 @@ extern "C" { #error "Must specify the maximum value that tick timer counter supports!" #endif +#define OS_TASK_BLOCKED_STATUS (OS_TASK_STATUS_PEND | OS_TASK_STATUS_SUSPEND | \ + OS_TASK_STATUS_EXIT | OS_TASK_STATUS_UNUSED) + STATIC SchedScan g_swtmrScan = NULL; STATIC SortLinkAttribute *g_taskSortLinkList = NULL; STATIC LOS_DL_LIST g_priQueueList[OS_PRIORITY_QUEUE_NUM]; @@ -511,7 +514,7 @@ BOOL OsSchedTaskSwitch(VOID) if (runTask->taskStatus & (OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_DELAY)) { OsAdd2SortLink(&runTask->sortList, runTask->startTime, runTask->waitTimes, OS_SORT_LINK_TASK); - } else if (!(runTask->taskStatus & (OS_TASK_STATUS_PEND | OS_TASK_STATUS_SUSPEND | OS_TASK_STATUS_UNUSED))) { + } else if (!(runTask->taskStatus & OS_TASK_BLOCKED_STATUS)) { OsSchedTaskEnQueue(runTask); } diff --git a/kernel/src/los_task.c b/kernel/src/los_task.c index 33437640..ea1401a2 100644 --- a/kernel/src/los_task.c +++ b/kernel/src/los_task.c @@ -123,6 +123,22 @@ STATIC_INLINE UINT32 OsCheckTaskIDValid(UINT32 taskID) return ret; } +STATIC VOID OsRecycleTaskResources(LosTaskCB *taskCB, UINTPTR *stackPtr) +{ + if (!(taskCB->taskStatus & OS_TASK_STATUS_EXIT)) { + LOS_ListAdd(&g_losFreeTask, &taskCB->pendList); + taskCB->taskStatus = OS_TASK_STATUS_UNUSED; + } + if (taskCB->topOfStack != 0) { +#if (LOSCFG_EXC_HARDWARE_STACK_PROTECTION == 1) + *stackPtr = taskCB->topOfStack - OS_TASK_STACK_PROTECT_SIZE; +#else + *stackPtr = taskCB->topOfStack; +#endif + taskCB->topOfStack = (UINT32)NULL; + } +} + STATIC VOID OsRecyleFinishedTask(VOID) { LosTaskCB *taskCB = NULL; @@ -133,14 +149,12 @@ STATIC VOID OsRecyleFinishedTask(VOID) while (!LOS_ListEmpty(&g_taskRecyleList)) { taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&g_taskRecyleList)); LOS_ListDelete(LOS_DL_LIST_FIRST(&g_taskRecyleList)); - LOS_ListAdd(&g_losFreeTask, &taskCB->pendList); -#if (LOSCFG_EXC_HARDWARE_STACK_PROTECTION == 1) - stackPtr = taskCB->topOfStack - OS_TASK_STACK_PROTECT_SIZE; -#else - stackPtr = taskCB->topOfStack; -#endif + stackPtr = 0; + OsRecycleTaskResources(taskCB, &stackPtr); + LOS_IntRestore(intSave); + (VOID)LOS_MemFree(OS_TASK_STACK_ADDR, (VOID *)stackPtr); - taskCB->topOfStack = (UINT32)NULL; + intSave = LOS_IntLock(); } LOS_IntRestore(intSave); } @@ -188,6 +202,10 @@ LITE_OS_SEC_TEXT_MINOR UINT8 *OsConvertTskStatus(UINT16 taskStatus) return (UINT8 *)"Running"; } else if (taskStatus & OS_TASK_STATUS_READY) { return (UINT8 *)"Ready"; + } else if (taskStatus & OS_TASK_STATUS_EXIT) { + return (UINT8 *)"Exit"; + } else if (taskStatus & OS_TASK_STATUS_SUSPEND) { + return (UINT8 *)"Suspend"; } else if (taskStatus & OS_TASK_STATUS_DELAY) { return (UINT8 *)"Delay"; } else if (taskStatus & OS_TASK_STATUS_PEND) { @@ -195,8 +213,6 @@ LITE_OS_SEC_TEXT_MINOR UINT8 *OsConvertTskStatus(UINT16 taskStatus) return (UINT8 *)"PendTime"; } return (UINT8 *)"Pend"; - } else if (taskStatus & OS_TASK_STATUS_SUSPEND) { - return (UINT8 *)"Suspend"; } return (UINT8 *)"Impossible"; @@ -606,8 +622,7 @@ LITE_OS_SEC_TEXT_INIT VOID OsTaskEntry(UINT32 taskID) UINT32 retVal; LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID); - (VOID)taskCB->taskEntry(taskCB->arg); - + taskCB->joinRetval = (UINTPTR)taskCB->taskEntry(taskCB->arg); retVal = LOS_TaskDelete(taskCB->taskID); if (retVal != LOS_OK) { PRINT_ERR("Delete Task[TID: %d] Failed!\n", taskCB->taskID); @@ -671,6 +686,11 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsNewTaskInit(LosTaskCB *taskCB, TSK_INIT_PARAM_S * taskCB->stackPointer = HalTskStackInit(taskCB->taskID, taskInitParam->uwStackSize, topOfStack); SET_SORTLIST_VALUE(&taskCB->sortList, OS_SORT_LINK_INVALID_TIME); LOS_EventInit(&(taskCB->event)); + + if (taskInitParam->uwResved & LOS_TASK_ATTR_JOINABLE) { + taskCB->taskStatus |= OS_TASK_FLAG_JOINABLE; + LOS_ListInit(&taskCB->joinList); + } return LOS_OK; } @@ -892,6 +912,124 @@ LOS_ERREND: return retErr; } +STATIC VOID OsTaskJoinPostUnsafe(LosTaskCB *taskCB) +{ + LosTaskCB *resumedTask = NULL; + + if (taskCB->taskStatus & OS_TASK_FLAG_JOINABLE) { + if (!LOS_ListEmpty(&taskCB->joinList)) { + resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(taskCB->joinList))); + OsSchedTaskWake(resumedTask); + } + taskCB->taskStatus |= OS_TASK_STATUS_EXIT; + } +} + +STATIC UINT32 OsTaskJoinPendUnsafe(LosTaskCB *taskCB) +{ + if (taskCB->taskStatus & OS_TASK_STATUS_EXIT) { + return LOS_OK; + } else if ((taskCB->taskStatus & OS_TASK_FLAG_JOINABLE) && LOS_ListEmpty(&taskCB->joinList)) { + OsSchedTaskWait(&taskCB->joinList, LOS_WAIT_FOREVER); + return LOS_OK; + } + + return LOS_NOK; +} + +STATIC UINT32 OsTaskSetDetachUnsafe(LosTaskCB *taskCB) +{ + if (taskCB->taskStatus & OS_TASK_FLAG_JOINABLE) { + if (LOS_ListEmpty(&(taskCB->joinList))) { + LOS_ListDelete(&(taskCB->joinList)); + taskCB->taskStatus &= ~OS_TASK_FLAG_JOINABLE; + return LOS_OK; + } + /* This error code has a special purpose and is not allowed to appear again on the interface */ + return LOS_ERRNO_TSK_NOT_JOIN; + } + + return LOS_NOK; +} + +LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskJoin(UINT32 taskID, UINTPTR *retval) +{ + LosTaskCB *taskCB = NULL; + UINTPTR stackPtr = 0; + UINT32 intSave; + UINT32 ret; + + ret = OsCheckTaskIDValid(taskID); + if (ret != LOS_OK) { + return ret; + } + + if (OS_INT_ACTIVE) { + return LOS_ERRNO_TSK_NOT_ALLOW_IN_INT; + } + + if (g_losTaskLock != 0) { + return LOS_ERRNO_TSK_SCHED_LOCKED; + } + + if (taskID == LOS_CurTaskIDGet()) { + return LOS_ERRNO_TSK_NOT_JOIN_SELF; + } + + taskCB = OS_TCB_FROM_TID(taskID); + intSave = LOS_IntLock(); + if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { + LOS_IntRestore(intSave); + return LOS_ERRNO_TSK_NOT_CREATED; + } + + ret = OsTaskJoinPendUnsafe(taskCB); + LOS_IntRestore(intSave); + if (ret == LOS_OK) { + LOS_Schedule(); + + if (retval != NULL) { + *retval = taskCB->joinRetval; + } + + intSave = LOS_IntLock(); + taskCB->taskStatus &= ~OS_TASK_STATUS_EXIT; + OsRecycleTaskResources(taskCB, &stackPtr); + LOS_IntRestore(intSave); + (VOID)LOS_MemFree(OS_TASK_STACK_ADDR, (VOID *)stackPtr); + return LOS_OK; + } + + return ret; +} + +LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDetach(UINT32 taskID) +{ + UINT32 intSave; + UINT32 ret; + LosTaskCB *taskCB = NULL; + + ret = OsCheckTaskIDValid(taskID); + if (ret != LOS_OK) { + return ret; + } + + if (OS_INT_ACTIVE) { + return LOS_ERRNO_TSK_NOT_ALLOW_IN_INT; + } + + taskCB = OS_TCB_FROM_TID(taskID); + intSave = LOS_IntLock(); + if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { + LOS_IntRestore(intSave); + return LOS_ERRNO_TSK_NOT_CREATED; + } + + ret = OsTaskSetDetachUnsafe(taskCB); + LOS_IntRestore(intSave); + return ret; +} + LITE_OS_SEC_TEXT_INIT STATIC_INLINE VOID OsRunningTaskDelete(UINT32 taskID, LosTaskCB *taskCB) { LOS_ListTailInsert(&g_taskRecyleList, &taskCB->pendList); @@ -911,21 +1049,27 @@ LITE_OS_SEC_TEXT_INIT STATIC_INLINE VOID OsRunningTaskDelete(UINT32 taskID, LosT LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID) { UINT32 intSave; - LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID); - UINTPTR stackPtr; + UINTPTR stackPtr = 0; + LosTaskCB *taskCB = NULL; UINT32 ret = OsCheckTaskIDValid(taskID); if (ret != LOS_OK) { return ret; } + taskCB = OS_TCB_FROM_TID(taskID); intSave = LOS_IntLock(); - if ((taskCB->taskStatus) & OS_TASK_STATUS_UNUSED) { + if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { LOS_IntRestore(intSave); return LOS_ERRNO_TSK_NOT_CREATED; } + if (taskCB->taskStatus & OS_TASK_STATUS_EXIT) { + LOS_IntRestore(intSave); + return LOS_ERRNO_TSK_ALREADY_EXIT; + } + /* If the task is running and scheduler is locked then you can not delete it */ if (((taskCB->taskStatus) & OS_TASK_STATUS_RUNNING) && (g_losTaskLock != 0)) { PRINT_INFO("In case of task lock, task deletion is not recommended\n"); @@ -934,6 +1078,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID) OsHookCall(LOS_HOOK_TYPE_TASK_DELETE, taskCB); OsSchedTaskExit(taskCB); + OsTaskJoinPostUnsafe(taskCB); LOS_EventDestroy(&(taskCB->event)); taskCB->event.uwEventID = OS_NULL_INT; @@ -943,24 +1088,19 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID) (VOID)memset_s((VOID *)&g_cpup[taskCB->taskID], sizeof(OsCpupCB), 0, sizeof(OsCpupCB)); #endif if (taskCB->taskStatus & OS_TASK_STATUS_RUNNING) { - taskCB->taskStatus = OS_TASK_STATUS_UNUSED; - OsRunningTaskDelete(taskID, taskCB); + if (!(taskCB->taskStatus & OS_TASK_STATUS_EXIT)) { + taskCB->taskStatus = OS_TASK_STATUS_UNUSED; + OsRunningTaskDelete(taskID, taskCB); + } LOS_IntRestore(intSave); LOS_Schedule(); return LOS_OK; - } else { - taskCB->taskStatus = OS_TASK_STATUS_UNUSED; - LOS_ListAdd(&g_losFreeTask, &taskCB->pendList); -#if (LOSCFG_EXC_HARDWARE_STACK_PROTECTION == 1) - stackPtr = taskCB->topOfStack - OS_TASK_STACK_PROTECT_SIZE; -#else - stackPtr = taskCB->topOfStack; -#endif - (VOID)LOS_MemFree(OS_TASK_STACK_ADDR, (VOID *)stackPtr); - taskCB->topOfStack = (UINT32)NULL; } + taskCB->joinRetval = LOS_CurTaskIDGet(); + OsRecycleTaskResources(taskCB, &stackPtr); LOS_IntRestore(intSave); + (VOID)LOS_MemFree(OS_TASK_STACK_ADDR, (VOID *)stackPtr); return LOS_OK; } diff --git a/testsuits/sample/kernel/event/It_los_event.c b/testsuits/sample/kernel/event/It_los_event.c index a2e25e09..ce315fa5 100644 --- a/testsuits/sample/kernel/event/It_los_event.c +++ b/testsuits/sample/kernel/event/It_los_event.c @@ -38,6 +38,7 @@ EVENT_CB_S g_pevent; VOID ItSuiteLosEvent() { ItLosEvent001(); + ItLosEvent003(); ItLosEvent004(); ItLosEvent005(); ItLosEvent006(); @@ -64,7 +65,6 @@ VOID ItSuiteLosEvent() ItLosEvent043(); #if (LOS_KERNEL_TEST_FULL == 1) ItLosEvent002(); - ItLosEvent003(); ItLosEvent011(); ItLosEvent012(); ItLosEvent015(); diff --git a/testsuits/sample/kernel/event/It_los_event_003.c b/testsuits/sample/kernel/event/It_los_event_003.c index 574a256b..1cdedcff 100644 --- a/testsuits/sample/kernel/event/It_los_event_003.c +++ b/testsuits/sample/kernel/event/It_los_event_003.c @@ -57,7 +57,7 @@ static UINT32 Testcase(VOID) task1.pcName = "EventTsk3"; task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the test task. - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; g_testCount = 0; g_pevent.uwEventID = 0; @@ -71,11 +71,13 @@ static UINT32 Testcase(VOID) g_testCount++; - LOS_TaskDelay(1); + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); ICUNIT_GOTO_EQUAL(g_testCount, 3, g_testCount, EXIT); // 3, Here, assert that g_testCount is equal to 3. EXIT: LOS_TaskDelete(g_testTaskID01); + LOS_TaskJoin(g_testCount, NULL); return LOS_OK; } diff --git a/testsuits/sample/kernel/task/BUILD.gn b/testsuits/sample/kernel/task/BUILD.gn index 9e20da8c..fa3d32f9 100644 --- a/testsuits/sample/kernel/task/BUILD.gn +++ b/testsuits/sample/kernel/task/BUILD.gn @@ -144,6 +144,11 @@ static_library("test_task") { "It_los_task_115.c", "It_los_task_116.c", "It_los_task_117.c", + "It_los_task_118.c", + "It_los_task_119.c", + "It_los_task_120.c", + "It_los_task_121.c", + "It_los_task_122.c", ] configs += [ "//kernel/liteos_m/testsuits:include" ] diff --git a/testsuits/sample/kernel/task/It_los_task.c b/testsuits/sample/kernel/task/It_los_task.c index 6cf299e0..8a7b8783 100644 --- a/testsuits/sample/kernel/task/It_los_task.c +++ b/testsuits/sample/kernel/task/It_los_task.c @@ -32,7 +32,6 @@ #include "osTest.h" #include "It_los_task.h" - VOID ItSuiteLosTask() { ItLosTask001(); @@ -76,8 +75,11 @@ VOID ItSuiteLosTask() ItLosTask042(); ItLosTask046(); ItLosTask047(); + ItLosTask048(); ItLosTask049(); ItLosTask050(); + ItLosTask051(); + ItLosTask052(); ItLosTask055(); ItLosTask057(); ItLosTask058(); @@ -95,28 +97,8 @@ VOID ItSuiteLosTask() ItLosTask076(); ItLosTask077(); ItLosTask078(); - -#if (LOS_KERNEL_TEST_FULL == 1) - ItLosTask039(); - ItLosTask040(); - ItLosTask043(); - ItLosTask048(); - ItLosTask051(); - ItLosTask052(); - ItLosTask056(); - ItLosTask063(); - ItLosTask075(); - ItLosTask079(); - ItLosTask081(); - ItLosTask082(); - ItLosTask083(); - ItLosTask085(); - ItLosTask087(); - ItLosTask088(); ItLosTask089(); - ItLosTask090(); ItLosTask092(); - ItLosTask093(); ItLosTask094(); ItLosTask095(); ItLosTask097(); @@ -135,6 +117,28 @@ VOID ItSuiteLosTask() ItLosTask112(); ItLosTask113(); ItLosTask115(); + ItLosTask118(); + ItLosTask119(); + ItLosTask120(); + ItLosTask121(); + ItLosTask122(); + +#if (LOS_KERNEL_TEST_FULL == 1) + ItLosTask039(); + ItLosTask040(); + ItLosTask043(); + ItLosTask056(); + ItLosTask063(); + ItLosTask075(); + ItLosTask079(); + ItLosTask081(); + ItLosTask082(); + ItLosTask083(); + ItLosTask085(); + ItLosTask087(); + ItLosTask088(); + ItLosTask090(); + ItLosTask093(); ItLosTask116(); #if (LOS_KERNEL_HWI_TEST == 1) ItLosTask053(); diff --git a/testsuits/sample/kernel/task/It_los_task.h b/testsuits/sample/kernel/task/It_los_task.h index c73f1fb5..b4fd5aae 100644 --- a/testsuits/sample/kernel/task/It_los_task.h +++ b/testsuits/sample/kernel/task/It_los_task.h @@ -179,6 +179,11 @@ extern VOID ItLosTask114(VOID); extern VOID ItLosTask115(VOID); extern VOID ItLosTask116(VOID); extern VOID ItLosTask117(VOID); +extern VOID ItLosTask118(VOID); +extern VOID ItLosTask119(VOID); +extern VOID ItLosTask120(VOID); +extern VOID ItLosTask121(VOID); +extern VOID ItLosTask122(VOID); #ifdef __cplusplus #if __cplusplus diff --git a/testsuits/sample/kernel/task/It_los_task_014.c b/testsuits/sample/kernel/task/It_los_task_014.c index 9d2cf239..7033fe56 100644 --- a/testsuits/sample/kernel/task/It_los_task_014.c +++ b/testsuits/sample/kernel/task/It_los_task_014.c @@ -48,7 +48,6 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk014A"; task1.usTaskPrio = TASK_PRIO_TEST - 1; - task1.uwResved = -1; g_testCount = 0; ret = LOS_TaskCreate(&g_testTaskID01, &task1); diff --git a/testsuits/sample/kernel/task/It_los_task_048.c b/testsuits/sample/kernel/task/It_los_task_048.c index 9a84ca8c..8d866ed6 100644 --- a/testsuits/sample/kernel/task/It_los_task_048.c +++ b/testsuits/sample/kernel/task/It_los_task_048.c @@ -58,7 +58,7 @@ static UINT32 TestCase(VOID) task1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF01; task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk048A"; - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; if (TASK_EXISTED_D_NUM == 4) { // 4, set priority based on TASK_EXISTED_D_NUM. task1.usTaskPrio = 2; // 2, TASK_EXISTED_D_NUM == 4, set 2 as priority. } else if (TASK_EXISTED_D_NUM == 3) { // 3, set reasonable priority based on TASK_EXISTED_D_NUM. @@ -75,11 +75,14 @@ static UINT32 TestCase(VOID) task1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF02; task1.pcName = "Tsk048B"; task1.usTaskPrio = LOS_TASK_PRIORITY_LOWEST - 1; - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; ret = LOS_TaskCreate(&g_testTaskID02, &task1); ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); - ret = LOS_TaskDelay(2); // 2, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); + + ret = LOS_TaskJoin(g_testTaskID02, NULL); ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT); // 2, Here, assert that g_testCount is equal to 2. diff --git a/testsuits/sample/kernel/task/It_los_task_051.c b/testsuits/sample/kernel/task/It_los_task_051.c index 4b2f7cc9..d885af45 100644 --- a/testsuits/sample/kernel/task/It_los_task_051.c +++ b/testsuits/sample/kernel/task/It_los_task_051.c @@ -50,6 +50,7 @@ static VOID TaskF01(VOID) task1.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; task1.pcName = "Tsk051B"; task1.usTaskPrio = TASK_PRIO_TEST - 1; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; ICUNIT_GOTO_EQUAL(g_testCount, 0, g_testCount, EXIT); g_testCount++; @@ -57,7 +58,7 @@ static VOID TaskF01(VOID) ret = LOS_TaskCreate(&g_testTaskID02, &task1); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); - ret = LOS_TaskDelay(2); // 2, set delay time + ret = LOS_TaskJoin(g_testTaskID02, NULL); ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret); ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT); // 2, Here, assert that g_testCount is equal to 2. @@ -76,13 +77,14 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk051A"; task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the current task. + task1.uwResved = LOS_TASK_ATTR_JOINABLE; g_testCount = 0; ret = LOS_TaskCreate(&g_testTaskID01, &task1); ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); - ret = LOS_TaskDelay(2); // 2, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); ICUNIT_ASSERT_EQUAL(g_testCount, 3, g_testCount); // 3, Here, assert that g_testCount is equal to 3. diff --git a/testsuits/sample/kernel/task/It_los_task_094.c b/testsuits/sample/kernel/task/It_los_task_094.c index 00529c79..86481d63 100644 --- a/testsuits/sample/kernel/task/It_los_task_094.c +++ b/testsuits/sample/kernel/task/It_los_task_094.c @@ -65,7 +65,7 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk094A"; task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the current task. - task1.uwResved = 0; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; task1.uwArg = 0xffff; g_testCount = 0; @@ -101,12 +101,22 @@ static UINT32 TestCase(VOID) ICUNIT_GOTO_EQUAL(g_testCount, 3, g_testCount, EXIT); // 3, Here, assert that g_testCount is equal to 3. - LOS_TaskDelay(10); // 10, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = LOS_TaskJoin(g_testTaskID02, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = LOS_TaskJoin(g_testTaskID03, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); EXIT: LOS_TaskDelete(g_testTaskID01); LOS_TaskDelete(g_testTaskID02); LOS_TaskDelete(g_testTaskID03); + LOS_TaskJoin(g_testTaskID01, NULL); + LOS_TaskJoin(g_testTaskID02, NULL); + LOS_TaskJoin(g_testTaskID03, NULL); return LOS_OK; } diff --git a/testsuits/sample/kernel/task/It_los_task_095.c b/testsuits/sample/kernel/task/It_los_task_095.c index 0ad05b51..4e8a340a 100644 --- a/testsuits/sample/kernel/task/It_los_task_095.c +++ b/testsuits/sample/kernel/task/It_los_task_095.c @@ -47,7 +47,7 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk095A"; task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the current task. - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; g_testCount = 0; ret = LOS_TaskCreateOnly(&g_testTaskID01, &task1); @@ -56,7 +56,8 @@ static UINT32 TestCase(VOID) LOS_TaskResume(g_testTaskID01); - LOS_TaskDelay(10); // 10, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); ret = LOS_TaskCreateOnly(&g_testTaskID01, &task1); ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); @@ -66,11 +67,13 @@ static UINT32 TestCase(VOID) ret = LOS_TaskDelete(g_testTaskID01); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); + LOS_TaskJoin(g_testTaskID01, NULL); + return LOS_OK; EXIT: LOS_TaskDelete(g_testTaskID01); - + LOS_TaskJoin(g_testTaskID01, NULL); return LOS_OK; } diff --git a/testsuits/sample/kernel/task/It_los_task_097.c b/testsuits/sample/kernel/task/It_los_task_097.c index 7f538434..4770efbd 100644 --- a/testsuits/sample/kernel/task/It_los_task_097.c +++ b/testsuits/sample/kernel/task/It_los_task_097.c @@ -72,13 +72,14 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk097A"; task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the current task. - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; g_testCount = 0; ret = LOS_TaskCreate(&g_testTaskID01, &task1); ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); - LOS_TaskDelay(10); // 10, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT); // 2, Here, assert that g_testCount is equal to 2. @@ -92,7 +93,7 @@ static UINT32 TestCase(VOID) EXIT: LOS_TaskDelete(g_testTaskID01); - + LOS_TaskJoin(g_testTaskID01, NULL); return LOS_OK; } diff --git a/testsuits/sample/kernel/task/It_los_task_098.c b/testsuits/sample/kernel/task/It_los_task_098.c index 9e1edc65..3512911b 100644 --- a/testsuits/sample/kernel/task/It_los_task_098.c +++ b/testsuits/sample/kernel/task/It_los_task_098.c @@ -74,7 +74,7 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk098A"; task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the current task. - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; g_testCount = 0; @@ -84,7 +84,8 @@ static UINT32 TestCase(VOID) LOS_TaskResume(g_testTaskID01); - LOS_TaskDelay(10); // 10, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT); // 2, Here, assert that g_testCount is equal to 2. @@ -98,6 +99,7 @@ static UINT32 TestCase(VOID) EXIT: LOS_TaskDelete(g_testTaskID01); + LOS_TaskJoin(g_testTaskID01, NULL); return LOS_OK; } diff --git a/testsuits/sample/kernel/task/It_los_task_100.c b/testsuits/sample/kernel/task/It_los_task_100.c index 92154bd8..c57e5b69 100644 --- a/testsuits/sample/kernel/task/It_los_task_100.c +++ b/testsuits/sample/kernel/task/It_los_task_100.c @@ -55,7 +55,7 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk100A"; task1.usTaskPrio = TASK_PRIO_TEST - 1; - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; g_testCount = 0; @@ -70,7 +70,8 @@ static UINT32 TestCase(VOID) ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT); // 2, Here, assert that g_testCount is equal to 2. - LOS_TaskDelay(10); // 10, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); ret = LOS_TaskPriGet(g_testTaskID01); ICUNIT_ASSERT_EQUAL(ret, (UINT16)OS_INVALID, ret); @@ -78,6 +79,7 @@ static UINT32 TestCase(VOID) return LOS_OK; EXIT: LOS_TaskDelete(g_testTaskID01); + LOS_TaskJoin(g_testTaskID01, NULL); return LOS_OK; } diff --git a/testsuits/sample/kernel/task/It_los_task_101.c b/testsuits/sample/kernel/task/It_los_task_101.c index 653a0f09..64ce487f 100644 --- a/testsuits/sample/kernel/task/It_los_task_101.c +++ b/testsuits/sample/kernel/task/It_los_task_101.c @@ -55,7 +55,7 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk101A"; task1.usTaskPrio = TASK_PRIO_TEST - 1; - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; g_testCount = 0; @@ -70,7 +70,8 @@ static UINT32 TestCase(VOID) ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT); // 2, Here, assert that g_testCount is equal to 2. - LOS_TaskDelay(10); // 10, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); ret = LOS_TaskPriGet(g_testTaskID01); ICUNIT_ASSERT_EQUAL(ret, (UINT16)OS_INVALID, ret); @@ -78,6 +79,7 @@ static UINT32 TestCase(VOID) return LOS_OK; EXIT: LOS_TaskDelete(g_testTaskID01); + LOS_TaskJoin(g_testTaskID01, NULL); return LOS_OK; } diff --git a/testsuits/sample/kernel/task/It_los_task_103.c b/testsuits/sample/kernel/task/It_los_task_103.c index 29846480..7ff4c3df 100644 --- a/testsuits/sample/kernel/task/It_los_task_103.c +++ b/testsuits/sample/kernel/task/It_los_task_103.c @@ -86,13 +86,14 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk103A"; task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the current task. - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; g_testCount = 0; ret = LOS_TaskCreate(&g_testTaskID01, &task1); ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); - LOS_TaskDelay(20); // 20, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT); // 2, Here, assert that g_testCount is equal to 2. @@ -100,7 +101,7 @@ static UINT32 TestCase(VOID) EXIT: LOS_TaskDelete(g_testTaskID01); - + LOS_TaskJoin(g_testTaskID01, NULL); return LOS_OK; } diff --git a/testsuits/sample/kernel/task/It_los_task_104.c b/testsuits/sample/kernel/task/It_los_task_104.c index 1996a11d..3a199a70 100644 --- a/testsuits/sample/kernel/task/It_los_task_104.c +++ b/testsuits/sample/kernel/task/It_los_task_104.c @@ -91,13 +91,14 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk104A"; task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the current task. - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; g_testCount = 0; ret = LOS_TaskCreate(&g_testTaskID01, &task1); ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); - LOS_TaskDelay(10); // 10, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); ICUNIT_GOTO_EQUAL(g_testCount, 1, g_testCount, EXIT); @@ -105,7 +106,7 @@ static UINT32 TestCase(VOID) EXIT: LOS_TaskDelete(g_testTaskID01); - + LOS_TaskJoin(g_testTaskID01, NULL); return LOS_OK; } diff --git a/testsuits/sample/kernel/task/It_los_task_105.c b/testsuits/sample/kernel/task/It_los_task_105.c index c0c2c2c1..e80462ec 100644 --- a/testsuits/sample/kernel/task/It_los_task_105.c +++ b/testsuits/sample/kernel/task/It_los_task_105.c @@ -58,7 +58,7 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk105A"; task1.usTaskPrio = TASK_PRIO_TEST - 1; - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; g_testCount = 0; @@ -79,7 +79,8 @@ static UINT32 TestCase(VOID) ret = LOS_TaskPriSet(g_testTaskID01, OS_TASK_PRIORITY_LOWEST + 1); ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_TSK_PRIOR_ERROR, ret); - LOS_TaskDelay(10); // 10, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT); // 2, Here, assert that g_testCount is equal to 2. @@ -90,6 +91,7 @@ static UINT32 TestCase(VOID) EXIT: LOS_TaskDelete(g_testTaskID01); + LOS_TaskJoin(g_testTaskID01, NULL); return LOS_OK; } diff --git a/testsuits/sample/kernel/task/It_los_task_107.c b/testsuits/sample/kernel/task/It_los_task_107.c index e9c63eff..7c62a56d 100644 --- a/testsuits/sample/kernel/task/It_los_task_107.c +++ b/testsuits/sample/kernel/task/It_los_task_107.c @@ -89,13 +89,14 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk107A"; task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the current task. - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; g_testCount = 0; ret = LOS_TaskCreate(&g_testTaskID01, &task1); ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); - LOS_TaskDelay(10); // 10, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); ICUNIT_GOTO_EQUAL(g_testCount, 3, g_testCount, EXIT); // 3, Here, assert that g_testCount is equal to 3. @@ -103,7 +104,7 @@ static UINT32 TestCase(VOID) EXIT: LOS_TaskDelete(g_testTaskID01); - + LOS_TaskJoin(g_testTaskID01, NULL); return LOS_OK; } diff --git a/testsuits/sample/kernel/task/It_los_task_108.c b/testsuits/sample/kernel/task/It_los_task_108.c index 003f878b..a42f2209 100644 --- a/testsuits/sample/kernel/task/It_los_task_108.c +++ b/testsuits/sample/kernel/task/It_los_task_108.c @@ -92,13 +92,14 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk108A"; task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the current task. - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; g_testCount = 0; ret = LOS_TaskCreate(&g_testTaskID01, &task1); ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); - LOS_TaskDelay(20); // 20, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); ICUNIT_GOTO_EQUAL(g_testCount, 4, g_testCount, EXIT); // 4, Here, assert that g_testCount is equal to 4. @@ -106,7 +107,7 @@ static UINT32 TestCase(VOID) EXIT: LOS_TaskDelete(g_testTaskID01); - + LOS_TaskJoin(g_testTaskID01, NULL); return LOS_OK; } diff --git a/testsuits/sample/kernel/task/It_los_task_109.c b/testsuits/sample/kernel/task/It_los_task_109.c index 67cafb49..2c3906fd 100644 --- a/testsuits/sample/kernel/task/It_los_task_109.c +++ b/testsuits/sample/kernel/task/It_los_task_109.c @@ -88,14 +88,15 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk109A"; task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the current task. - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; g_testCount = 0; ret = LOS_TaskCreate(&g_testTaskID01, &task1); ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); - LOS_TaskDelay(10); // 10, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); ICUNIT_GOTO_EQUAL(g_testCount, 3, g_testCount, EXIT); // 3, Here, assert that g_testCount is equal to 3. @@ -103,7 +104,7 @@ static UINT32 TestCase(VOID) EXIT: LOS_TaskDelete(g_testTaskID01); - + LOS_TaskJoin(g_testTaskID01, NULL); return LOS_OK; } diff --git a/testsuits/sample/kernel/task/It_los_task_110.c b/testsuits/sample/kernel/task/It_los_task_110.c index 1bb1f8b4..e0b5cec0 100644 --- a/testsuits/sample/kernel/task/It_los_task_110.c +++ b/testsuits/sample/kernel/task/It_los_task_110.c @@ -94,13 +94,14 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk110A"; task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the current task. - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; g_testCount = 0; ret = LOS_TaskCreate(&g_testTaskID01, &task1); ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); - LOS_TaskDelay(10); // 10, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); ICUNIT_GOTO_EQUAL(g_testCount, 4, g_testCount, EXIT); // 4, Here, assert that g_testCount is equal to 4. @@ -108,7 +109,7 @@ static UINT32 TestCase(VOID) EXIT: LOS_TaskDelete(g_testTaskID01); - + LOS_TaskJoin(g_testTaskID01, NULL); return LOS_OK; } diff --git a/testsuits/sample/kernel/task/It_los_task_111.c b/testsuits/sample/kernel/task/It_los_task_111.c index f276dae3..d49b7b08 100644 --- a/testsuits/sample/kernel/task/It_los_task_111.c +++ b/testsuits/sample/kernel/task/It_los_task_111.c @@ -42,10 +42,10 @@ static VOID TaskF02(VOID) g_testCount++; // 3, modify task priority, base on testsuite task`s priority. - ret = LOS_TaskPriSet(g_testTaskID01, TASK_PRIO_TEST - 3); + ret = LOS_TaskPriSet(g_testTaskID01, TASK_PRIO_TEST - 1); /* 1: Priority is relatively cheap */ ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret); - ICUNIT_GOTO_EQUAL(g_testCount, 1, g_testCount, EXIT); + ICUNIT_GOTO_EQUAL(g_testCount, 1, g_testCount, EXIT); /* 1: count */ g_testCount++; return; @@ -70,7 +70,7 @@ static VOID TaskF01(VOID) ret = LOS_TaskPriGet(g_testTaskID01); // 3, Assert this result is consistent with the priority that has been set. - ICUNIT_ASSERT_EQUAL_VOID(ret, TASK_PRIO_TEST - 3, ret); + ICUNIT_ASSERT_EQUAL_VOID(ret, TASK_PRIO_TEST - 1, ret); /* 1: Priority is relatively cheap */ ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT); // 2, Here, assert that g_testCount is equal to 2. g_testCount++; @@ -91,13 +91,14 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk111A"; task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the current task. - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; g_testCount = 0; ret = LOS_TaskCreate(&g_testTaskID01, &task1); ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); - LOS_TaskDelay(10); // 10, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); ICUNIT_GOTO_EQUAL(g_testCount, 3, g_testCount, EXIT); // 3, Here, assert that g_testCount is equal to 3. @@ -105,7 +106,7 @@ static UINT32 TestCase(VOID) EXIT: LOS_TaskDelete(g_testTaskID01); - + LOS_TaskJoin(g_testTaskID01, NULL); return LOS_OK; } diff --git a/testsuits/sample/kernel/task/It_los_task_112.c b/testsuits/sample/kernel/task/It_los_task_112.c index 2c472493..84e29324 100644 --- a/testsuits/sample/kernel/task/It_los_task_112.c +++ b/testsuits/sample/kernel/task/It_los_task_112.c @@ -32,9 +32,6 @@ #include "osTest.h" #include "It_los_task.h" - - - static VOID TaskF02(VOID) { UINT32 ret; @@ -93,13 +90,14 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk112A"; task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the current task. - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; g_testCount = 0; ret = LOS_TaskCreate(&g_testTaskID01, &task1); ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); - LOS_TaskDelay(10); // 10, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); ICUNIT_GOTO_EQUAL(g_testCount, 3, g_testCount, EXIT); // 3, Here, assert that g_testCount is equal to 3. @@ -107,7 +105,7 @@ static UINT32 TestCase(VOID) EXIT: LOS_TaskDelete(g_testTaskID01); - + LOS_TaskJoin(g_testTaskID01, NULL); return LOS_OK; } diff --git a/testsuits/sample/kernel/task/It_los_task_113.c b/testsuits/sample/kernel/task/It_los_task_113.c index 4c2a5504..958078c5 100644 --- a/testsuits/sample/kernel/task/It_los_task_113.c +++ b/testsuits/sample/kernel/task/It_los_task_113.c @@ -99,13 +99,14 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk113A"; task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the current task. - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; g_testCount = 0; ret = LOS_TaskCreate(&g_testTaskID01, &task1); ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); - LOS_TaskDelay(10); // 10, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); ICUNIT_GOTO_EQUAL(g_testCount, 5, g_testCount, EXIT); // 5, Here, assert that g_testCount is equal to 5. @@ -113,7 +114,7 @@ static UINT32 TestCase(VOID) EXIT: LOS_TaskDelete(g_testTaskID01); - + LOS_TaskJoin(g_testTaskID01, NULL); return LOS_OK; } diff --git a/testsuits/sample/kernel/task/It_los_task_115.c b/testsuits/sample/kernel/task/It_los_task_115.c index 0ca84a4a..cc17fe64 100644 --- a/testsuits/sample/kernel/task/It_los_task_115.c +++ b/testsuits/sample/kernel/task/It_los_task_115.c @@ -98,13 +98,14 @@ static UINT32 TestCase(VOID) task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk078A"; task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the current task. - task1.uwResved = LOS_TASK_STATUS_DETACHED; + task1.uwResved = LOS_TASK_ATTR_JOINABLE; g_testCount = 0; ret = LOS_TaskCreate(&g_testTaskID01, &task1); ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); - LOS_TaskDelay(10); // 10, set delay time + ret = LOS_TaskJoin(g_testTaskID01, NULL); + ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); ICUNIT_GOTO_EQUAL(g_testCount, 4, g_testCount, EXIT); // 4, Here, assert that g_testCount is equal to 4. @@ -112,7 +113,7 @@ static UINT32 TestCase(VOID) EXIT: LOS_TaskDelete(g_testTaskID01); - + LOS_TaskJoin(g_testTaskID01, NULL); return LOS_OK; } diff --git a/testsuits/sample/kernel/task/It_los_task_118.c b/testsuits/sample/kernel/task/It_los_task_118.c new file mode 100644 index 00000000..46d0db7f --- /dev/null +++ b/testsuits/sample/kernel/task/It_los_task_118.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "osTest.h" +#include "It_los_task.h" + +static VOID *TaskJoinf01(void *argument) +{ + g_testCount++; + + return (VOID *)9; /* 9: return val */ +} + +static UINT32 TestCase(VOID) +{ + UINT32 taskID; + UINT32 ret; + UINTPTR uwtemp = 1; + TSK_INIT_PARAM_S osTaskInitParam = { 0 }; + + g_testCount = 0; + + osTaskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskJoinf01; + osTaskInitParam.uwStackSize = OS_TSK_TEST_STACK_SIZE; + osTaskInitParam.pcName = "Join"; + osTaskInitParam.usTaskPrio = TASK_PRIO_TEST; + osTaskInitParam.uwResved = LOS_TASK_ATTR_JOINABLE; + + ret = LOS_TaskCreate(&taskID, &osTaskInitParam); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = LOS_TaskJoin(taskID, &uwtemp); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + ICUNIT_ASSERT_EQUAL(uwtemp, 9, uwtemp); /* 8: pthread exit code */ + + return LOS_OK; +} + +VOID ItLosTask118(VOID) // IT_Layer_ModuleORFeature_No +{ + TEST_ADD_CASE("ItLosTask118", TestCase, TEST_LOS, TEST_TASK, TEST_LEVEL0, TEST_FUNCTION); +} + diff --git a/testsuits/sample/kernel/task/It_los_task_119.c b/testsuits/sample/kernel/task/It_los_task_119.c new file mode 100644 index 00000000..ea6e30f7 --- /dev/null +++ b/testsuits/sample/kernel/task/It_los_task_119.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "osTest.h" +#include "It_los_task.h" + +static VOID *TaskDeatchf01(void *argument) +{ + int ret = LOS_TaskDetach(LOS_CurTaskIDGet()); + ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_TSK_NOT_JOIN, ret); + + g_testCount++; + return NULL; +} + +static UINT32 TestCase(VOID) +{ + UINT32 ret; + UINT32 taskID; + TSK_INIT_PARAM_S osTaskInitParam = { 0 }; + + g_testCount = 0; + + osTaskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskDeatchf01; + osTaskInitParam.uwStackSize = OS_TSK_TEST_STACK_SIZE; + osTaskInitParam.pcName = "IT_TST_INI"; + osTaskInitParam.usTaskPrio = TASK_PRIO_TEST + 1; + osTaskInitParam.uwResved = LOS_TASK_ATTR_JOINABLE; + + ret = LOS_TaskCreate(&taskID, &osTaskInitParam); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = LOS_TaskJoin(taskID, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ICUNIT_ASSERT_EQUAL(g_testCount, 1, g_testCount); + + return LOS_OK; +} + +VOID ItLosTask119(VOID) // IT_Layer_ModuleORFeature_No +{ + TEST_ADD_CASE("ItLosTask119", TestCase, TEST_LOS, TEST_TASK, TEST_LEVEL0, TEST_FUNCTION); +} + diff --git a/testsuits/sample/kernel/task/It_los_task_120.c b/testsuits/sample/kernel/task/It_los_task_120.c new file mode 100644 index 00000000..c6f4c155 --- /dev/null +++ b/testsuits/sample/kernel/task/It_los_task_120.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "osTest.h" +#include "It_los_task.h" + +static VOID *TaskDeatchf01(void *argument) +{ + UINT32 ret = LOS_TaskDetach(LOS_CurTaskIDGet()); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + g_testCount++; + + LOS_TaskDelay(1000); /* 1000 ticks */ + return NULL; +} + +static UINT32 TestCase(VOID) +{ + UINT32 ret; + UINT32 taskID; + TSK_INIT_PARAM_S osTaskInitParam = { 0 }; + + g_testCount = 0; + + osTaskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskDeatchf01; + osTaskInitParam.uwStackSize = OS_TSK_TEST_STACK_SIZE; + osTaskInitParam.pcName = "deatch"; + osTaskInitParam.usTaskPrio = TASK_PRIO_TEST - 1; + osTaskInitParam.uwResved = LOS_TASK_ATTR_JOINABLE; + + ret = LOS_TaskCreate(&taskID, &osTaskInitParam); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ICUNIT_ASSERT_EQUAL(g_testCount, 1, g_testCount); + + ret = LOS_TaskJoin(taskID, NULL); + ICUNIT_ASSERT_EQUAL(ret, LOS_NOK, ret); + + return LOS_OK; +} + +VOID ItLosTask120(VOID) // IT_Layer_ModuleORFeature_No +{ + TEST_ADD_CASE("ItLosTask120", TestCase, TEST_LOS, TEST_TASK, TEST_LEVEL0, TEST_FUNCTION); +} + diff --git a/testsuits/sample/kernel/task/It_los_task_121.c b/testsuits/sample/kernel/task/It_los_task_121.c new file mode 100644 index 00000000..d9e45706 --- /dev/null +++ b/testsuits/sample/kernel/task/It_los_task_121.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "osTest.h" +#include "It_los_task.h" + +static VOID *TaskDeatchf01(void *argument) +{ + UINT32 ret = LOS_TaskDetach(LOS_CurTaskIDGet()); + ICUNIT_ASSERT_EQUAL(ret, LOS_NOK, ret); + + g_testCount++; + + LOS_TaskDelay(1000); /* 1000 ticks */ + return NULL; +} + +static UINT32 TestCase(VOID) +{ + UINT32 ret; + UINT32 taskID; + TSK_INIT_PARAM_S osTaskInitParam = { 0 }; + + g_testCount = 0; + + osTaskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskDeatchf01; + osTaskInitParam.uwStackSize = OS_TSK_TEST_STACK_SIZE; + osTaskInitParam.pcName = "deatch"; + osTaskInitParam.usTaskPrio = TASK_PRIO_TEST - 1; + + ret = LOS_TaskCreate(&taskID, &osTaskInitParam); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ICUNIT_ASSERT_EQUAL(g_testCount, 1, g_testCount); + + ret = LOS_TaskJoin(taskID, NULL); + ICUNIT_ASSERT_EQUAL(ret, LOS_NOK, ret); + + return LOS_OK; +} + +VOID ItLosTask121(VOID) // IT_Layer_ModuleORFeature_No +{ + TEST_ADD_CASE("ItLosTask121", TestCase, TEST_LOS, TEST_TASK, TEST_LEVEL0, TEST_FUNCTION); +} + diff --git a/testsuits/sample/kernel/task/It_los_task_122.c b/testsuits/sample/kernel/task/It_los_task_122.c new file mode 100644 index 00000000..31b223ce --- /dev/null +++ b/testsuits/sample/kernel/task/It_los_task_122.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "osTest.h" +#include "It_los_task.h" + +static UINT32 g_joinTaskID; +static VOID *TaskJoinf01(void *argument) +{ + g_testCount++; + + return NULL; +} + +static VOID *TaskJoinf02(VOID *argument) +{ + UINT32 ret = LOS_TaskDelete(g_joinTaskID); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + return NULL; +} + +static UINT32 TestCase(VOID) +{ + UINT32 taskID; + UINT32 ret; + UINTPTR temp = 0; + TSK_INIT_PARAM_S osTaskInitParam = { 0 }; + + g_testCount = 0; + + osTaskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskJoinf01; + osTaskInitParam.uwStackSize = OS_TSK_TEST_STACK_SIZE; + osTaskInitParam.pcName = "Join"; + osTaskInitParam.usTaskPrio = TASK_PRIO_TEST + 1; + osTaskInitParam.uwResved = LOS_TASK_ATTR_JOINABLE; + + ret = LOS_TaskCreate(&g_joinTaskID, &osTaskInitParam); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + osTaskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskJoinf02; + osTaskInitParam.uwStackSize = OS_TSK_TEST_STACK_SIZE; + osTaskInitParam.pcName = "deatch"; + osTaskInitParam.usTaskPrio = TASK_PRIO_TEST - 1; + + ret = LOS_TaskCreate(&taskID, &osTaskInitParam); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = LOS_TaskJoin(g_joinTaskID, &temp); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + ICUNIT_ASSERT_EQUAL(temp, taskID, temp); + + return LOS_OK; +} + +VOID ItLosTask122(VOID) // IT_Layer_ModuleORFeature_No +{ + TEST_ADD_CASE("ItLosTask122", TestCase, TEST_LOS, TEST_TASK, TEST_LEVEL0, TEST_FUNCTION); +} + diff --git a/testsuits/src/osTest.c b/testsuits/src/osTest.c index b7ac3baf..2b442c08 100644 --- a/testsuits/src/osTest.c +++ b/testsuits/src/osTest.c @@ -184,13 +184,13 @@ VOID TestTaskEntry() UINT32 los_TestInit(VOID) { UINT32 ret; - TSK_INIT_PARAM_S osTaskInitParam; + TSK_INIT_PARAM_S osTaskInitParam = { 0 }; osTaskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)TestTaskEntry; osTaskInitParam.uwStackSize = OS_TSK_TEST_STACK_SIZE; osTaskInitParam.pcName = "IT_TST_INI"; osTaskInitParam.usTaskPrio = TASK_PRIO_TEST; - osTaskInitParam.uwResved = LOS_TASK_STATUS_DETACHED; + osTaskInitParam.uwResved = LOS_TASK_ATTR_JOINABLE; ret = LOS_TaskCreate(&g_testTskHandle, &osTaskInitParam); if (LOS_OK != ret) { diff --git a/testsuits/unittest/posix/src/pthread/pthread_cond_func_test.c b/testsuits/unittest/posix/src/pthread/pthread_cond_func_test.c index 5c6faeda..5093d3ec 100644 --- a/testsuits/unittest/posix/src/pthread/pthread_cond_func_test.c +++ b/testsuits/unittest/posix/src/pthread/pthread_cond_func_test.c @@ -36,6 +36,8 @@ #include "cmsis_os2.h" #include "common_test.h" +static UINT32 g_testCount; + /** * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency * @param : subsystem name is pthread @@ -63,13 +65,234 @@ static BOOL PthreadFuncTestSuiteTearDown(void) return TRUE; } +static VOID *pthread_join_f01(void *argument) +{ + g_testCount++; + + pthread_exit((void *)8); /* 8: pthread exit code */ + return (void *)9; /* 9: return val */ +} + /** * @tc.number : SUB_KERNEL_PTHREAD_OPERATION_001 - * @tc.name : event operation for creat + * @tc.name : event operation for join * @tc.desc : [C- SOFTWARE -0200] */ LITE_TEST_CASE(PthreadFuncTestSuite, testPthread001, Function | MediumTest | Level1) { + pthread_attr_t attr; + pthread_t newTh; + struct sched_param schedParam = { 0 }; + UINT32 ret; + UINTPTR uwtemp = 1; + + g_testCount = 0; + + ret = pthread_attr_init(&attr); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_setstacksize(&attr, OS_TSK_TEST_STACK_SIZE); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + schedParam.sched_priority = TASK_PRIO_TEST; + ret = pthread_attr_setschedparam(&attr, &schedParam); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_create(&newTh, &attr, pthread_join_f01, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_join(newTh, (void **)&uwtemp); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + ICUNIT_ASSERT_EQUAL(uwtemp, 8, uwtemp); /* 8: pthread exit code */ + + return LOS_OK; +}; + +static VOID *pthread_join_f02(void *argument) +{ + g_testCount++; + + return (void *)9; /* 9: return val */ +} + +/** + * @tc.number : SUB_KERNEL_PTHREAD_OPERATION_002 + * @tc.name : event operation for join + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadFuncTestSuite, testPthread002, Function | MediumTest | Level1) +{ + pthread_attr_t attr; + pthread_t newTh; + struct sched_param schedParam = { 0 }; + UINT32 ret; + UINTPTR uwtemp = 1; + + g_testCount = 0; + + ret = pthread_attr_init(&attr); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_setstacksize(&attr, OS_TSK_TEST_STACK_SIZE); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + schedParam.sched_priority = TASK_PRIO_TEST; + ret = pthread_attr_setschedparam(&attr, &schedParam); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_create(&newTh, &attr, pthread_join_f02, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_join(newTh, (void **)&uwtemp); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + ICUNIT_ASSERT_EQUAL(uwtemp, 9, uwtemp); /* 9: pthread exit code */ + + return LOS_OK; +}; + +static VOID *pthread_join_f03(void *argument) +{ + int ret = pthread_detach(pthread_self()); + ICUNIT_ASSERT_EQUAL(ret, ESRCH, ret); + + g_testCount++; + return NULL; +} + +/** + * @tc.number : SUB_KERNEL_PTHREAD_OPERATION_003 + * @tc.name : event operation for deatch + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadFuncTestSuite, testPthread003, Function | MediumTest | Level1) +{ + pthread_attr_t attr; + pthread_t newTh; + struct sched_param schedParam = { 0 }; + UINT32 ret; + + g_testCount = 0; + + ret = pthread_attr_init(&attr); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_setstacksize(&attr, OS_TSK_TEST_STACK_SIZE); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + schedParam.sched_priority = TASK_PRIO_TEST + 1; + ret = pthread_attr_setschedparam(&attr, &schedParam); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_create(&newTh, &attr, pthread_join_f03, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_join(newTh, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ICUNIT_ASSERT_EQUAL(g_testCount, 1, g_testCount); + return LOS_OK; +}; + +static VOID *pthread_join_f04(void *argument) +{ + int ret = pthread_detach(pthread_self()); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + g_testCount++; + return NULL; +} + +/** + * @tc.number : SUB_KERNEL_PTHREAD_OPERATION_004 + * @tc.name : event operation for deatch + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadFuncTestSuite, testPthread004, Function | MediumTest | Level1) +{ + pthread_attr_t attr; + pthread_t newTh; + struct sched_param schedParam = { 0 }; + UINT32 ret; + + g_testCount = 0; + + ret = pthread_attr_init(&attr); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_setstacksize(&attr, OS_TSK_TEST_STACK_SIZE); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + schedParam.sched_priority = TASK_PRIO_TEST - 1; + ret = pthread_attr_setschedparam(&attr, &schedParam); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_create(&newTh, &attr, pthread_join_f04, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ICUNIT_ASSERT_EQUAL(g_testCount, 1, g_testCount); + + ret = pthread_join(newTh, NULL); + ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret); + + return LOS_OK; +}; + +static VOID *pthread_join_f05(void *argument) +{ + int ret = pthread_detach(pthread_self()); + ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret); + + usleep(100000); /* 100000: sleep 100 ms */ + return NULL; +} + +/** + * @tc.number : SUB_KERNEL_PTHREAD_OPERATION_005 + * @tc.name : event operation for deatch + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadFuncTestSuite, testPthread005, Function | MediumTest | Level1) +{ + pthread_attr_t attr; + pthread_t newTh; + struct sched_param schedParam = { 0 }; + UINT32 ret; + + ret = pthread_attr_init(&attr); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_setstacksize(&attr, OS_TSK_TEST_STACK_SIZE); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + schedParam.sched_priority = TASK_PRIO_TEST - 1; + ret = pthread_attr_setschedparam(&attr, &schedParam); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_create(&newTh, &attr, pthread_join_f05, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_join(newTh, NULL); + ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret); + + return LOS_OK; }; RUN_TEST_SUITE(PthreadFuncTestSuite);