Featured Webinar: Simplify Compliance Workflows With New C/C++test 2024.2 & AI-Driven Automation Watch Now
Structural Code Coverage
Collecting and analyzing code coverage metrics is an important aspect of safety-critical automotive software development. Code coverage measures the completion of test cases and executed tests. It provides evidence that validation is complete, at least as specified by your stakeholder and compliance requirements.
It also identifies dead code. This is code that can logically never be reached. It demonstrates the existence of unintended behavior. Code that isn’t covered by any test is a liability because its behavior and functionality are unknown.
The amount and extent of code coverage depend on the safety integrity level and coverage percentage goals. For safety-critical applications, 100% code coverage is the norm. The higher the integrity level, the higher the rigor. Inevitably the number and complexity of test cases will grow.
The following table shows the recommendations for types of code coverage at each ISO 26262 ASIL.
Statement Coverage
Statement coverage requires that each program statement be executed at least once and is recommended at the lower ASIL levels. Branch and MC/DC coverage encompass statement coverage.
Branch Coverage
Branch coverage ensures that each decision path of a branch (if-then-else constructs) is executed.
Modified Condition/Decision Coverage (MC/DC)
Modified condition/decision coverage (MC/DC) requires the most complete code coverage to ensure test cases execute each decision branch and all the possible combinations of inputs that affect the outcome of decision logic. For complex logic, the number of test cases can explode, so the modified condition restrictions are used to limit test cases to those that result in standalone logical expressions changing. See this tutorial from NASA.
Advanced unit test automation tools such as Parasoft C/++test provide all these code coverage metrics. C/C++test automates this data collection on host and target testing and accumulates test coverage history over time. This code coverage history can span unit, integration, and system testing to ensure coverage is complete and traceable at all levels of testing.
Increasing Code Coverage With Automated Unit Test Case Creation
The creation of productive unit tests has always been a challenge. Functional safety standards compliance demands high-quality software, which drives a need for test suites that affect and produce high code coverage statistics. Teams require unit test cases that help them achieve 100% code coverage.
This is easier said than done. Analyzing branches in the code and trying to find reasons why certain code sections are not covered continues to steal cycles from development teams.
Parasoft Coverage Advisor
Parasoft C/C++test resolves the coverage gaps in test suites. Parasoft discovered how to use advanced static code analysis (data and control flow analysis) to find values for the input parameters required to execute specific lines of uncovered code.
In complex code, there are always those elusive code statements of which it is exceedingly difficult to obtain coverage. It’s likely there are multiple input values with various permutations and possible paths that make it mind twisting and time consuming to decipher. But only one combination can get you the coverage you need. Parasoft makes it easy to obtain coverage of those difficult to reach lines of code.
Select the line of code you want to cover, and the Coverage Advisor will tell you what input values, global variables, and external calls you need to stimulate the code and obtain coverage.
The figure on the right shows an analysis report providing the user with a solution. The Pre-conditions field expresses:
- The range and input values for mainSensorSignal and coSensorSignal
- The expected outputs from the external calls
Upon creating the unit test case with these set parameter values and stubs for external calls, the user will obtain coverage of the line selected, plus the additional lines expressed in the Expected Coverage field.
Elevate your software testing with Parasoft solutions.
Explore the Chapters
- Introduction »
- 1. Overview »
- 2. Static Analysis »
- 3. MISRA »
- 4. AUTOSAR C++ 14 »
- 5. SEI/CERT »
- 6. CWE »
- 7. Unit Testing »
- 8. Regression Testing »
- 9. Software Integration Testing »
- 10. Software System Testing »
- 11. Structural Code Coverage »
- 12. Requirements Traceability Matrix »
- 13. Tool Qualification »
- 14. Reporting & Analytics »