Expedite Your Code Coverage Task With a Coverage Advisor
By Ricardo Camacho
December 3, 2020
4 min read
Jump to Section
Software testing is an integral part of software development. Every industry that develops and executes code can benefit from using structural code coverage testing tools. These tools are especially useful in industries for embedded development of safety-critical applications where software systems cannot fail — or lives will be lost. Parasoft C/C++test 2020.2 comes with a coverage advisor to help users create that elusive test case that is difficult and time consuming to form.
Code Coverage Is an Important Necessity
Obtaining 100% code coverage metrics in embedded safety- and security-critical systems serves multiple purposes. The primary purpose is to conform to verification and validation (V&V) requirements defined in process standards like DO-178C, IEC 62304, and others.
The value that code coverage provides is an add-on V&V activity that flushes out defects in the code. It makes sure that every line of code has been executed and hence examined through testing. This gives you an additional safety net on code quality and reliability.
Also, if you execute all your test cases and only obtain 60%, it becomes obvious that you haven’t created enough test cases. As a result, hidden defects might lurk in these untouched areas.
Another concern is “dead code”. That means code that would never be executed because no pathway to it exists. This can happen when a feature/capability is implemented but at some point, the requirement for the feature is removed. If you don’t completely remove the code, it can result in dead code. Finding dead code within functions or operations can also highlight bad code logic that you must address. In this situation, the dead code indicates no reachable, logical path exists.
How to Satisfy Your Code Coverage Requirement
You can achieve code coverage through various methods of testing or a combination of:
- System testing
I’ve participated in the following two approaches, which Parasoft easily supports:
- A combination of system and unit testing. First, instrument the code and execute all the system test cases, which yields a lot of coverage metrics. Last, apply unit testing to obtain coverage of the remaining uncovered code.
- Utilizing unit testing to achieve 100% structural code coverage. This approach is straight forward. The user creates unit level test cases to ensure coverage of each function/operation.
Code Coverage Metrics
There are various coverage metrics to consider. Knowing which specific type to apply depends on the software integrity level (SIL) as defined in IEC 61508. Another example is Design Assurance Level (DAL) for DO-178B/C. For embedded systems, the control metrics referenced are statements, branch, modified condition decision coverage (MC/DC) and for the strictest requirements, there is Object/Assembly code. Parasoft supports gathering all these coverage metrics, including terms other industries use like block, call, function, path, decision, and more.
Automating the Process
Parasoft C/C++test has made huge productivity impacts in automating the process of obtaining code coverage. The first is in automated test case generation. With one click and a menu selection, the testing solution analyzes the code and automatically generates smart unit test cases. These unit test cases can then be executed. Depending on code size and complexity, teams can instantly achieve up to 90%.
For complex code, there are always those elusive code statements of which it’s 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 C/C++test 2020.2 has enhanced its coverage advisor, making it easier to obtain coverage of those difficult to reach lines of code.
How to Obtain Coverage in Coverage Advisor
Within your editor, right-click on the line of code that you want coverage for and select Parasoft -> Show in Coverage Advisor.
Figure 3 below shows an analysis report providing the user with a solution. The Pre-conditions field express:
- 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.
Performing structural code coverage is necessary when building embedded safety- and security-critical software systems. Together with requirements test coverage, it ensures that:
- You created enough test cases to test your software.
- There isn’t any dead code.
- Each line is inspected for compliance and certification needs.
Parasoft C/C++test is a unified testing solution that provides teams with testing method capabilities and automated productivity features like Coverage Advisor. Using this feature, developers can reach their code coverage goals quickly. Accordingly, software directors and managers can achieve business goals for time-to-market, labor cost reduction, audit safeguards, and ease in product certification.