Skip to content

Commit 4441405

Browse files
authored
Update single core CMBC and unit test (FreeRTOS#1045)
This PR fixes CBMC and unit test for single core FreeRTOS in the FreeRTOS-Kernel PR - FreeRTOS/FreeRTOS-Kernel#716. - xYieldPendings and xIdleTaskHandles are now an array. Update in FreeRTOS unit test. - Update CBMC patches.
1 parent 80c6479 commit 4441405

8 files changed

+99
-72
lines changed

FreeRTOS/Test/CBMC/patches/0005-Remove-volatile-qualifier-from-tasks-variables.patch

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,40 @@ In the case of `uxPendedTicks`, a non-volatile copy of the variable is done
1111
before the following loop in tasks.c (lines 2231-2255):
1212

1313
{
14-
UBaseType_t uxPendedCounts = uxPendedTicks; /* Non-volatile copy. */
14+
UBaseType_t uxPendedCounts = uxPendedTicks; /* Non-volatile copy. */
1515

16-
if( uxPendedCounts > ( UBaseType_t ) 0U )
17-
{
18-
do
19-
{
20-
if( xTaskIncrementTick() != pdFALSE )
21-
{
22-
xYieldPending = pdTRUE;
23-
}
24-
else
25-
{
26-
mtCOVERAGE_TEST_MARKER();
27-
}
28-
--uxPendedCounts;
29-
} while( uxPendedCounts > ( UBaseType_t ) 0U );
16+
if( uxPendedCounts > ( UBaseType_t ) 0U )
17+
{
18+
do
19+
{
20+
if( xTaskIncrementTick() != pdFALSE )
21+
{
22+
xYieldPending = pdTRUE;
23+
}
24+
else
25+
{
26+
mtCOVERAGE_TEST_MARKER();
27+
}
28+
--uxPendedCounts;
29+
} while( uxPendedCounts > ( UBaseType_t ) 0U );
3030

31-
uxPendedTicks = 0;
32-
}
33-
else
34-
{
35-
mtCOVERAGE_TEST_MARKER();
36-
}
31+
uxPendedTicks = 0;
32+
}
33+
else
34+
{
35+
mtCOVERAGE_TEST_MARKER();
36+
}
3737
}
3838

3939
Here, `uxPendedTicks` could return any value, making it impossible to unwind
4040
(or unroll) this loop in CBMC. Therefore, we require `uxPendedTicks` to behave
4141
as a regular variable so that the loop can be unwound.
4242

4343
diff --git a/FreeRTOS/Source/tasks.c b/FreeRTOS/Source/tasks.c
44-
index 0e7a56c60..b29c19ea5 100644
44+
index b991b7da4..a220cf0bf 100644
4545
--- a/FreeRTOS/Source/tasks.c
4646
+++ b/FreeRTOS/Source/tasks.c
47-
@@ -339,8 +339,8 @@ portDONT_DISCARD PRIVILEGED_DATA TCB_t * volatile pxCurrentTCB = NULL;
47+
@@ -399,8 +399,8 @@ typedef tskTCB TCB_t;
4848
PRIVILEGED_DATA static List_t pxReadyTasksLists[ configMAX_PRIORITIES ]; /**< Prioritised ready tasks. */
4949
PRIVILEGED_DATA static List_t xDelayedTaskList1; /**< Delayed tasks. */
5050
PRIVILEGED_DATA static List_t xDelayedTaskList2; /**< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */
@@ -53,14 +53,14 @@ index 0e7a56c60..b29c19ea5 100644
5353
+PRIVILEGED_DATA static List_t * pxDelayedTaskList; /**< Points to the delayed task list currently being used. */
5454
+PRIVILEGED_DATA static List_t * pxOverflowDelayedTaskList; /**< Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count. */
5555
PRIVILEGED_DATA static List_t xPendingReadyList; /**< Tasks that have been readied while the scheduler was suspended. They will be moved to the ready list when the scheduler is resumed. */
56-
56+
5757
#if ( INCLUDE_vTaskDelete == 1 )
58-
@@ -367,7 +367,7 @@ PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType
58+
@@ -427,7 +427,7 @@ PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType
5959
PRIVILEGED_DATA static volatile TickType_t xTickCount = ( TickType_t ) configINITIAL_TICK_COUNT;
6060
PRIVILEGED_DATA static volatile UBaseType_t uxTopReadyPriority = tskIDLE_PRIORITY;
6161
PRIVILEGED_DATA static volatile BaseType_t xSchedulerRunning = pdFALSE;
6262
-PRIVILEGED_DATA static volatile TickType_t xPendedTicks = ( TickType_t ) 0U;
6363
+PRIVILEGED_DATA static TickType_t xPendedTicks = ( TickType_t ) 0U;
64-
PRIVILEGED_DATA static volatile BaseType_t xYieldPending = pdFALSE;
64+
PRIVILEGED_DATA static volatile BaseType_t xYieldPendings[ configNUMBER_OF_CORES ] = { pdFALSE };
6565
PRIVILEGED_DATA static volatile BaseType_t xNumOfOverflows = ( BaseType_t ) 0;
6666
PRIVILEGED_DATA static UBaseType_t uxTaskNumber = ( UBaseType_t ) 0U;

FreeRTOS/Test/CBMC/patches/0005-remove-static-from-prvCopyDataToQueue.patch

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
diff --git a/FreeRTOS/Source/queue.c b/FreeRTOS/Source/queue.c
2-
index 08d3799da..6681a34f1 100644
2+
index e87db0f45..1ffbf1191 100644
33
--- a/FreeRTOS/Source/queue.c
44
+++ b/FreeRTOS/Source/queue.c
5-
@@ -193,7 +193,7 @@ static BaseType_t prvIsQueueFull( const Queue_t * pxQueue ) PRIVILEGED_FUNCTION;
5+
@@ -197,7 +197,7 @@ static BaseType_t prvIsQueueFull( const Queue_t * pxQueue ) PRIVILEGED_FUNCTION;
66
* Copies an item into the queue, either at the front of the queue or the
77
* back of the queue.
88
*/
99
-static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
1010
+BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
1111
const void * pvItemToQueue,
1212
const BaseType_t xPosition ) PRIVILEGED_FUNCTION;
13-
14-
@@ -2157,7 +2157,7 @@ void vQueueDelete( QueueHandle_t xQueue )
13+
14+
@@ -2263,7 +2263,7 @@ UBaseType_t uxQueueGetQueueItemSize( QueueHandle_t xQueue ) /* PRIVILEGED_FUNCTI
1515
#endif /* configUSE_MUTEXES */
1616
/*-----------------------------------------------------------*/
17-
17+
1818
-static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
1919
+BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
2020
const void * pvItemToQueue,

