Overview

It is critical to test your code, but how thorough are the tests? This case study achieves 100% code coverage. Specifically, the Freescale PWM function is tested.

Download

Note that you will need a fully functional and licensed TPU Simulator, version 3.41, Build D (or later) to run this test.

Click here to download this example

How to Run

Did it work?

What did it do?

A series of four tests were run. These tested the following four things:

At the end of each test, the following scripts (more or less) were run.

// 18/24 instructions executed which is 75.0%
// 5/12 branches which is 41.6%
load_cumulative_file_coverage("Pwm.uc",
              "00_PwmCovStart.CoverageData");
verify_file_coverage("Pwm.uc", 74.9, 41.5);
save_cumulative_file_coverage("Pwm.uc",
               "01_PwmCov_0_100.CoverageData");

At the the VERY END ALL THE LAST-RUN TESTs, the following script command is run.

// 24/24 instructions executed, 100%
// 12/12 branches which is 100%
// Read it and weep, baby.
verify_file_coverage("Pwm.uc", 100, 100);

What else did it do?

Note that there is a fifth test in the directory called PwmCovBug.TpuCommand. Why? Because a situation in which an errant pulse could be generated was found. This test will fail, unless the code is modified!