Skip to content

Commit

Permalink
Merge branch 'main' into fix_misra_7_2
Browse files Browse the repository at this point in the history
  • Loading branch information
aggarg authored Dec 6, 2023
2 parents 16a1a36 + 71d86f9 commit 1f4b5a1
Show file tree
Hide file tree
Showing 195 changed files with 13,002 additions and 21,518 deletions.
65 changes: 0 additions & 65 deletions .github/actions/url_verifier.sh

This file was deleted.

15 changes: 3 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
- uses: actions/checkout@v3
- name: Check Formatting of FreeRTOS-Kernel Files
uses: FreeRTOS/CI-CD-Github-Actions/formatting@main
with:
exclude-dirs: portable

spell-check:
runs-on: ubuntu-latest
Expand All @@ -30,18 +32,7 @@ jobs:
- name: Clone This Repo
uses: actions/checkout@v3
- name: Link Verification
uses: FreeRTOS/CI-CD-Github-Actions/link-verifier@v2

url-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
path: ./kernel

- name: URL Checker
run: |
bash kernel/.github/actions/url_verifier.sh kernel
uses: FreeRTOS/CI-CD-Github-Actions/link-verifier@main

verify-manifest:
runs-on: ubuntu-latest
Expand Down
69 changes: 55 additions & 14 deletions .github/workflows/coverity_scan.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,88 @@
name: FreeRTOS-Kernel Coverity Scan
name: Coverity Scan
on:
schedule: ## Scheduled to run at 1:15 AM UTC daily.
- cron: '15 1 * * *'
# Run on every commit to mainline
push:
branches: main
# Allow manual running of the scan
workflow_dispatch:

env:
bashPass: \033[32;1mPASSED -
bashInfo: \033[33;1mINFO -
bashFail: \033[31;1mFAILED -
bashEnd: \033[0m

jobs:

Coverity-Scan:
if: ( github.repository == 'FreeRTOS/FreeRTOS-Kernel' )
name: Coverity Scan
runs-on: ubuntu-latest
steps:
- name: Checkout the Repository
uses: actions/checkout@v3

- name: Install Build Essentials
- env:
stepName: Install Build Essentials
shell: bash
run: |
# ${{ env.stepName }}
echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}"
sudo apt-get -y update
sudo apt-get -y install build-essential
- name: Install Coverity Build
shell: bash
env:
echo "::endgroup::"
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
- env:
stepName: Install Coverity Build
COVERITY_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
shell: bash
run: |
# ${{ env.stepName }}
echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}"
wget -nv -qO- https://scan.coverity.com/download/linux64 --post-data "token=${COVERITY_TOKEN}&project=FreeRTOS-Kernel" | tar -zx --one-top-level=cov_scan --strip-components 1
echo "cov_scan_path=$(pwd)/cov_scan/bin" >> $GITHUB_ENV
- name: Coverity Build & Upload for Scan
shell: bash
env:
echo "::endgroup::"
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }} "
- env:
stepName: Coverity Build
COVERITY_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
COVERITY_EMAIL: ${{ secrets.COVERITY_SCAN_EMAIL }}
shell: bash
run: |
# ${{ env.stepName }}
echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}"
export PATH="$PATH:${{env.cov_scan_path}}"
cmake -S ./examples/cmake_example/ -B build
cd build
cov-build --dir cov-int make -j
tar czvf gcc_freertos_kerenl_sample_build.tgz cov-int
# Move the report out of the build directory
tar czvf ../gcc_freertos_kernel_sample_build.tgz cov-int
echo "::endgroup::"
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }} "
- env:
stepName: Upload Coverity Report for Scan
COVERITY_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
COVERITY_EMAIL: ${{ secrets.COVERITY_SCAN_EMAIL }}
shell: bash
run: |
# ${{ env.stepName }}
echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}"
COV_SCAN_UPLOAD_STATUS=$(curl --form token=${COVERITY_TOKEN} \
--form email=${COVERITY_EMAIL} \
--form file=@gcc_freertos_kerenl_sample_build.tgz \
--form file=@gcc_freertos_kernel_sample_build.tgz \
--form version="Mainline" \
--form description="FreeRTOS Kernel Nightly Scan" \
--form description="FreeRTOS Kernel Commit Scan" \
https://scan.coverity.com/builds?project=FreeRTOS-Kernel)
echo "::endgroup::"
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }} "
echo "${COV_SCAN_UPLOAD_STATUS}" | grep -q -e 'Build successfully submitted' || echo >&2 "Error submitting build for analysis: ${COV_SCAN_UPLOAD_STATUS}"
4 changes: 3 additions & 1 deletion .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Apply Formatting Fix
id: check-formatting
uses: FreeRTOS/CI-CD-Github-Actions/formatting-bot@main
id: check-formatting
with:
exclude-dirs: portable
7 changes: 7 additions & 0 deletions .github/workflows/kernel-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ jobs:
cmake -S . -B build
cmake --build build
- name: Build CMake SMP Example Demo
shell: bash
working-directory: examples/cmake_example
run: |
cmake -S . -B build -DFREERTOS_SMP_EXAMPLE=1
cmake --build build
MSP430-GCC:
name: GNU MSP430 Toolchain
runs-on: ubuntu-latest
Expand Down
79 changes: 66 additions & 13 deletions MISRA.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,73 @@ grep 'MISRA Ref 8.4.1' . -rI

