~rcr/rirc

ref: 3edc5a832c66e6515c1317148d3be6da3e45700e rirc/scripts/coverage.sh -rwxr-xr-x 1.2 KiB
3edc5a83 — Richard Robbins fix scripts, add compile flags to make output 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash

set -e

CDIR="coverage"

export CC=gcc
export CFLAGS_DEBUG="-fprofile-arcs -ftest-coverage -fprofile-abs-path"

export MAKEFLAGS="-e -j $(nproc)"

rm -rf $CDIR && mkdir -p $CDIR

make clean
make check

GCNO=$(find build -name '*.t.gcno')

FILTER=$(cat << 'EOF'
{
	use Cwd;
	@results;
	@result_ds;
	@result_fs;
	if (eof()) {
		print "- Coverage:";
		print "- ", "=" x 40;
		print "- $_", for sort(@result_fs);
		print "- $_", for sort(@result_ds);
		print "- ", "=" x 40;
		printf("- Total %20d/%d  %6.2f%%\n", $lc, $lt, (($lc / $lt) * 100.0));
	} elsif ($p) {
		chomp $file;
		chomp $_;
		$file =~ s/'//g;
		$file = substr($file, (length(getcwd()) + 6));
		@s1 = split /:/, $_;
		@s2 = split / /, $s1[1];
		$lt = $lt + $s2[2];
		$lc = $lc + $s2[2] * ($s2[0] / 100.0);
		$result = sprintf("%-25s  %4s  %7s", $file, $s2[2], $s2[0]);
		if ($file =~ m|src/.*/.*|) {
			push @result_fs, $result;
		} else {
			push @result_ds, $result;
		}
		$p = 0;
	}
	$p++ if /^File.*src.*c'/;
	$file = $_;
}
EOF
)

gcov --preserve-paths $GCNO | perl -lne "$FILTER"

mv *.gcov $CDIR

if [ -x "$(command -v gcovr)" ]; then
	gcovr -r . --html --html-details --filter ".*src.*c$" -o $CDIR/index.html
fi