FreeRTOS/Test/CBMC/patches/0006-Remove-static-from-prvNotifyQueueSetContainer.patch

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
diff --git a/FreeRTOS/Source/queue.c b/FreeRTOS/Source/queue.c
2-
index 17a6964e..24a40c29 100644
2+
index e87db0f45..ec9cc78a9 100644
33
--- a/FreeRTOS/Source/queue.c
44
+++ b/FreeRTOS/Source/queue.c
5-
@@ -207,7 +207,7 @@ static void prvCopyDataFromQueue( Queue_t * const pxQueue, void * const pvBuffer
6-
* Checks to see if a queue is a member of a queue set, and if so, notifies
7-
* the queue set that the queue contains data.
8-
*/
9-
- static BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue ) PRIVILEGED_FUNCTION;
10-
+ BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue ) PRIVILEGED_FUNCTION;
5+
@@ -213,7 +213,7 @@ static void prvCopyDataFromQueue( Queue_t * const pxQueue,
6+
* Checks to see if a queue is a member of a queue set, and if so, notifies
7+
* the queue set that the queue contains data.
8+
*/
9+
- static BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue ) PRIVILEGED_FUNCTION;
10+
+ BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue ) PRIVILEGED_FUNCTION;
1111
#endif
12-
12+
1313
/*
14-
@@ -2957,7 +2957,7 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
14+
@@ -3121,7 +3121,7 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
1515

1616
#if ( configUSE_QUEUE_SETS == 1 )
1717

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
diff --git a/FreeRTOS/Source/queue.c b/FreeRTOS/Source/queue.c
2-
index 17a6964e..60ea3e69 100644
2+
index e87db0f45..98f77012f 100644
33
--- a/FreeRTOS/Source/queue.c
44
+++ b/FreeRTOS/Source/queue.c
5-
@@ -175,7 +175,7 @@ typedef xQUEUE Queue_t;
5+
@@ -177,7 +177,7 @@ typedef xQUEUE Queue_t;
66
* to indicate that a task may require unblocking. When the queue in unlocked
77
* these lock counts are inspected, and the appropriate action taken.
88
*/
99
-static void prvUnlockQueue( Queue_t * const pxQueue ) PRIVILEGED_FUNCTION;
1010
+void prvUnlockQueue( Queue_t * const pxQueue ) PRIVILEGED_FUNCTION;
11-
11+
1212
/*
1313
* Uses a critical section to determine if there is any data in a queue.
14-
@@ -2175,7 +2175,7 @@ static void prvCopyDataFromQueue( Queue_t * const pxQueue, void * const pvBuffer
14+
@@ -2367,7 +2367,7 @@ static void prvCopyDataFromQueue( Queue_t * const pxQueue,
1515
}
1616
/*-----------------------------------------------------------*/
17-
17+
1818
-static void prvUnlockQueue( Queue_t * const pxQueue )
1919
+void prvUnlockQueue( Queue_t * const pxQueue )
2020
{
21-
/* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */
22-
21+
/* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */
22+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
diff --git a/FreeRTOS/Source/queue.c b/FreeRTOS/Source/queue.c
2+
index e87db0f45..a5f1ac9d0 100644
3+
--- a/FreeRTOS/Source/queue.c
4+
+++ b/FreeRTOS/Source/queue.c
5+
@@ -88,12 +88,14 @@ typedef struct SemaphoreData
6+
/* If the cooperative scheduler is being used then a yield should not be
7+
* performed just because a higher priority task has been woken. */
8+
#define queueYIELD_IF_USING_PREEMPTION()
9+
-#else
10+
- #if ( configNUMBER_OF_CORES == 1 )
11+
- #define queueYIELD_IF_USING_PREEMPTION() portYIELD_WITHIN_API()
12+
- #else /* #if ( configNUMBER_OF_CORES == 1 ) */
13+
- #define queueYIELD_IF_USING_PREEMPTION() vTaskYieldWithinAPI()
14+
- #endif /* #if ( configNUMBER_OF_CORES == 1 ) */
15+
+#endif
16+
+
17+
+#if ( configNUMBER_OF_CORES == 1 ) && ( configUSE_PREEMPTION == 1 )
18+
+ #define queueYIELD_IF_USING_PREEMPTION() portYIELD_WITHIN_API()
19+
+#endif
20+
+
21+
+#if ( configNUMBER_OF_CORES > 1 ) && ( configUSE_PREEMPTION == 1 )
22+
+ #define queueYIELD_IF_USING_PREEMPTION() vTaskYieldWithinAPI()
23+
#endif
24+
25+
/*

FreeRTOS/Test/CBMC/proofs/Task/TaskIncrementTick/tasks_test_access_functions.h

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
/*
2-
* FreeRTOS memory safety proofs with CBMC.
3-
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* FreeRTOS V202212.00
3+
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
44
*
5-
* Permission is hereby granted, free of charge, to any person
6-
* obtaining a copy of this software and associated documentation
7-
* files (the "Software"), to deal in the Software without
8-
* restriction, including without limitation the rights to use, copy,
9-
* modify, merge, publish, distribute, sublicense, and/or sell copies
10-
* of the Software, and to permit persons to whom the Software is
11-
* furnished to do so, subject to the following conditions:
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
* this software and associated documentation files (the "Software"), to deal in
7+
* the Software without restriction, including without limitation the rights to
8+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
* the Software, and to permit persons to whom the Software is furnished to do so,
10+
* subject to the following conditions:
1211
*
13-
* The above copyright notice and this permission notice shall be
14-
* included in all copies or substantial portions of the Software.
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
1514
*
16-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19-
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20-
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21-
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22-
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23-
* SOFTWARE.
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2421
*
25-
* https://aws.amazon.com/freertos
2622
* https://www.FreeRTOS.org
23+
* https://github.com/FreeRTOS
24+
*
2725
*/
2826

2927
#include "cbmc.h"
@@ -77,7 +75,7 @@ void vSetGlobalVariables()
7775
{
7876
xPendedTicks = nondet_ubasetype();
7977
uxSchedulerSuspended = nondet_ubasetype();
80-
xYieldPending = nondet_basetype();
78+
xYieldPendings[ 0 ] = nondet_basetype();
8179
xTickCount = nondet_ticktype();
8280
}
8381

FreeRTOS/Test/CMock/tasks/tasks_1_utest.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ extern volatile TickType_t xTickCount;
6565
extern volatile UBaseType_t uxTopReadyPriority;
6666
extern volatile BaseType_t xSchedulerRunning;
6767
extern volatile TickType_t xPendedTicks;
68-
extern volatile BaseType_t xYieldPending;
68+
extern volatile BaseType_t xYieldPendings[];
69+
#define xYieldPending xYieldPendings[ 0 ]
6970
extern volatile BaseType_t xNumOfOverflows;
7071
extern UBaseType_t uxTaskNumber;
7172
extern volatile TickType_t xNextTaskUnblockTime;
72-
extern TaskHandle_t xIdleTaskHandle;
73+
extern TaskHandle_t xIdleTaskHandles[];
74+
#define xIdleTaskHandle xIdleTaskHandles[ 0 ]
7375
extern volatile UBaseType_t uxSchedulerSuspended;
7476

7577
/* ============================= DEFINES ================================== */

FreeRTOS/Test/CMock/tasks/tasks_2_utest.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ extern volatile TickType_t xTickCount;
6464
extern volatile UBaseType_t uxTopReadyPriority;
6565
extern volatile BaseType_t xSchedulerRunning;
6666
extern volatile TickType_t xPendedTicks;
67-
extern volatile BaseType_t xYieldPending;
67+
extern volatile BaseType_t xYieldPendings[];
68+
#define xYieldPending xYieldPendings[ 0 ]
6869
extern volatile BaseType_t xNumOfOverflows;
6970
extern UBaseType_t uxTaskNumber;
7071
extern volatile TickType_t xNextTaskUnblockTime;
71-
extern TaskHandle_t xIdleTaskHandle;
72+
extern TaskHandle_t xIdleTaskHandles[];
73+
#define xIdleTaskHandle xIdleTaskHandles[ 0 ]
7274
extern volatile UBaseType_t uxSchedulerSuspended;
7375

7476

0 commit comments

Comments
 (0)