#### Rule 8.4

MISRA C:2012 Rule 8.4: A compatible declaration shall be visible when an
object or function with external linkage is defined.

_Ref 8.4.1_

- MISRA C:2012 Rule 8.4: A compatible declaration shall be visible when an
object or function with external linkage is defined.
This rule requires that a compatible declaration is made available
in a header file when an object with external linkage is defined.
pxCurrentTCB(s) is defined with external linkage but it is only
referenced from the assembly code in the port files. Therefore, adding
a declaration in header file is not useful as the assembly code will
still need to declare it separately.
- This rule requires that a compatible declaration is made available
in a header file when an object with external linkage is defined.
pxCurrentTCB(s) is defined with external linkage but it is only
referenced from the assembly code in the port files. Therefore, adding
a declaration in header file is not useful as the assembly code will
still need to declare it separately.


#### Rule 11.3

MISRA C:2012 Rule 11.3: A cast shall not be performed between a pointer to
object type and a pointer to a different object type.

_Ref 11.3.1_
- This rule prohibits casting a pointer to object into a pointer to a
different object because it may result in an incorrectly aligned pointer,
leading to undefined behavior. Even if the casting produces a correctly
aligned pointer, the behavior may be still undefined if the pointer is
used to access an object. FreeRTOS deliberately creates external aliases
for all the kernel object types (StaticEventGroup_t, StaticQueue_t,
StaticStreamBuffer_t, StaticTimer_t and StaticTask_t) for data hiding
purposes. The internal object types and the corresponding external
aliases are guaranteed to have the same size and alignment which is
checked using configASSERT.


#### Rule 11.5

MISRA C:2012 Rule 11.5: A conversion should not be performed from pointer to
void into pointer to object.
This rule prohibits conversion of a pointer to void into a pointer to
object because it may result in an incorrectly aligned pointer leading
to undefined behavior.

_Ref 11.5.1_
- The memory blocks returned by pvPortMalloc() are guaranteed to meet the
architecture alignment requirements specified by portBYTE_ALIGNMENT.
The casting of the pointer to void returned by pvPortMalloc() is,
therefore, safe because it is guaranteed to be aligned.

_Ref 11.5.2_
- The conversion from a pointer to void into a pointer to EventGroup_t is
safe because it is a pointer to EventGroup_t, which is returned to the
application at the time of event group creation for data hiding
purposes.

_Ref 11.5.3_
- The conversion from a pointer to void in list macros for list item owner
is safe because the type of the pointer stored and retrieved is the
same.

_Ref 11.5.4_
- The conversion from a pointer to void into a pointer to EventGroup_t is
safe because it is a pointer to EventGroup_t, which is passed as a
parameter to the xTimerPendFunctionCallFromISR API when the callback is
pended.

_Ref 11.5.5_
- The conversion from a pointer to void into a pointer to uint8_t is safe
because data storage buffers are implemented as uint8_t arrays for the
ease of sizing, alignment and access.


### MISRA configuration

Expand Down Expand Up @@ -62,11 +119,7 @@ Copy below content to `misra.conf` to run Coverity on FreeRTOS-Kernel.
{
deviation: "Rule 8.7",
reason: "API functions are not used by the library outside of the files they are defined; however, they must be externally visible in order to be used by an application."
},
{
deviation: "Rule 11.5",
reason: "Allow casts from `void *`. List owner, pvOwner, is stored as `void *` and are cast to various types for use in functions."
}
]
}
```
```
3 changes: 3 additions & 0 deletions croutine.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@
traceENTER_xCoRoutineCreate( pxCoRoutineCode, uxPriority, uxIndex );

/* Allocate the memory that will store the co-routine control block. */
/* MISRA Ref 11.5.1 [Malloc memory assignment] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
/* coverity[misra_c_2012_rule_11_5_violation] */
pxCoRoutine = ( CRCB_t * ) pvPortMalloc( sizeof( CRCB_t ) );

if( pxCoRoutine )
Expand Down
Loading

0 comments on commit 1f4b5a1

Please sign in to comment.