Skip to content

Commit 22d02e9

Browse files
authored
Add unit test coverage for vTaskPriorityDisinheritAfterTimeout (FreeRTOS#1382)
vTaskPriorityDisinheritAfterTimeout has been tweaked to reset the original priority upon entry. This change modifies unit tests to verify this
1 parent 4879cfd commit 22d02e9

File tree

3 files changed

+48
-16
lines changed

3 files changed

+48
-16
lines changed

FreeRTOS/Source

Submodule Source updated 120 files

FreeRTOS/Test/CMock/tasks/tasks_1_utest.c

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
#include <string.h>
5151
#include <stdlib.h>
5252

53-
5453
/* =========================== EXTERN VARIABLES =========================== */
5554
extern TCB_t * volatile pxCurrentTCB;
5655
extern List_t pxReadyTasksLists[ configMAX_PRIORITIES ];
@@ -115,15 +114,16 @@ extern volatile UBaseType_t uxSchedulerSuspended;
115114
( list_item2 ).pxContainer = &( list ); \
116115
} while( 0 )
117116

118-
#define taskNOT_WAITING_NOTIFICATION ( ( uint8_t ) 0 )
119-
#define taskWAITING_NOTIFICATION ( ( uint8_t ) 1 )
120-
#define taskNOTIFICATION_RECEIVED ( ( uint8_t ) 2 )
121-
#define TCB_ARRAY 10 /* simulate up to 10 tasks: add more if needed */
117+
#define taskNOT_WAITING_NOTIFICATION ( ( uint8_t ) 0 )
118+
#define taskWAITING_NOTIFICATION ( ( uint8_t ) 1 )
119+
#define taskNOTIFICATION_RECEIVED ( ( uint8_t ) 2 )
120+
#define TCB_ARRAY 10 /* simulate up to 10 tasks: add more if needed */
121+
#define taskEVENT_LIST_ITEM_VALUE_IN_USE ( ( uint32_t ) 0x80000000U )
122122

123123
/**
124124
* @brief CException code for when a configASSERT should be intercepted.
125125
*/
126-
#define configASSERT_E 0xAA101
126+
#define configASSERT_E 0xAA101
127127

128128
/* =========================== GLOBAL VARIABLES =========================== */
129129
static StaticTask_t xIdleTaskTCB;
@@ -1503,7 +1503,7 @@ void test_vTaskPrioritySet_success_gt_max_prio( void )
15031503
ptcb = ( TCB_t * ) taskHandle;
15041504

15051505
/* expectations */
1506-
listGET_LIST_ITEM_VALUE_ExpectAnyArgsAndReturn( 0x80000000UL );
1506+
listGET_LIST_ITEM_VALUE_ExpectAnyArgsAndReturn( taskEVENT_LIST_ITEM_VALUE_IN_USE );
15071507
listIS_CONTAINED_WITHIN_ExpectAndReturn( &pxReadyTasksLists[ 3 ],
15081508
&( ptcb->xStateListItem ),
15091509
pdTRUE );
@@ -1528,7 +1528,7 @@ void test_vTaskPrioritySet_success_call_current_null( void )
15281528
ptcb = ( TCB_t * ) taskHandle;
15291529

15301530
/* expectations */
1531-
listGET_LIST_ITEM_VALUE_ExpectAnyArgsAndReturn( 0x80000000UL );
1531+
listGET_LIST_ITEM_VALUE_ExpectAnyArgsAndReturn( taskEVENT_LIST_ITEM_VALUE_IN_USE );
15321532
listIS_CONTAINED_WITHIN_ExpectAndReturn( &pxReadyTasksLists[ 3 ],
15331533
&( ptcb->xStateListItem ),
15341534
pdTRUE );
@@ -1638,7 +1638,7 @@ void test_vTaskPrioritySet_success_gt_curr_prio_diff_base( void )
16381638
ptcb = ( TCB_t * ) taskHandle;
16391639
TEST_ASSERT_EQUAL_PTR( pxCurrentTCB, taskHandle2 );
16401640
/* task handle will inherit the priorit of taskHandle2 */
1641-
listGET_LIST_ITEM_VALUE_ExpectAnyArgsAndReturn( 0x80000000UL );
1641+
listGET_LIST_ITEM_VALUE_ExpectAnyArgsAndReturn( taskEVENT_LIST_ITEM_VALUE_IN_USE );
16421642
listIS_CONTAINED_WITHIN_ExpectAndReturn( &pxReadyTasksLists[ 3 ],
16431643
&( taskHandle->xStateListItem ),
16441644
pdFALSE );
@@ -1677,7 +1677,7 @@ void test_vTaskPrioritySet_success_lt_curr_prio_diff_base( void )
16771677
ptcb = ( TCB_t * ) taskHandle;
16781678
TEST_ASSERT_EQUAL_PTR( pxCurrentTCB, taskHandle2 );
16791679
/* task handle will inherit the priorit of taskHandle2 */
1680-
listGET_LIST_ITEM_VALUE_ExpectAnyArgsAndReturn( 0x80000000UL );
1680+
listGET_LIST_ITEM_VALUE_ExpectAnyArgsAndReturn( taskEVENT_LIST_ITEM_VALUE_IN_USE );
16811681
listIS_CONTAINED_WITHIN_ExpectAndReturn( &pxReadyTasksLists[ 3 ],
16821682
&( taskHandle->xStateListItem ),
16831683
pdFALSE );
@@ -3884,7 +3884,7 @@ void test_vTaskPlaceOnUnorderedEventList( void )
38843884
uxSchedulerSuspended = pdTRUE;
38853885

