Skip to content

Commit fdf4695

Browse files
chinglee-iotUbuntuaggarg
authored
Adding SMP coverity example (#1039)
* Adding SMP coverity example * Add coverity scan flow * Fix format * Update README.md * Code review suggestions Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> --------- Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> Co-authored-by: Ubuntu <ubuntu@ip-172-31-34-245.ap-northeast-1.compute.internal> Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
1 parent 2a014ce commit fdf4695

File tree

8 files changed

+109
-1
lines changed

8 files changed

+109
-1
lines changed

.github/workflows/coverity_scan.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,42 @@ jobs:
8686
echo "::endgroup::"
8787
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }} "
8888
echo "${COV_SCAN_UPLOAD_STATUS}" | grep -q -e 'Build successfully submitted' || echo >&2 "Error submitting build for analysis: ${COV_SCAN_UPLOAD_STATUS}"
89+
90+
- env:
91+
stepName: Coverity Build for SMP FreeRTOS
92+
COVERITY_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
93+
COVERITY_EMAIL: ${{ secrets.COVERITY_SCAN_EMAIL }}
94+
shell: bash
95+
run: |
96+
# ${{ env.stepName }}
97+
echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}"
98+
99+
export PATH="$PATH:${{env.cov_scan_path}}"
100+
cmake -S ./examples/cmake_example/ -B build -DFREERTOS_SMP_EXAMPLE=1
101+
cd build
102+
cov-build --dir cov-int make -j
103+
# Move the report out of the build directory
104+
tar czvf ../gcc_freertos_kernel_smp_sample_build.tgz cov-int
105+
106+
echo "::endgroup::"
107+
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }} "
108+
109+
- env:
110+
stepName: Upload FreeRTOS SMP Coverity Report for Scan
111+
COVERITY_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
112+
COVERITY_EMAIL: ${{ secrets.COVERITY_SCAN_EMAIL }}
113+
shell: bash
114+
run: |
115+
# ${{ env.stepName }}
116+
echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}"
117+
118+
COV_SCAN_UPLOAD_STATUS=$(curl --form token=${COVERITY_TOKEN} \
119+
--form email=${COVERITY_EMAIL} \
120+
--form file=@gcc_freertos_kernel_smp_sample_build.tgz \
121+
--form version="Mainline" \
122+
--form description="FreeRTOS Kernel SMP Commit Scan" \
123+
https://scan.coverity.com/builds?project=FreeRTOS-Kernel)
124+
125+
echo "::endgroup::"
126+
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }} "
127+
echo "${COV_SCAN_UPLOAD_STATUS}" | grep -q -e 'Build successfully submitted' || echo >&2 "Error submitting build for analysis: ${COV_SCAN_UPLOAD_STATUS}"

