Expedite Your Code Coverage Task With a Coverage Advisor

Headshot of Ricardo Camacho, Director of Safety & Security Compliance

By Ricardo Camacho

December 3, 2020

4  min read

When building critical systems, structural code coverage becomes a necessity. This post highlights how Parasoft C/C++test can help testing teams with automated productivity features like coverage advisor.

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 the embedded development of safety-critical applications where software systems cannot fail — or lives will be lost. Parasoft C/C++test’s coverage advisor helps 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 Advantages

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:

  • Unit
  • Integration
  • 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.

Dashboard showing code coverage metrics and trends
Figure 1: Metrics and Trends

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.

Menu showing Parasoft then Show in Coverage Advisor
Figure 2: Show in Coverage Advisor Menu

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.

Screen capture of Coverage Advisor tab showing dependencies, preconditions, expected coverage
Figure 3: Parasoft C/C++test 2020.2 Coverage Advisor Line Coverage Analysis Feedback

Summary

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.

The Value of Using a Unified C/C++ Testing Solution

 

Headshot of Ricardo Camacho, Director of Safety & Security Compliance

By Ricardo Camacho

Sr. Technical Product Marketing Manager for Parasoft’s embedded testing solutions. He has expertise in the SDLC and test automation of embedded real-time, safety- and security-critical applications, and software compliance to industry standards.

Get the latest software testing news and resources delivered to your inbox.