38863886
/* Expectations */
3887-
listSET_LIST_ITEM_VALUE_Expect( &ptcb->xEventListItem, 32 | 0x80000000UL );
3887+
listSET_LIST_ITEM_VALUE_Expect( &ptcb->xEventListItem, 32 | taskEVENT_LIST_ITEM_VALUE_IN_USE );
38883888
listINSERT_END_Expect( &eventList, &ptcb->xEventListItem );
38893889
/* prvAddCurrentTaskToDelayedList */
38903890
uxListRemove_ExpectAndReturn( &ptcb->xStateListItem, 1 );
@@ -4031,7 +4031,7 @@ void test_vTaskRemoveFromUnorderedEventList( void )
40314031
ptcb = task_handle;
40324032

40334033
/* Expectations */
4034-
listSET_LIST_ITEM_VALUE_Expect( &list_item, xItemValue | 0x80000000UL );
4034+
listSET_LIST_ITEM_VALUE_Expect( &list_item, xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE );
40354035
listGET_LIST_ITEM_OWNER_ExpectAndReturn( &list_item, tcb );
40364036
listREMOVE_ITEM_Expect( &list_item );
40374037
/* prvResetNextTaskUnblockTime */
@@ -4069,7 +4069,7 @@ void test_vTaskRemoveFromUnorderedEventList_yielding( void )
40694069
TEST_ASSERT_EQUAL( task_handle2, pxCurrentTCB );
40704070

40714071
/* Expectations */
4072-
listSET_LIST_ITEM_VALUE_Expect( &list_item, xItemValue | 0x80000000UL );
4072+
listSET_LIST_ITEM_VALUE_Expect( &list_item, xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE );
40734073
listGET_LIST_ITEM_OWNER_ExpectAndReturn( &list_item, tcb );
40744074
/*uxListRemove_ExpectAndReturn( &list_item, pdTRUE ); */
40754075
listREMOVE_ITEM_Expect( &( list_item ) );
@@ -4813,35 +4813,67 @@ void test_vTaskPriorityDisinheritAfterTimeout_fail_null_handle()
48134813
void test_vTaskPriorityDisinheritAfterTimeout_success()
48144814
{
48154815
TaskHandle_t mutex_holder;
4816+
UBaseType_t inheritedPriority = 5U;
4817+
/* Tasks at priority 1-3 are ready */
4818+
UBaseType_t lowPriorityTasksReady = ( UBaseType_t ) ( ( 1 << 1 ) | ( 1 << 2 ) | ( 1 << 3 ) );
48164819

48174820
/* Setup */
48184821
create_task_priority = 4;
48194822
mutex_holder = create_task();
48204823
mutex_holder->uxMutexesHeld = 1;
4824+
mutex_holder->uxPriority = inheritedPriority;
4825+
/* Now mark task priority 5 as ready */
4826+
uxTopReadyPriority = ( UBaseType_t ) ( ( 1 << inheritedPriority ) | lowPriorityTasksReady );
48214827
/* Expectations */
4828+
listGET_LIST_ITEM_VALUE_ExpectAndReturn( &mutex_holder->xEventListItem, taskEVENT_LIST_ITEM_VALUE_IN_USE );
4829+
listIS_CONTAINED_WITHIN_ExpectAndReturn( &pxReadyTasksLists[ inheritedPriority ],
4830+
&mutex_holder->xStateListItem,
4831+
pdTRUE );
4832+
uxListRemove_ExpectAndReturn( &mutex_holder->xStateListItem, 0 );
4833+
/* prvAddTaskToReadyList */
4834+
listINSERT_END_Expect( &pxReadyTasksLists[ mutex_holder->uxBasePriority ],
4835+
&mutex_holder->xStateListItem );
48224836
/* API Call */
48234837
vTaskPriorityDisinheritAfterTimeout( mutex_holder,
48244838
create_task_priority - 1 );
48254839
/* Validations */
48264840
TEST_ASSERT_EQUAL( create_task_priority, mutex_holder->uxPriority );
48274841
TEST_ASSERT_EQUAL( create_task_priority, mutex_holder->uxBasePriority );
4842+
/* Priority is reset back to 4, we should expect tasks 4-1 to be ready */
4843+
TEST_ASSERT_EQUAL( uxTopReadyPriority, ( UBaseType_t ) ( ( 1 << create_task_priority ) | lowPriorityTasksReady ) );
48284844
}
48294845

