See real examples of how you can use AI in your testing. Right now. Learn More >>
Recommended Content
WEBINAR
Code coverage measures how much of an application’s source code is tested through various methods, such as unit testing, manual testing, and automated functional testing. Code coverage percentage goals can be subjective. The thoroughness of the coverage in safety-critical systems depends on the application safety integrity level (SIL) metric used in different industries and the design assurance level (DAL) commonly used in avionics. In building safety-critical applications where failure may cause death, regulatory and industry standards require 100% structural code coverage.
This presentation dives into the essential topic of code coverage for embedded C/C++ systems, explaining its importance, different measurement types, and practical application. We explore how to achieve thorough testing, especially in safety-critical environments, and demonstrate tools that simplify the process.
Code coverage is a metric that tells you how much of your application’s source code has been executed during testing. It’s a way to answer the question: “Have we tested enough?” By highlighting untested code, it helps uncover potential bugs and identify dead code. The most common way to achieve this is through code instrumentation, where extra code is added to track the execution of statements, decisions, or branches. This instrumentation then logs the execution, allowing for a percentage of code coverage to be calculated and visualized, often with code highlighted in green (executed) or red (not executed).
The presentation included a demonstration showcasing:
In the embedded world, C and C++ are frequently used in safety and security-critical systems. Industries like automotive (ISO 26262), avionics (DO-178C), and medical devices (IEC 62304) have strict regulatory requirements and process standards. These standards often assign Safety Integrity Levels (SIL) or Design Assurance Levels (DAL) to software components. Higher levels, indicating greater risk if the software fails, typically mandate more rigorous testing. For instance, SIL 4 in IEC 61508 highly recommends 100% coverage for statements, branches, and MC/DC. The common thread across these standards is the focus on statement, branch, and MC/DC coverage, as these are deemed best practices by industry experts to ensure high-quality, safe, secure, and reliable code.
Achieving code coverage can be done through various testing methods:
Many organizations combine results from these different testing methods to achieve their overall coverage targets. For example, coverage from unit tests can be merged with coverage from system tests.
Code coverage is a vital part of a Continuous Integration/Continuous Delivery (CI/CD) pipeline. Tools can automate the instrumentation, execution, and reporting of coverage data, integrating seamlessly with build systems and CI/CD platforms like Jenkins, GitLab, and Azure DevOps. This provides real-time feedback on code quality and helps manage risks effectively.
Ultimately, code coverage is a powerful technique for ensuring the quality and reliability of embedded C/C++ systems, especially in safety-critical domains. By understanding the different coverage criteria and leveraging appropriate tools, development teams can achieve their testing objectives more efficiently.