summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/test/fuzz/fuzz_coverage.sh
blob: abe40bea1cc4a7016aa7e0714cb5070f5fc10240 (plain)
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
62
63
#!/bin/bash
#
# fuzz_coverage.sh - generate coverage information after running a fuzz test.
#
# This script assumes it is running in the directory that the fuzz test was executed in and requires
# that WiredTiger was running with "-fprofile-instr-generate" and "-fcoverage-mapping".
#
# Usage
# fuzz_coverage.sh <fuzz-test-binary>
#
# Environment variables
# PROFDATA_BINARY --
# 	The binary to use to merge the profiling data. (default: llvm-profdata)
# COV_BINARY --
# 	The binary to use to generate coverage information. (default: llvm-cov)
#
# Output
# <fuzz-test-binary>_cov.txt --
#	A coverage report in text format. It can be inspect with the "less" command and searched for
#	functions of interest. The numbers on the left of each line of code indicate how many times
#	they were hit in the fuzz test.
# <fuzz-test-binary>_cov.html --
#	A coverage report in html format. If a web browser is available, this might be a nicer way
#	visualize the coverage.

if test "$#" -lt "1"; then
	echo "$0: must specify fuzz test to generate coverage for"
	exit 1
fi

fuzz_test_bin="$1"

if test -z "$PROFDATA_BINARY"; then
	profdata_bin="llvm-profdata"
	echo "$0: PROFDATA_BINARY is unset, defaulting to $profdata_bin"
else
	profdata_bin="$PROFDATA_BINARY"
fi

if test -z "$COV_BINARY"; then
	cov_bin="llvm-cov"
	echo "$0: COV_BINARY is unset, defaulting to $cov_bin"
else
	cov_bin="$COV_BINARY"
fi

# Remove anything from previous runs.
rm *_cov.profdata *_cov.txt *_cov.html &> /dev/null

fuzz_cov_name="${fuzz_test_bin}_cov"
combined_profdata_name="${fuzz_cov_name}.profdata"

# Check that there is coverage data.
ls *.profraw &> /dev/null
if test $? -ne "0"; then
	echo "$0: could not find any .profraw files in the current directory"
	echo "$0: ensure that -fprofile-instr-generate and -fcoverage-mapping are added to your CFLAGS and LINKFLAGS when configuring"
	exit 1
fi

$profdata_bin merge -sparse *.profraw -o $combined_profdata_name || exit 1
$cov_bin show $fuzz_test_bin -instr-profile=$combined_profdata_name > "${fuzz_cov_name}.txt"
$cov_bin show $fuzz_test_bin -instr-profile=$combined_profdata_name -format=html > "${fuzz_cov_name}.html"