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.
Note that you will need a fully functional and licensed TPU Simulator, version 3.41, Build D (or later) to run this test.
A series of four tests were run. These tested the following four things:
- Basic operation
- 100% and 0% duty cycle generation
- Immediate override of duty cycle
- TCR2 Operation
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);
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!