Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MISRA Compliance Update #26

Merged
merged 2 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions MISRA.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
# MISRA Compliance

The Fleet Provisioning Library files conform to the [MISRA
C:2012](https://www.misra.org.uk) guidelines, with some noted exceptions.
Compliance is checked with Coverity static analysis. Deviations from the MISRA
standard are listed below:
The Fleet Provisioning Library files conform to the [MISRA C:2012](https://www.misra.org.uk)
guidelines, with some noted exceptions. Compliance is checked with Coverity static analysis.
The specific deviations, suppressed inline, are listed below.

### Ignored by [Coverity Configuration](tools/coverity/misra.config)
| Deviation | Category | Justification |
| :-: | :-: | :-: |
| Directive 4.9 | Advisory | Allow inclusion of function like macros. Asserts, logging, and topic string macros use function like macros. |
| Rule 2.5 | Advisory | Allow unused macros. Macros defined for topic strings are not used by the library, but are part of the API. |
| Rule 3.1 | Required | Allow nested comments. C++ style `//` comments are used in example code within Doxygen documentation blocks. |

### Flagged by Coverity
| Deviation | Category | Justification |
| :-: | :-: | :-: |
| Rule 8.7 | Advisory | 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. |
Additionally, [MISRA configuration file](https://github.com/aws/Fleet-Provisioning-for-AWS-IoT-embedded-sdk/blob/main/tools/coverity/misra.config) contains the project wide deviations.

### Suppressed with Coverity Comments
To find the violation references in the source files run grep on the source code
with ( Assuming rule 11.4 violation; with justification in point 2 ):
```
grep 'MISRA Ref 11.4.2' . -rI
```

*None.*
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ target_include_directories( coverity_analysis PUBLIC
${FLEET_PROVISIONING_INCLUDE_PUBLIC_DIRS}
"${CMAKE_CURRENT_LIST_DIR}/include" )


# Build without debug enabled when performing static analysis
target_compile_options(coverity_analysis PUBLIC -DNDEBUG -DDISABLE_LOGGING)

# ============================ Test Configuration ============================

# Include Unity build configuration.
Expand Down
26 changes: 22 additions & 4 deletions test/include/fleet_provisioning_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,30 @@

#include <stdio.h>

#define LogError( message ) printf( "Error: " ); printf message; printf( "\n" )
#ifdef DISABLE_LOGGING
#ifndef LogError
#define LogError( message )
#endif
#ifndef LogWarn
#define LogWarn( message )
#endif

#define LogWarn( message ) printf( "Warn: " ); printf message; printf( "\n" )
#ifndef LogInfo
#define LogInfo( message )
#endif

#define LogInfo( message ) printf( "Info: " ); printf message; printf( "\n" )
#ifndef LogDebug
#define LogDebug( message )
#endif

#define LogDebug( message ) printf( "Debug: " ); printf message; printf( "\n" )
#else /* ! DISABLE_LOGGING */
#define LogError( message ) printf( "Error: " ); printf message; printf( "\n" )

#define LogWarn( message ) printf( "Warn: " ); printf message; printf( "\n" )

#define LogInfo( message ) printf( "Info: " ); printf message; printf( "\n" )

#define LogDebug( message ) printf( "Debug: " ); printf message; printf( "\n" )
#endif /* DISABLE_LOGGING */

#endif /* FLEET_PROVISIONING_CONFIG_H_ */
6 changes: 5 additions & 1 deletion tools/coverity/misra.config
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
{
deviation: "Rule 3.1",
reason: "Allow nested comments. C++ style `//` comments are used in example code within Doxygen documentation blocks."
}
},
{
deviation: "Rule 8.7",
reason: "API functions are not used by library. They must be externally visible in order to be used by the application."
},
]
}