MISRA.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ with ( Assuming rule 8.4 violation; with justification in point 1 ):
1818
grep 'MISRA Ref 8.4.1' . -rI
1919
```
2020

21+
#### Dir 4.7
22+
MISRA C:2012 Dir 4.7: If a function returns error information, then that error
23+
information shall be tested.
24+
25+
_Ref 4.7.1_
26+
- `taskENTER_CRITICAL_FROM_ISR` returns the interrupt mask and not any error
27+
information. Therefore, there is no need test the return value.
28+
2129
#### Rule 8.4
2230

2331
MISRA C:2012 Rule 8.4: A compatible declaration shall be visible when an

event_groups.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,9 @@
529529

530530
traceENTER_xEventGroupGetBitsFromISR( xEventGroup );
531531

532+
/* MISRA Ref 4.7.1 [Return value shall be checked] */
533+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
534+
/* coverity[misra_c_2012_directive_4_7_violation] */
532535
uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
533536
{
534537
uxReturn = pxEventBits->uxEventBits;

examples/coverity/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ target_include_directories(freertos_config
2323
INTERFACE
2424
./)
2525

26+
if (DEFINED FREERTOS_SMP_EXAMPLE AND FREERTOS_SMP_EXAMPLE STREQUAL "1")
27+
message(STATUS "Build FreeRTOS SMP example")
28+
# Adding the following configurations to build SMP template port
29+
add_compile_options( -DconfigNUMBER_OF_CORES=2 -DconfigUSE_PASSIVE_IDLE_HOOK=0 )
30+
endif()
31+
2632
# Select the heap. Values between 1-5 will pick a heap.
2733
set(FREERTOS_HEAP "3" CACHE STRING "" FORCE)
2834

examples/coverity/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,16 @@ commands in a terminal:
3434
cov-configure --force --compiler cc --comptype gcc
3535
~~~
3636
2. Create the build files using CMake in a `build` directory:
37+
38+
Singe core FreeRTOS:
3739
~~~
3840
cmake -B build -S examples/coverity
3941
~~~
42+
43+
SMP FreeRTOS:
44+
~~~
45+
cmake -B build -S examples/coverity -DFREERTOS_SMP_EXAMPLE=1
46+
~~~
4047
3. Build the (pseudo) application:
4148
~~~
4249
cd build/
@@ -47,7 +54,7 @@ commands in a terminal:
4754
~~~
4855
cov-analyze --dir ./cov-out \
4956
--coding-standard-config ../examples/coverity/coverity_misra.config \
50-
--tu-pattern "file('[A-Za-z_]+\.c')"
57+
--tu-pattern "file('[A-Za-z_]+\.c') && ( ! file('main.c') ) && ( ! file('port.c') )"
5158
~~~
5259
5. Generate the HTML report:
5360
~~~

queue.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,9 @@ BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
11901190
* read, instead return a flag to say whether a context switch is required or
11911191
* not (i.e. has a task with a higher priority than us been woken by this
11921192
* post). */
1193+
/* MISRA Ref 4.7.1 [Return value shall be checked] */
1194+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
1195+
/* coverity[misra_c_2012_directive_4_7_violation] */
11931196
uxSavedInterruptStatus = ( UBaseType_t ) taskENTER_CRITICAL_FROM_ISR();
11941197
{
11951198
if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )
@@ -1365,6 +1368,9 @@ BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
13651368
* link: https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
13661369
portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
13671370

1371+
/* MISRA Ref 4.7.1 [Return value shall be checked] */
1372+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
1373+
/* coverity[misra_c_2012_directive_4_7_violation] */
13681374
uxSavedInterruptStatus = ( UBaseType_t ) taskENTER_CRITICAL_FROM_ISR();
13691375
{
13701376
const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
@@ -2055,6 +2061,9 @@ BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue,
20552061
* link: https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
20562062
portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
20572063

2064+
/* MISRA Ref 4.7.1 [Return value shall be checked] */
2065+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
2066+
/* coverity[misra_c_2012_directive_4_7_violation] */
20582067
uxSavedInterruptStatus = ( UBaseType_t ) taskENTER_CRITICAL_FROM_ISR();
20592068
{
20602069
const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
@@ -2153,6 +2162,9 @@ BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue,
21532162
* link: https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
21542163
portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
21552164

2165+
/* MISRA Ref 4.7.1 [Return value shall be checked] */
2166+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
2167+
/* coverity[misra_c_2012_directive_4_7_violation] */
21562168
uxSavedInterruptStatus = ( UBaseType_t ) taskENTER_CRITICAL_FROM_ISR();
21572169
{
21582170
/* Cannot block in an ISR, so check there is data available. */

stream_buffer.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,9 @@ BaseType_t xStreamBufferResetFromISR( StreamBufferHandle_t xStreamBuffer )
676676
#endif
677677

678678
/* Can only reset a message buffer if there are no tasks blocked on it. */
679+
/* MISRA Ref 4.7.1 [Return value shall be checked] */
680+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
681+
/* coverity[misra_c_2012_directive_4_7_violation] */
679682
uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
680683
{
681684
if( ( pxStreamBuffer->xTaskWaitingToReceive == NULL ) && ( pxStreamBuffer->xTaskWaitingToSend == NULL ) )
@@ -972,6 +975,9 @@ size_t xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer,
972975
/* Was a task waiting for the data? */
973976
if( prvBytesInBuffer( pxStreamBuffer ) >= pxStreamBuffer->xTriggerLevelBytes )
974977
{
978+
/* MISRA Ref 4.7.1 [Return value shall be checked] */
979+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
980+
/* coverity[misra_c_2012_directive_4_7_violation] */
975981
prvSEND_COMPLETE_FROM_ISR( pxStreamBuffer, pxHigherPriorityTaskWoken );
976982
}
977983
else
@@ -1245,6 +1251,9 @@ size_t xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer,
12451251
/* Was a task waiting for space in the buffer? */
12461252
if( xReceivedLength != ( size_t ) 0 )
12471253
{
1254+
/* MISRA Ref 4.7.1 [Return value shall be checked] */
1255+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
1256+
/* coverity[misra_c_2012_directive_4_7_violation] */
12481257
prvRECEIVE_COMPLETED_FROM_ISR( pxStreamBuffer, pxHigherPriorityTaskWoken );
12491258
}
12501259
else
@@ -1397,6 +1406,9 @@ BaseType_t xStreamBufferSendCompletedFromISR( StreamBufferHandle_t xStreamBuffer
13971406

13981407
configASSERT( pxStreamBuffer );
13991408

1409+
/* MISRA Ref 4.7.1 [Return value shall be checked] */
1410+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
1411+
/* coverity[misra_c_2012_directive_4_7_violation] */
14001412
uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
14011413
{
14021414
if( ( pxStreamBuffer )->xTaskWaitingToReceive != NULL )
@@ -1433,6 +1445,9 @@ BaseType_t xStreamBufferReceiveCompletedFromISR( StreamBufferHandle_t xStreamBuf
14331445

14341446
configASSERT( pxStreamBuffer );
14351447

1448+
/* MISRA Ref 4.7.1 [Return value shall be checked] */
1449+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
1450+
/* coverity[misra_c_2012_directive_4_7_violation] */
14361451
uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
14371452
{
14381453
if( ( pxStreamBuffer )->xTaskWaitingToSend != NULL )

tasks.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,6 +2666,9 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
26662666
* https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
26672667
portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
26682668

2669+
/* MISRA Ref 4.7.1 [Return value shall be checked] */
2670+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
2671+
/* coverity[misra_c_2012_directive_4_7_violation] */
26692672
uxSavedInterruptStatus = ( UBaseType_t ) taskENTER_CRITICAL_FROM_ISR();
26702673
{
26712674
/* If null is passed in here then it is the priority of the calling
@@ -2737,6 +2740,9 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
27372740
* https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
27382741
portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
27392742

2743+
/* MISRA Ref 4.7.1 [Return value shall be checked] */
2744+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
2745+
/* coverity[misra_c_2012_directive_4_7_violation] */
27402746
uxSavedInterruptStatus = ( UBaseType_t ) taskENTER_CRITICAL_FROM_ISR();
27412747
{
27422748
/* If null is passed in here then it is the base priority of the calling
@@ -3433,6 +3439,9 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
34333439
* https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
34343440
portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
34353441

3442+
/* MISRA Ref 4.7.1 [Return value shall be checked] */
3443+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
3444+
/* coverity[misra_c_2012_directive_4_7_violation] */
34363445
uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
34373446
{
34383447
if( prvTaskIsTaskSuspended( pxTCB ) != pdFALSE )
@@ -4989,6 +4998,9 @@ BaseType_t xTaskIncrementTick( void )
49894998

49904999
/* Save the hook function in the TCB. A critical section is required as
49915000
* the value can be accessed from an interrupt. */
5001+
/* MISRA Ref 4.7.1 [Return value shall be checked] */
5002+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
5003+
/* coverity[misra_c_2012_directive_4_7_violation] */
49925004
uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
49935005
{
49945006
xReturn = pxTCB->pxTaskTag;
@@ -7974,6 +7986,9 @@ TickType_t uxTaskResetEventItemValue( void )
79747986

79757987
pxTCB = xTaskToNotify;
79767988

7989+
/* MISRA Ref 4.7.1 [Return value shall be checked] */
7990+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
7991+
/* coverity[misra_c_2012_directive_4_7_violation] */
79777992
uxSavedInterruptStatus = ( UBaseType_t ) taskENTER_CRITICAL_FROM_ISR();
79787993
{
79797994
if( pulPreviousNotificationValue != NULL )
@@ -8133,6 +8148,9 @@ TickType_t uxTaskResetEventItemValue( void )
81338148

81348149
pxTCB = xTaskToNotify;
81358150

8151+
/* MISRA Ref 4.7.1 [Return value shall be checked] */
8152+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
8153+
/* coverity[misra_c_2012_directive_4_7_violation] */
81368154
uxSavedInterruptStatus = ( UBaseType_t ) taskENTER_CRITICAL_FROM_ISR();
81378155
{
81388156
ucOriginalNotifyState = pxTCB->ucNotifyState[ uxIndexToNotify ];

0 commit comments

Comments
 (0)