Skip to content

Conversation

@adam-scislowicz
Copy link

@adam-scislowicz adam-scislowicz commented Feb 13, 2023

Add coverage tests for the functions mentioned in the title.

Added new tests to the multiple_priorities_no_timeslice and created a new directory multiple_priorities_no_timeslice_tickless_idle with configUSE_TICKLESS_IDLE set to 1.

Test Steps

From the FreeRTOS/Test/CMock/smp subdirectory run 'make' against the default target followed by running 'make lcovhtml' to generate an HTML coverage report.

Related Issue

TS-24171, TS-24181

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@chinglee-iot
Copy link
Owner

chinglee-iot commented Feb 14, 2023

Create new folder only when the FreeRTOSConfig.h file is different

It looks like the task_creation_covg has similar FreeRTOSConfig.h with multiple_priorities_no_timeslice. Suggest we use the same folder and put the test in covg_multiple_priorities_no_timeslice_utest.c.

@chinglee-iot
Copy link
Owner

test_coverage_<API>_<tested behavior>
Example:
test_coverage_xTaskResumeFromISR_resume_lower_priority_suspended_task

The test case naming is different from the test format guideline. Suggest we update the test case naming.

@adam-scislowicz adam-scislowicz changed the title Add coverage for prvAddNewTaskToReadyList and vTaskCoreAffinitySet. Add coverage for prvAddNewTaskToReadyList, vTaskCoreAffinitySet, vTaskGetInfo, and xTaskGenericNotify. Feb 15, 2023
@chinglee-iot
Copy link
Owner

chinglee-iot commented Feb 16, 2023

@adam-scislowicz

  • Please create new different PRs for the new commits. This would help the reviewer focus on the changes. We can also contribute to the project gradually.
  • We agree to use doxygen comment format in the meeting. Suggest we also update the comments section. This can be referenced in the Adding coverage test for TaskResumeFromISR #4 .
  • printf is used in the test cases. I think they are for debug purpose. Suggest we remove it or use debug macro and default disable it.
  • We suggest to use mocks and variables to implement the test cases ( reference Adding coverage test for TaskResumeFromISR #4 ). If there is difficulty we can't use mock or variable, please feedback the problem and we will discuss over it.

@adam-scislowicz adam-scislowicz changed the title Add coverage for prvAddNewTaskToReadyList, vTaskCoreAffinitySet, vTaskGetInfo, and xTaskGenericNotify. Add coverage for prvAddNewTaskToReadyList, vTaskCoreAffinitySet. Feb 16, 2023
xTickCount = 0U;
vTaskStepTick((TickType_t)10U);
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these duplicated test cases?
Can you share your opinion about removing these test cases?

void test_coverage_xTaskResumeFromISR_resume_higher_priority_suspended_task( void )
void test_coverage_xTaskResumeFromISR_resume_lower_priority_suspended_task( void )

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, those may be duplicate. In fact they were meant to cover this:

      /* Ready lists can be accessed so move the task from the
                     * suspended list to the ready list directly. */
                    if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )
                    {
                        xYieldRequired = pdTRUE;

                        /* Mark that a yield is pending in case the user is not
                         * using the return value to initiate a context switch
                         * from the ISR using portYIELD_FROM_ISR. */
                        xYieldPendings[ 0 ] = pdTRUE;
                    }
                    else
                    {
                        mtCOVERAGE_TEST_MARKER();
                    }

However, the above is within an IFDEF and only applies to single core processing. So I think they are not actually covering the case I intended, and that case is already covered by other tests.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
These test cases tried to cover these section in the image. The comment also have code snippet to indicate that.
I run the coverage test with you repo. They are not covered.
So I don't think these are duplicated test cases.
Suggest we don't remove these test cases.

*
* <b>Coverage</b>
* @code{c}
* for( xCoreID = 0; xCoreID < configNUMBER_OF_CORES; xCoreID++ )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
This condition doesn't seems to be covered with this test.

Copy link
Owner

@chinglee-iot chinglee-iot Feb 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the test coverage report, this line doesn't seem to be covered by the test.
My suggestion is that we following the best practice in the document "FreeRTOS SMP coverage test format and guideline". The following implementation of this test case can be referenced.

Please also apply this comment in other test cases if they may be given the same suggestion.

