[test suite] update to use helper scripts for code coverage report generation
This commit is contained in:
parent
b9d5919cdd
commit
49b09c4903
9
test/afl/afl-compile-code-coverage.sh
Executable file
9
test/afl/afl-compile-code-coverage.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh -x
|
||||
|
||||
cd ..
|
||||
./rm-coverage-files.sh
|
||||
cd afl
|
||||
|
||||
./afl-compile.sh --enable-profile-coverage
|
||||
|
||||
exit
|
||||
@ -1,7 +1,7 @@
|
||||
#!/bin/sh -x
|
||||
|
||||
cd ../../
|
||||
CC=afl-gcc ./extras/apparmor/configure_args.sh --enable-afl-fuzzing
|
||||
CC=afl-gcc ./extras/apparmor/configure_args.sh --enable-afl-fuzzing $@
|
||||
make clean
|
||||
make
|
||||
cd test/afl
|
||||
|
||||
13
test/afl/afl-gen-code-coverage.sh
Executable file
13
test/afl/afl-gen-code-coverage.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/sh -x
|
||||
|
||||
RESULTS_DIR=afl-lcov-results
|
||||
[ -d $RESULTS_DIR ] && rm -rf $RESULTS_DIR
|
||||
|
||||
cd ..
|
||||
./gen-coverage-report.sh
|
||||
mv lcov-results afl/$RESULTS_DIR
|
||||
cd afl
|
||||
|
||||
echo "[+] Code coverage available in the $RESULTS_DIR/ directory"
|
||||
|
||||
exit
|
||||
29
test/gen-coverage-report.sh
Executable file
29
test/gen-coverage-report.sh
Executable file
@ -0,0 +1,29 @@
|
||||
#!/bin/sh -x
|
||||
|
||||
TOP_DIR="test"
|
||||
LCOV_INFO="$TOP_DIR/lcov_coverage.info"
|
||||
LCOV_INFO_FINAL="$TOP_DIR/lcov_coverage_final.info"
|
||||
LCOV_RESULTS_DIR="$TOP_DIR/lcov-results"
|
||||
|
||||
cd ..
|
||||
[ ! -d $TOP_DIR ] && mkdir $TOP_DIR
|
||||
[ -d $LCOV_RESULTS_DIR ] && rm -rf $LCOV_RESULTS_DIR
|
||||
[ ! -d $LCOV_RESULTS_DIR ] && mkdir $LCOV_RESULTS_DIR
|
||||
|
||||
for d in client server
|
||||
do
|
||||
cd $d
|
||||
gcov -b -u *.gcno
|
||||
cd ..
|
||||
done
|
||||
|
||||
cd lib
|
||||
gcov -b -u .libs/*.gcno
|
||||
cd ..
|
||||
|
||||
lcov --rc lcov_branch_coverage=1 --capture --directory . --output-file $LCOV_INFO
|
||||
lcov --rc lcov_branch_coverage=1 -r $LCOV_INFO /usr/include/\* --output-file $LCOV_INFO_FINAL
|
||||
genhtml --rc genhtml_branch_coverage=1 $LCOV_INFO_FINAL --output-directory $LCOV_RESULTS_DIR
|
||||
|
||||
cd test
|
||||
exit
|
||||
12
test/rm-coverage-files.sh
Executable file
12
test/rm-coverage-files.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh -x
|
||||
|
||||
cd ..
|
||||
for d in client server lib
|
||||
do
|
||||
for s in *.gcda *.gcno *.gcov
|
||||
do
|
||||
find $d -name $s | xargs rm -f
|
||||
done
|
||||
done
|
||||
cd test
|
||||
exit
|
||||
@ -214,6 +214,8 @@ my $enable_recompilation_warnings_check = 0;
|
||||
my $enable_configure_args_checks = 0;
|
||||
my $enable_profile_coverage_check = 0;
|
||||
my $disable_profile_coverage_init = 0;
|
||||
my $profile_rm_prev_sh = 'rm-coverage-files.sh';
|
||||
my $profile_gen_report_sh = 'gen-coverage-report.sh';
|
||||
my $enable_make_distcheck = 0;
|
||||
my $enable_perl_module_checks = 0;
|
||||
my $enable_perl_module_fuzzing_spa_pkt_generation = 0;
|
||||
@ -1296,6 +1298,8 @@ sub compile_warnings() {
|
||||
|
||||
sub profile_coverage() {
|
||||
|
||||
my $rv = 1;
|
||||
|
||||
### check for any *.gcno files - if they don't exist, then fwknop was
|
||||
### not compiled with profile support
|
||||
unless (glob('../client/*.gcno') and glob('../server/*.gcno')) {
|
||||
@ -1306,40 +1310,28 @@ sub profile_coverage() {
|
||||
|
||||
my $curr_dir = getcwd() or die $!;
|
||||
|
||||
### gcov -b ../client/*.gcno
|
||||
for my $dir ('../client', '../server', '../lib/.libs') {
|
||||
next unless -d $dir;
|
||||
chdir $dir or die $!;
|
||||
system "$gcov_path -b -u *.gcno > /dev/null 2>&1";
|
||||
chdir $curr_dir or die $!;
|
||||
|
||||
&run_cmd(qq|grep "called 0 returned" $dir/*.gcov|,
|
||||
$cmd_out_tmp, $curr_test_file);
|
||||
unless ($lcov_path) {
|
||||
&write_test_file(
|
||||
"[-] lcov command not found, skipping code coverage report generation.",
|
||||
$curr_test_file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
### if lcov has been installed then use it to build profile
|
||||
### result HTML pages
|
||||
if ($lcov_path) {
|
||||
mkdir "$output_dir/$lcov_results_dir"
|
||||
unless -d "$output_dir/$lcov_results_dir";
|
||||
&run_cmd(qq|$lcov_path --rc lcov_branch_coverage=1 --capture --directory .. | .
|
||||
qq|--output-file $output_dir/lcov_coverage.info|,
|
||||
$cmd_out_tmp, $curr_test_file);
|
||||
&run_cmd("./$profile_gen_report_sh", $cmd_out_tmp, $curr_test_file);
|
||||
|
||||
### exclude /usr/include/* files
|
||||
&run_cmd(qq|$lcov_path --rc lcov_branch_coverage=1 | .
|
||||
qq|-r $output_dir/lcov_coverage.info | .
|
||||
qq|/usr/include/\\* --output-file $output_dir/lcov_coverage_final.info|,
|
||||
$cmd_out_tmp, $curr_test_file);
|
||||
|
||||
&run_cmd(qq|$genhtml_path --rc genhtml_branch_coverage=1 | .
|
||||
qq|$output_dir/lcov_coverage_final.info | .
|
||||
qq|--output-directory $output_dir/$lcov_results_dir|,
|
||||
$cmd_out_tmp, $curr_test_file);
|
||||
|
||||
if (-d "${output_dir}.last") {
|
||||
&run_cmd("./$coverage_diff_path", $cmd_out_tmp, $curr_test_file);
|
||||
if (-d $lcov_results_dir) {
|
||||
move $lcov_results_dir, "$output_dir/$lcov_results_dir";
|
||||
for my $f ('lcov_coverage.info', 'lcov_coverage_final.info') {
|
||||
move $f, "$output_dir/$f" if -e $f;
|
||||
}
|
||||
} else {
|
||||
&write_test_file("[-] $lcov_results_dir does not exist.",
|
||||
$cmd_out_tmp, $curr_test_file);
|
||||
$rv = 0;
|
||||
}
|
||||
|
||||
if (-d "${output_dir}.last") {
|
||||
&run_cmd("./$coverage_diff_path", $cmd_out_tmp, $curr_test_file);
|
||||
}
|
||||
|
||||
if ($username) {
|
||||
@ -1352,7 +1344,7 @@ sub profile_coverage() {
|
||||
system qq/find .. -name $extension | xargs -r chmod a+w/;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return $rv;
|
||||
}
|
||||
|
||||
sub fiu_run_fault_injection() {
|
||||
@ -1588,12 +1580,11 @@ sub config_recompile() {
|
||||
my $config_cmd = shift;
|
||||
|
||||
if ($enable_profile_coverage_check) {
|
||||
chdir 'test' or die $!;
|
||||
### we're recompiling, so remove any existing profile coverage
|
||||
### files since they will be invalidated by the recompile
|
||||
for my $extension ('*.gcno', '*.gcda', '*.gcov') {
|
||||
### remove profile output from any previous run
|
||||
system qq{find . -name $extension | xargs rm 2> /dev/null};
|
||||
}
|
||||
&run_cmd("./test/$profile_rm_prev_sh", $cmd_out_tmp, $curr_test_file);
|
||||
chdir '..' or die $!;
|
||||
}
|
||||
|
||||
&run_cmd('make clean', $cmd_out_tmp, "test/$curr_test_file");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user