From: Peter O. <obe...@us...> - 2007-07-06 07:39:04
|
Update of /cvsroot/ltp/utils/analysis/lcov/bin In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv1063/bin Modified Files: geninfo lcov Log Message: lcov: - add new option --initial to get zero coverage data from graph files Index: geninfo =================================================================== RCS file: /cvsroot/ltp/utils/analysis/lcov/bin/geninfo,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** geninfo 2 Jul 2007 15:29:02 -0000 1.29 --- geninfo 6 Jul 2007 07:38:47 -0000 1.30 *************** *** 93,96 **** --- 93,98 ---- sub read_config($); sub apply_config($); + sub gen_initial_info($); + sub process_graphfile($); # Global variables *************** *** 117,120 **** --- 119,123 ---- our @ignore_errors; # List of errors to ignore (parameter) our @ignore; # List of errors to ignore (array) + our $initial; our $cwd = `pwd`; *************** *** 170,174 **** "no-compat-libtool" => \$no_compat_libtool, "gcov-tool=s" => \$gcov_tool, ! "ignore-errors=s" => \@ignore_errors )) { --- 173,178 ---- "no-compat-libtool" => \$no_compat_libtool, "gcov-tool=s" => \$gcov_tool, ! "ignore-errors=s" => \@ignore_errors, ! "initial|i" => \$initial )) { *************** *** 355,361 **** # Do something ! foreach (@data_directory) { ! gen_info($_); } info("Finished .info-file creation\n"); --- 359,375 ---- # Do something ! if ($initial) { ! foreach (@data_directory) ! { ! gen_initial_info($_); ! } ! } ! else ! { ! foreach (@data_directory) ! { ! gen_info($_); ! } } info("Finished .info-file creation\n"); *************** *** 379,383 **** Usage: $tool_name [OPTIONS] DIRECTORY ! Traverse DIRECTORY and create a .info file for each .da/.gcda file found. Note that you may specify more than one directory, all of which are then processed sequentially. --- 393,397 ---- Usage: $tool_name [OPTIONS] DIRECTORY ! Traverse DIRECTORY and create a .info file for each data file found. Note that you may specify more than one directory, all of which are then processed sequentially. *************** *** 386,389 **** --- 400,404 ---- -v, --version Print version number, then exit -q, --quiet Do not print progress messages + -i, --initial Capture initial zero coverage data -t, --test-name NAME Use test case name NAME for resulting data -o, --output-filename OUTFILE Write data only to OUTFILE *************** *** 694,698 **** # gcov will happily create output even if there's no source code ! # available - this interfers with checksum creation so we need # to pull the emergency brake here. if (defined($source) && ! -r $source && $checksum) --- 709,713 ---- # gcov will happily create output even if there's no source code ! # available - this interferes with checksum creation so we need # to pull the emergency brake here. if (defined($source) && ! -r $source && $checksum) *************** *** 763,772 **** foreach (split(",",$bb_content{$source_filename})) { ! # Write "line_number,function_name" for each function. ! # Note that $_ contains this information in the form ! # "function_name=line_number" so that the order of ! # elements has to be reversed. ! printf(INFO_HANDLE "FN:%s\n", ! join(",", (split("=", $_))[1,0])); } } --- 778,787 ---- foreach (split(",",$bb_content{$source_filename})) { ! my ($fn, $line) = split("=", $_); ! ! if ($fn ne "") ! { ! print(INFO_HANDLE "FN:$line,$fn\n"); ! } } } *************** *** 1214,1218 **** # # filename -> comma-separated list of pairs (function name=starting ! # line number) for each function found # # for each entry in the .bb file. Filenames are absolute, i.e. relative --- 1229,1234 ---- # # filename -> comma-separated list of pairs (function name=starting ! # line number) to indicate the starting line of a function or ! # =name to indicate an instrumented line # # for each entry in the .bb file. Filenames are absolute, i.e. relative *************** *** 1275,1278 **** --- 1291,1306 ---- elsif ($value > 0) { + if (defined($filename)) + { + $result{$filename} .= + ($result{$filename} ? "," : ""). + "=$value"; + } + else + { + warn("WARNING: unassigned line". + " number in .bb file ". + "$bb_filename\n"); + } if ($function_name) { *************** *** 1340,1344 **** # # filename -> comma-separated list of pairs (function name=starting ! # line number) for each function found # # for each entry in the .gcno file. Filenames are absolute, i.e. relative --- 1368,1373 ---- # # filename -> comma-separated list of pairs (function name=starting ! # line number) to indicate the starting line of a function or ! # =name to indicate an instrumented line # # for each entry in the .gcno file. Filenames are absolute, i.e. relative *************** *** 1361,1364 **** --- 1390,1394 ---- my $blocks; my $packed_word; + my $string; local *INPUT; *************** *** 1408,1411 **** --- 1438,1447 ---- read(INPUT, $packed_word, 4); $length = unpack_int32($packed_word, $endianness); + if ($length > 0) + { + # Block number + read(INPUT, $packed_word, 4); + $length--; + } while ($length > 0) { *************** *** 1416,1423 **** if ($lineno != 0) { next; } ! ($blocks, $filename) = read_gcno_string(*INPUT, $endianness); if ($blocks > 1) { --- 1452,1475 ---- if ($lineno != 0) { + if (defined($filename)) + { + $result{$filename} .= + ($result{$filename} ? "," : ""). + "=$lineno"; + } + else + { + warn("WARNING: unassigned line". + " number in .gcno file ". + "$gcno_filename\n"); + } next; } ! ($blocks, $string) = read_gcno_string(*INPUT, $endianness); + if (defined($string)) + { + $filename = $string; + } if ($blocks > 1) { *************** *** 1496,1500 **** # # filename -> comma-separated list of pairs (function name=starting ! # line number) for each function found # # for each entry in the .bbg file. Filenames are absolute, i.e. relative --- 1548,1553 ---- # # filename -> comma-separated list of pairs (function name=starting ! # line number) to indicate the starting line of a function or ! # =name to indicate an instrumented line # # for each entry in the .bbg file. Filenames are absolute, i.e. relative *************** *** 1576,1579 **** --- 1629,1644 ---- $first_line = $lineno; } + if (defined($filename)) + { + $result{$filename} .= + ($result{$filename} ? "," : ""). + "=$lineno"; + } + else + { + warn("WARNING: unassigned line". + " number in .bbg file ". + "$bbg_filename\n"); + } next; } *************** *** 1671,1675 **** # ! # unpack_int32(word, endianess) # # Interpret 4-byte binary string WORD as signed 32 bit integer in --- 1736,1740 ---- # ! # unpack_int32(word, endianness) # # Interpret 4-byte binary string WORD as signed 32 bit integer in *************** *** 1739,1743 **** if (defined($output_filename) && ($output_filename eq "-")) { ! # Don't interfer with the .info output to STDOUT printf(STDERR @_); } --- 1804,1808 ---- if (defined($output_filename) && ($output_filename eq "-")) { ! # Don't interfere with the .info output to STDOUT printf(STDERR @_); } *************** *** 1876,1877 **** --- 1941,2080 ---- } } + + + sub gen_initial_info($) + { + my $directory = $_[0]; + my @file_list; + + if (-d $directory) + { + info("Scanning $directory for $graph_file_extension ". + "files ...\n"); + + @file_list = `find $directory $follow -name \\*$graph_file_extension -type f 2>/dev/null`; + chomp(@file_list); + @file_list or die("ERROR: no $graph_file_extension files ". + "found in $directory!\n"); + info("Found %d graph files in %s\n", $#file_list+1, $directory); + } + else + { + @file_list = ($directory); + } + + # Process all files in list + foreach (@file_list) { process_graphfile($_); } + } + + sub process_graphfile($) + { + my $graph_filename = $_[0]; + my $graph_dir; + my $graph_basename; + my $source_dir; + my $base_dir; + my %graph_data; + my $filename; + local *INFO_HANDLE; + + info("Processing $_[0]\n"); + + # Get path to data file in absolute and normalized form (begins with /, + # contains no more ../ or ./) + $graph_filename = solve_relative_path($cwd, $graph_filename); + + # Get directory and basename of data file + ($graph_dir, $graph_basename) = split_filename($graph_filename); + + # avoid files from .libs dirs + if ($compat_libtool && $graph_dir =~ m/(.*)\/\.libs$/) { + $source_dir = $1; + } else { + $source_dir = $graph_dir; + } + + # Construct base_dir for current file + if ($base_directory) + { + $base_dir = $base_directory; + } + else + { + $base_dir = $source_dir; + } + + if ($gcov_version < $GCOV_VERSION_3_4_0) + { + if (defined($compatibility) && $compatibility eq $COMPAT_HAMMER) + { + %graph_data = read_hammer_bbg_file($graph_filename, + $base_dir); + } + else + { + %graph_data = read_bb_file($graph_filename, $base_dir); + } + } + else + { + %graph_data = read_gcno_file($graph_filename, $base_dir); + } + + # Check whether we're writing to a single file + if ($output_filename) + { + if ($output_filename eq "-") + { + *INFO_HANDLE = *STDOUT; + } + else + { + # Append to output file + open(INFO_HANDLE, ">>$output_filename") + or die("ERROR: cannot write to ". + "$output_filename!\n"); + } + } + else + { + # Open .info file for output + open(INFO_HANDLE, ">$graph_filename.info") + or die("ERROR: cannot create $graph_filename.info!\n"); + } + + # Write test name + printf(INFO_HANDLE "TN:%s\n", $test_name); + foreach $filename (keys(%graph_data)) + { + my %lines; + my $count = 0; + + print(INFO_HANDLE "SF:$filename\n"); + foreach (split(",",$graph_data{$filename})) + { + my ($fn, $line) = split("=", $_); + + if ($fn eq "") + { + $lines{$line} = ""; + } + else + { + print(INFO_HANDLE "FN:$line,$fn\n"); + } + } + foreach (sort {$a <=> $b } keys(%lines)) + { + print(INFO_HANDLE "DA:$_,0\n"); + $count++; + } + print(INFO_HANDLE "LH:0\n"); + print(INFO_HANDLE "LF:$count\n"); + print(INFO_HANDLE "end_of_record\n"); + } + if (!($output_filename && ($output_filename eq "-"))) + { + close(INFO_HANDLE); + } + } Index: lcov =================================================================== RCS file: /cvsroot/ltp/utils/analysis/lcov/bin/lcov,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** lcov 4 Jul 2007 14:38:59 -0000 1.22 --- lcov 6 Jul 2007 07:38:47 -0000 1.23 *************** *** 153,156 **** --- 153,157 ---- our $gcov_tool; our $ignore_errors; + our $initial; our $config; # Configuration file contents chomp($cwd); *************** *** 214,218 **** "no-compat-libtool" => \$no_compat_libtool, "gcov-tool=s" => \$gcov_tool, ! "ignore-errors=s" => \$ignore_errors )) { --- 215,220 ---- "no-compat-libtool" => \$no_compat_libtool, "gcov-tool=s" => \$gcov_tool, ! "ignore-errors=s" => \$ignore_errors, ! "initial|i" => \$initial )) { *************** *** 274,277 **** --- 276,289 ---- } } + else + { + if ($initial) + { + print(STDERR "Option --initial is only valid when capturing ". + "data (-c)\n"); + print_usage(*STDERR); + exit(2); + } + } # Check for requested functionality *************** *** 367,370 **** --- 379,383 ---- Options: + -i, --initial Capture initial zero coverage data -t, --test-name NAME Specify test name to be stored with data -o, --output-file FILENAME Write data to FILENAME instead of stdout *************** *** 408,413 **** if ($i == 0) { ! print(STDERR "Need one of the options -z, -c, -e, -a, -r, -l ". ! "or --diff\n"); print_usage(*STDERR); exit(2); --- 421,426 ---- if ($i == 0) { ! print(STDERR "Need one of the options -z, -c, -a, -e, -r, ". ! "-l or --diff\n"); print_usage(*STDERR); exit(2); *************** *** 415,419 **** elsif ($i > 1) { ! die("ERROR: only one of -z, -c, -e, -a, -r, -l or ". "--diff allowed!\n"); } --- 428,432 ---- elsif ($i > 1) { ! die("ERROR: only one of -z, -c, -a, -e, -r, -l or ". "--diff allowed!\n"); } *************** *** 520,523 **** --- 533,540 ---- @param = (@param, "--ignore-errors", $ignore_errors); } + if ($initial) + { + @param = (@param, "--initial"); + } system(@param); *************** *** 651,658 **** --- 668,695 ---- } } + if ($base_directory) + { + @param = (@param, "--base-directory", $base_directory); + } + if ($no_compat_libtool) + { + @param = (@param, "--no-compat-libtool"); + } + elsif ($compat_libtool) + { + @param = (@param, "--compat-libtool"); + } if ($gcov_tool) { @param = (@param, "--gcov-tool", $gcov_tool); } + if ($ignore_errors) + { + @param = (@param, "--ignore-errors", $ignore_errors); + } + if ($initial) + { + @param = (@param, "--initial"); + } system(@param) and exit($? >> 8); |