Next:Support for testing profile-directed optimizations, Previous:Support for testing link-time optimizations, Up:Testsuites [Contents][Index]
gcov ¶Language-independent support for testinggcov, and for checkingthat branch profiling produces expected values, is provided by theexpect filelib/gcov.exp.gcov tests also rely on proceduresinlib/gcc-dg.exp to compile and run the test program. A typicalgcov test contains the following DejaGnu commands within comments:
{ dg-options "--coverage" }{ dg-do run { target native } }{ dg-final { run-gcov sourcefile } }Checks ofgcov output can include line counts, branch percentages,and call return percentages. All of these checks are requested viacommands that appear in comments in the test’s source file.Commands to check line counts are processed by default.Commands to check branch percentages and call return percentages areprocessed if therun-gcov command has argumentsbranchesorcalls, respectively. For example, the following specifieschecking both, as well as passing-b togcov:
{ dg-final { run-gcov branches calls { -b sourcefile } } }A line count command appears within a comment on the source linethat is expected to get the specified count and has the formcount(cnt). A test should only check line counts forlines that will get the same count for any architecture.
Commands to check branch percentages (branch) and callreturn percentages (returns) are very similar to each other.A beginning command appears on or before the first of a range oflines that will report the percentage, and the ending commandfollows that range of lines. The beginning command can include alist of percentages, all of which are expected to be found withinthe range. A range is terminated by the next command of the samekind. A commandbranch(end) orreturns(end) marksthe end of a range without starting a new one. For example:
if (i > 10 && j > i && j < 20) /*branch(27 50 75) */ /*branch(end) */ foo (i, j);
For a call return percentage, the value specified is thepercentage of calls reported to return. For a branch percentage,the value is either the expected percentage or 100 minus thatvalue, since the direction of a branch can differ depending on thetarget or the optimization level.
Not all branches and calls need to be checked. A test should notcheck for branches that might be optimized away or replaced withpredicated instructions. Don’t check for calls inserted by thecompiler or ones that might be inlined or optimized away.
A single test can check for combinations of line counts, branchpercentages, and call return percentages. The command to check aline count must appear on the line that will report that count, butcommands to check branch percentages and call return percentages canbracket the lines that report them.
Next:Support for testing profile-directed optimizations, Previous:Support for testing link-time optimizations, Up:Testsuites [Contents][Index]