48304846
void test_vTaskPriorityDisinheritAfterTimeout_success2()
48314847
{
48324848
TaskHandle_t mutex_holder;
4849+
UBaseType_t inheritedPriority = 6U;
4850+
/* Task at priority 5 is ready */
4851+
UBaseType_t priorityFiveTaskReady = ( UBaseType_t ) ( 1 << 5 );
48334852

48344853
/* Setup */
48354854
create_task_priority = 4;
48364855
mutex_holder = create_task();
48374856
mutex_holder->uxMutexesHeld = 1;
4857+
mutex_holder->uxPriority = inheritedPriority;
4858+
/* Now mark task priority 6 as ready */
4859+
uxTopReadyPriority = ( UBaseType_t ) ( ( 1 << inheritedPriority ) | priorityFiveTaskReady );
48384860
/* Expectations */
4861+
listGET_LIST_ITEM_VALUE_ExpectAndReturn( &mutex_holder->xEventListItem, taskEVENT_LIST_ITEM_VALUE_IN_USE );
4862+
listIS_CONTAINED_WITHIN_ExpectAndReturn( &pxReadyTasksLists[ inheritedPriority ],
4863+
&mutex_holder->xStateListItem,
4864+
pdTRUE );
4865+
uxListRemove_ExpectAndReturn( &mutex_holder->xStateListItem, 0 );
4866+
/* prvAddTaskToReadyList */
4867+
listINSERT_END_Expect( &pxReadyTasksLists[ mutex_holder->uxBasePriority ],
4868+
&mutex_holder->xStateListItem );
48394869
/* API Call */
48404870
vTaskPriorityDisinheritAfterTimeout( mutex_holder,
48414871
create_task_priority );
48424872
/* Validations */
48434873
TEST_ASSERT_EQUAL( create_task_priority, mutex_holder->uxPriority );
48444874
TEST_ASSERT_EQUAL( create_task_priority, mutex_holder->uxBasePriority );
4875+
/* Priority is reset back to 4, we should expect tasks 5-4 to be ready */
4876+
TEST_ASSERT_EQUAL( uxTopReadyPriority, ( UBaseType_t ) ( ( 1 << create_task_priority ) | priorityFiveTaskReady ) );
48454877
}
48464878

48474879
void test_vTaskPriorityDisinheritAfterTimeout_success3()
@@ -4870,7 +4902,7 @@ void test_vTaskPriorityDisinheritAfterTimeout_success4()
48704902
mutex_holder = create_task();
48714903
mutex_holder->uxMutexesHeld = 1;
48724904
/* Expectations */
4873-
listGET_LIST_ITEM_VALUE_ExpectAndReturn( &mutex_holder->xEventListItem, 0x80000000UL );
4905+
listGET_LIST_ITEM_VALUE_ExpectAndReturn( &mutex_holder->xEventListItem, taskEVENT_LIST_ITEM_VALUE_IN_USE );
48744906
listIS_CONTAINED_WITHIN_ExpectAndReturn( &pxReadyTasksLists[ mutex_holder->uxPriority ],
48754907
&mutex_holder->xStateListItem,
48764908
pdFALSE );

manifest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ license: "MIT"
55

66
dependencies:
77
- name: "FreeRTOS-Kernel"
8-
version: "0030d609a"
8+
version: "1dbc776"
99
repository:
1010
type: "git"
1111
url: "https://github.com/FreeRTOS/FreeRTOS-Kernel.git"

0 commit comments

Comments
 (0)