Test Case Concept
With test cases made known to Testwell CTC++, the counter data can be written in separate data files.
The instrumented program is assumed to contain a test driver portion. It can be instrumented or not. The test driver calls the code under test, the instrumented code. In the test driver, the tests can be grouped to test cases, and the coverage can be measured per test case.
void ctc_set_testcase(const char* tcname);
In the test driver, you call this function when a new test case starts, handing over a proper name for the test case. With that separation, several data files are written containing the coverage data of the corresponding test case.
Example: If you name the test cases "tc01", "tc02" and "tc03", three or four data files are created: MON.dat (if there is some coverage data collected before the first test case starts), MONtc01.dat, MONtc02.dat and MONtc03.dat.
Test case specific coverage reports are obtained by ctcpost from MON.sym and one of the MONtc<n>.dat.
A coverage report for the whole test session is obtained from MON.sym and all MONtc*.dat.
Instead of calling ctc_set_testcase(“tcname”)
directly, you can also use a
pragma:
#pragma CTC TESTCASE tcname
If the test driver code is compiled without instrumentation, the file still compiles, and the line has no effect.
In practical programs (test drivers, which necessarily are not instrumented), it is perhaps
best to write a prototype for ctc_set_testcase()
, and then call it
explicitly. Then you can also pass the test case name via a variable of type
char *
, while in the #pragma
style a variable
cannot be used.
ctc_set_testcase()
call there are "open functions" (the instrumented function has been entered, but not yet exited), the timing data in the data files is not correct for these functions.