|
|
It is difficult to write test suites that fully cover programs if you have no way of determining how much of the code is exercised. lprof removes the guesswork by showing, on a line-by-line basis, which lines of code are executed. That allows the tester to know exactly what has been tested. It also makes it easier to refine and improve tests.
Suppose you want to measure how well a given test suite tests a program. First, compile and link the program with -ql so that profiling information will be saved. Then, run the program with the tests to get the profiling data. By looking at the summary output, you can see how much of the code is exercised.
Coverage Data Source: test.cnt Date of Coverage Data Source: Wed Mar 2 11:11:58 1994 Object: progpercent lines total function covered covered lines name
91.5 97 106 compile 100.0 18 18 step 100.0 73 73 advance 100.0 4 4 getrnge 42.9 12 28 main 100.0 29 29 execute 100.0 19 19 succeed 42.9 3 7 putdata 0.0 0 19 regerr 100.0 21 21 fgetl
85.2 276 324 TOTAL
lprof Summary Output for a Test Suite
Now you can examine individual functions that do not have 100% coverage to find ways of improving the tests.
The rest of this section consists of three examples that show why certain functions may not have 100% coverage. The first example demonstrates how to uncover an option that is usually missed because it is not documented. The second example shows how to uncover a function that is never called. The third example examines code that is never executed because of an error condition that is difficult to produce. Each section also explains how to resolve the problem of lack of coverage.