Add coverage option to test.sh script

This commit is contained in:
Harendra Kumar 2020-12-26 12:54:45 +05:30
parent 1b1cbbd16d
commit 4dc01677c7
3 changed files with 82 additions and 22 deletions

View File

@ -66,10 +66,10 @@ list_comparisons () {
# chart is expensive to build and usually not required to be rebuilt,
# use master branch as fallback
cabal_which_report() {
local path=$(cabal_which streamly-benchmarks $1)
local path=$(cabal_which streamly-benchmarks x $1)
if test -z "$path"
then
cabal_which_builddir dist-newstyle streamly-benchmarks $1
cabal_which_builddir dist-newstyle streamly-benchmarks x $1
else
echo $path
fi
@ -199,14 +199,14 @@ run_benches_comparing() {
git checkout "$BASE" || die "Checkout of base commit [$BASE] failed"
$BUILD_BENCH || die "build failed"
run_targets streamly-benchmarks "$bench_list" target_exe_extra_args
run_targets streamly-benchmarks b "$bench_list" target_exe_extra_args
echo "Checking out candidate commit [$CANDIDATE] for benchmarking"
git checkout "$CANDIDATE" || \
die "Checkout of candidate [$CANDIDATE] commit failed"
$BUILD_BENCH || die "build failed"
run_targets streamly-benchmarks "$bench_list" target_exe_extra_args
run_targets streamly-benchmarks b "$bench_list" target_exe_extra_args
# XXX reset back to the original commit
}
@ -230,7 +230,7 @@ run_measurements() {
if test "$COMPARE" = "0"
then
run_targets streamly-benchmarks "$bench_list" target_exe_extra_args
run_targets streamly-benchmarks b "$bench_list" target_exe_extra_args
else
run_benches_comparing "$bench_list"
fi

View File

@ -116,9 +116,11 @@ set_targets() {
# The path is dependent on the architecture and cabal version.
# $1: package name
# $2: target
# $2: component
# $3: target
cabal_target_prog () {
local target_prog=`cabal_which $1 $2`
local target_prog=`cabal_which $1 $2 $3`
echo $target_prog 1>&2
if test -x "$target_prog"
then
echo $target_prog
@ -157,15 +159,18 @@ set_common_vars () {
# $1: builddir
# $2: package name
# $3: command to find
# $3: component ("" (lib), t (test), b (benchmark), x (executable))
# $4: command to find
cabal_which_builddir() {
find $1 -type f -path "*${GHC_VERSION}/${2}*/$3" 2>/dev/null
local path=$(echo $1/build/*/ghc-${GHC_VERSION}/${2}-0.0.0/$3/$4/build/$4/$4)
test -f "$path" && echo $path
}
# $1: package name
# $2: command to find
# $2: component
# $3: command to find
cabal_which() {
cabal_which_builddir $BUILD_DIR $1 $2
cabal_which_builddir $BUILD_DIR $1 $2 $3
}
# $1: build program
@ -187,32 +192,36 @@ run_build () {
}
# $1: package name
# $2: target
# $3: args generator func
# $2: component
# $3: target
# $4: args generator func
run_target () {
local package_name=$1
local target_name=$2
local extra_args=$3
local component=$2
local target_name=$3
local extra_args=$4
local target_prog
target_prog=$(cabal_target_prog $package_name $target_name) || \
target_prog=$(cabal_target_prog $package_name $component $target_name) || \
die "Cannot find executable for target $target_name"
echo "Running executable $target_name ..."
# Needed by bench-exec-one.sh
export BENCH_EXEC_PATH=$target_prog
export HPCTIXFILE=$BUILD_DIR/coverage/$target_name.tix
run_verbose $target_prog $($extra_args $target_name $target_prog) \
|| die "Target exe failed"
}
# $1: package name
# $2: targets
# $3: args generator func
# $2: component
# $3: targets
# $4: args generator func
run_targets() {
for i in $2
for i in $3
do
run_target $1 $i $3
run_target $1 $2 $i $4
done
}

View File

@ -31,6 +31,9 @@ RUNNING_TESTS=y
source $SCRIPT_DIR/build-lib.sh
set_common_vars
COVERAGE=
MEASURE=1
HPC_REPORT_OPTIONS=
# XXX add a bisect option
while test -n "$1"
@ -40,11 +43,14 @@ do
# options with arguments
--targets) shift; TARGETS=$1; shift ;;
--cabal-build-options) shift; CABAL_BUILD_OPTIONS=$1; shift ;;
--hpc-report-options) shift; HPC_REPORT_OPTIONS=$1; shift ;;
--rtsopts) shift; RTS_OPTIONS=$1; shift ;;
# flags
--slow) SLOW=1; shift ;;
--quick) QUICK_MODE=1; shift ;;
--dev-build) RUNNING_DEVBUILD=1; shift ;;
--coverage) COVERAGE=1; shift ;;
--no-measure) MEASURE=0; shift ;;
--) shift; break ;;
-*|--*) echo "Unknown flags: $*"; echo; print_help ;;
*) break ;;
@ -77,7 +83,12 @@ echo "Using targets [$TARGETS]"
test_exe_rts_opts () {
case "$1" in
*) echo -n "-K8M -M64M" ;;
*) if test "$COVERAGE" -eq "1"
then
echo -n "-K8M -M1024M"
else
echo -n "-K8M -M64M"
fi ;;
esac
}
@ -93,11 +104,51 @@ target_exe_extra_args () {
-RTS"
}
if test "$COVERAGE" -eq "1"
then
# With the --enable-coverage option the tests as well as the library get
# compiled with -fhpc, and we get coverage for tests as well. But we want to
# exclude that, so a project file is needed.
CABAL_BUILD_OPTIONS+=" --project-file cabal.project.coverage"
mkdir -p $BUILD_DIR/coverage
fi
BUILD_TEST="$CABAL_EXECUTABLE v2-build $CABAL_BUILD_OPTIONS --enable-tests"
if test "$MEASURE" -eq "1"
then
run_build "$BUILD_TEST" streamly-tests test "$TARGETS"
fi
#-----------------------------------------------------------------------------
# Run targets
#-----------------------------------------------------------------------------
run_targets streamly-tests "$TARGETS" target_exe_extra_args
if test "$MEASURE" -eq "1"
then
run_targets streamly-tests t "$TARGETS" target_exe_extra_args
fi
#-----------------------------------------------------------------------------
# Run coverage reports
#-----------------------------------------------------------------------------
if test "$COVERAGE" -eq "1"
then
TIXFILES=
for i in $TARGETS
do
TIXFILES+="$BUILD_DIR/coverage/${i}.tix "
done
case `uname` in
Linux) SYSTEM=x86_64-linux ;;
*) echo "Unsupported system"; exit 1 ;;
esac
ALLTIX=$BUILD_DIR/coverage/all.tix
hpc sum --output=$ALLTIX $TIXFILES
run_verbose hpc markup $ALLTIX --hpcdir \
$BUILD_DIR/build/$SYSTEM/ghc-${GHC_VERSION}/streamly-0.7.2/hpc/vanilla/mix/streamly-0.7.2/
run_verbose hpc report $ALLTIX $HPC_REPORT_OPTIONS --hpcdir \
$BUILD_DIR/build/$SYSTEM/ghc-${GHC_VERSION}/streamly-0.7.2/hpc/vanilla/mix/streamly-0.7.2/
fi