[igt-dev] [PATCH i-g-t 05/12] code_cov_parse_info: add a tool to analyze branch coverage

Kamil Konieczny kamil.konieczny at linux.intel.com
Wed Jan 25 14:13:44 UTC 2023


Hi Mauro,

On 2023-01-17 at 15:06:00 +0100, Mauro Carvalho Chehab wrote:
> From: Mauro Carvalho Chehab <mchehab at kernel.org>
> 
> Branch coverage is trickier than functions. Add a tool that displays
> the starting line that it is not being covered, together with up
> to 10 context lines before.
--------------------- ^

imho it will help to print also few lines after, especially for
multiline ones.

> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab at kernel.org>
> ---
>  scripts/code_cov_parse_info | 85 ++++++++++++++++++++++++++++++++++++-
>  1 file changed, 84 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/code_cov_parse_info b/scripts/code_cov_parse_info
> index 3a503423861d..3982dbd513c4 100755
> --- a/scripts/code_cov_parse_info
> +++ b/scripts/code_cov_parse_info
> @@ -894,6 +894,76 @@ sub generate_report($)
>  	close OUT;
>  }
>  
> +sub check_source_branches()
------ ^
Maybe change this name to print_not_covered_branches ?
Option name may also change but you can keep it as is if you prefer.

Acked-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>

--
Kamil

> +{
> +	foreach my $source (sort keys(%all_branch)) {
> +		next if (!$used_source{$source});
> +		next if (is_file_excluded($source));
> +
> +		my @lines;
> +		foreach my $where (sort keys %{$all_branch{$source}}) {
> +			my $taken = $all_branch{$source}{$where};
> +			next if ($taken > 0);
> +
> +			next if !($where =~ m/^(-?\d+),(-?\d+),(-?\d+)/);
> +
> +			my ($ln, $block, $branch, $ctx_lines);
> +			$ln = $1;
> +			$block = $2;
> +			$branch = $3;
> +
> +			if (!@lines) {
> +				open IN, "$source";
> +				@lines = <IN>;
> +				close IN;
> +			}
> +
> +			if ($ln >= $#lines) {
> +				print "Error: $ln is bigger than $#lines. Can't print branch!\n";
> +			}
> +
> +			my $func = $all_branch{$source}{$where}{func};
> +			my $func_ln = $all_branch{$source}{$where}{func_ln};
> +
> +			print "Branch $source:$ln, ";
> +			if ($func) {
> +				if ($func_ln) {
> +					print "func: $func, ";
> +				} else {
> +					print "func: $func:$func_ln, ";
> +				}
> +			}
> +			print "block $block, branch $branch not taken:\n";
> +
> +			if ($func_ln) {
> +				$ctx_lines = $ln - $func_ln;
> +			} else {
> +				$ctx_lines = 10;
> +			}
> +
> +
> +			# Search for up to $ctx_lines before the occurrence
> +			my $context = "";
> +			my $has_if;
> +			$ln-- if ($ln > 0);
> +			my $delim = "->";
> +			for (my $if_ln = $ln; $if_ln >= 0 && (($ln - $if_ln) < $ctx_lines); $if_ln--) {
> +				$context = "$if_ln$delim\t$lines[$if_ln]" . $context;
> +				$delim = "";
> +				if ($lines[$if_ln] =~ m/(\bif\b|#if)/) {
> +					$has_if = 1;
> +					last;
> +				}
> +			}
> +			if ($has_if) {
> +				print $context;
> +			} else {
> +				print "$ln->\t$lines[$ln]";
> +			}
> +		}
> +	}
> +}
> +
>  #
>  # Argument handling
>  #
> @@ -910,6 +980,7 @@ my $show_files;
>  my $show_lines;
>  my $only_i915;
>  my $only_drm;
> +my $check_branches;
>  
>  GetOptions(
>  	"print-coverage|print_coverage|print|p" => \$print_used,
> @@ -929,6 +1000,7 @@ GetOptions(
>  	"show-files|show_files" => \$show_files,
>  	"show-lines|show_lines" => \$show_lines,
>  	"report|r=s" => \$gen_report,
> +	"check-branches" => \$check_branches,
>  	"css-file|css|c=s" => \$css_file,
>  	"title|t=s" => \$title,
>  	"html-prolog|prolog=s" => \$html_prolog,
> @@ -946,7 +1018,7 @@ if ($#ARGV < 0) {
>  }
>  
>  # At least one action should be specified
> -pod2usage(1) if (!$print_used && !$filter && !$stat && !$print_unused && !$gen_report);
> +pod2usage(1) if (!$print_used && !$filter && !$stat && !$print_unused && !$gen_report && !$check_branches);
>  
>  pod2usage(1) if ($gen_report && ($print_used || $filter || $stat || $print_unused));
>  
> @@ -1027,6 +1099,11 @@ if ($gen_report) {
>  
>  gen_stats();
>  
> +
> +if ($check_branches) {
> +	check_source_branches();
> +}
> +
>  die "Nothing counted. Wrong input files?" if (!$stats{"all_files"});
>  
>  print_code_coverage($print_used, $print_unused, $show_lines);
> @@ -1284,6 +1361,12 @@ This option is automaticaly enabled when B<--func-filters> is used.
>  Shows the list of files that were used to produce the code coverage
>  results.
>  
> +=item B<--check-branches>
> +
> +Checks at the Linux Kernel source files what's the contents of the
> +branches that weren't taken. The directory should match what's
> +stored inside the info files.
> +
>  =item B<--verbose> or B<-v>
>  
>  Prints the name of each parsed file.
> -- 
> 2.39.0
> 


More information about the igt-dev mailing list