/**
 * @brief prvAddNewTaskToReadyList - add a new idle task to the list of ready tasks
 *
 * This test creates more tasks than ther are cores in order to test the
 * branch related to the limit condition of the for loop.
 *
 * <b>Coverage</b>
 * @code{c}
 * for( xCoreID = 0; xCoreID < configNUMBER_OF_CORES; xCoreID++ )
 * @endcode
 * for loop condition ( xCoreID < configNUMBER_OF_CORES ) is false.
 */
void test_coverage_prvAddNewTaskToReadyList_create_more_idle_tasks_than_cores( void )
{
    TCB_t xTaskTCBs[ configNUMBER_OF_CORES + 1 ] = { 0 };
    uint32_t i;

    /* Setup the variables and structure. */
    /* Initialize the idle priority ready list and set top ready priority to idle priority. */
    vListInitialise( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) );
    uxTopReadyPriority = tskIDLE_PRIORITY;
    uxCurrentNumberOfTasks = 0;
    xSchedulerRunning = pdFALSE;

    /* Create idle tasks and add it into the ready list. Create one more idle priority level
     * in the loop. */
    for( i = 0; i < ( configNUMBER_OF_CORES + 1U ); i++ )
    {
        xTaskTCBs[ i ].uxPriority = tskIDLE_PRIORITY;
        xTaskTCBs[ i ].xStateListItem.pvOwner = &xTaskTCBs[ i ];
        xTaskTCBs[ i ].uxCoreAffinityMask = ( ( 1U << configNUMBER_OF_CORES ) - 1U );
        xTaskTCBs[ i ].uxTaskAttributes = -1;
        if( i < configNUMBER_OF_CORES )
        {
            /* Create idle tasks with equal number of cores. */
            pxCurrentTCBs[ i ] = &xTaskTCBs[ i ];
            xTaskTCBs[ i ].xTaskRunState = i;
            xTaskTCBs[ i ].xStateListItem.pxContainer = &pxReadyTasksLists[ tskIDLE_PRIORITY ];
            listINSERT_END( &pxReadyTasksLists[ tskIDLE_PRIORITY ], &xTaskTCBs[ i ].xStateListItem );
            uxCurrentNumberOfTasks = uxCurrentNumberOfTasks + 1;
        }
        else
        {
            /* Create one more idle task to be added to ready list. */
            xTaskTCBs[ i ].xTaskRunState = -1;  /* Set run state to taskTASK_NOT_RUNNING. */
        }
    }

    /* API calls. */
    prvAddNewTaskToReadyList( &xTaskTCBs[ configNUMBER_OF_CORES ] );

    /* Validateions. The run state of this task is still taskNOT_RUNNING ( -1 ). */
    configASSERT( xTaskTCBs[ configNUMBER_OF_CORES + 1U ].xTaskRunState == -1 );
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've included it, but commented out for now as the work to expose private/static functions and variables isn't yet merged or enabled for this subdirectory. Also, the priority to cover operationally unreachable code is I assume very low.

Copy link
Owner

@chinglee-iot chinglee-iot Feb 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discuss in the meeting,
https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/570ade4001e50adbf06a074582ea993af562e0e1/tasks.c#L107

#ifdef portREMOVE_STATIC_QUALIFIER
    #define static
#endif

These code already in kernel and the macro is defined in SMP test groups.
We should be able to access the private function and static variable in tasks.c file without problem.

The code snippet is for your referenced. If you want to use it to commit, at least we should be able to build without problem.

You can add the following extern to fix the compilation problem.

extern List_t pxReadyTasksLists[ configMAX_PRIORITIES ];
extern volatile UBaseType_t uxTopReadyPriority;
extern void prvAddNewTaskToReadyList( TCB_t * pxNewTCB );

the priority to cover operationally unreachable code is I assume very low.
I think you write this test case to cover this line.
If the priority is low, you can feedback in the slack channel and meeting.
We will discuss should we cover this line.

…out for now as the private functions are currently unlinkable.
@adam-scislowicz adam-scislowicz changed the title Add coverage for prvAddNewTaskToReadyList, vTaskCoreAffinitySet. Coverage tests for prvAddNewTaskToReadyList, vTaskCoreAffinitySet. Feb 20, 2023
@adam-scislowicz adam-scislowicz merged commit 943c89a into smp-unit-test-covg Feb 20, 2023
@adam-scislowicz adam-scislowicz deleted the adammds/smp-unit-test-covg branch February 20, 2023 20:46
chinglee-iot added a commit that referenced this pull request Mar 17, 2023
Update single priority timeslice to sync with JAMA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants