Global Sources
EE Times-India
Stay in touch with EE Times India
 
EE Times-India > Embedded
 
 
Embedded  

Finding bugs in embedded C software

Posted: 11 Aug 2009     Print Version  Bookmark and Share

Keywords:embedded C  static code analysis  bugs software 

We just found one instance of a memory overwrite in the code paths that we exercisedbut how can we rest assured that there are no more memory overwrites in the code that we did not exercise? If we look at the coverage analysis, we see that one of the functions, reportSensorFailure(), has not been exercised at all. We need to test this function—but how? One way is to create a unit test that will call this function.

We create a test case skeleton using C++test's test case wizard, then we fill in some test code. Then, we run this test case—exercising just this one previously-untested function—with runtime memory monitoring enabled. With C++test, this entire operation takes just seconds.

The results show that the function is now covered, but new errors are reported (figure 4).

image name

Figure4: The results show that the function is now covered, but new errors are reported. (Click for a larger image)

Our test case uncovered more memory-related errors. We have a clear problem with memory initialization (null pointers) when our failure handler is being called. Further analysis leads us to realize that in reportSensorValue() we mixed an order of calls. finalize() is being called before printMessage() is called, but finalize() actually frees memory used by printMessage().

image name

Figure 5: finalize() actually frees memory used by printMessage().

We fix this order, then rerun the test case one more time.

That resolves one of the errors reported. Now, let's look at the second problem reported: AccessViolationException in the print message. This occurs because these table messages are not initialized. To resolve this, we call the initialize() function before printing the message. The repaired function is shown in figure 6.

image name

Figure 6: Shown is the repaired function.

When we rerun the test, only one task is reported: an unvalidated unit test case, which is not really an error. All we need to do here is verify the outcome in order to convert this test into a regression test. C++test will do this for us automatically by creating appropriate assertion (figure 7).

image name

Figure 7: When we rerun the test, only one task is reported: an unvalidated unit test case, which is not really an error. (Click for a larger image)

Next, we run the entire application again. The coverage analysis shows that almost the entire application was covered, and the results show that no memory error problems occurred.

 First Page Previous Page 1 • 2 • 3 • 4 • 5 Next Page Last Page



Comment on "Finding bugs in embedded C software"
Comments:  
*  You can enter [0] more charecters.
*Verify code:
 
 
Webinars

Seminars

Visit Asia Webinars to learn about the latest in technology and get practical design tips.

 

Go to top             Connect on Facebook      Follow us on Twitter      Follow us on Orkut

 
Back to Top