on master help sign in
Add coverage option to test.sh script
commit4dc01677c74520d861bf4dae092ee4d6c0609f10 authorHarendra Kumar <harendra@composewell.com> dateSat 26 Dec 2020, 12:54 (6 years ago) parent1b1cbbd
3 files changed+82−22
bin/bench.sh+5−5 bin/build-lib.sh+24−15 bin/test.sh+53−2
bin/bench.sh+5−5
@@ -66,10 +66,10 @@ list_comparisons () {
6666# chart is expensive to build and usually not required to be rebuilt,
6767# use master branch as fallback
6868cabal_which_report() {
69− local path=$(cabal_which streamly-benchmarks $1)
69+ local path=$(cabal_which streamly-benchmarks x $1)
7070 if test -z "$path"
7171 then
72− cabal_which_builddir dist-newstyle streamly-benchmarks $1
72+ cabal_which_builddir dist-newstyle streamly-benchmarks x $1
7373 else
7474 echo $path
7575 fi
@@ -199,14 +199,14 @@ run_benches_comparing() {
199199 git checkout "$BASE" || die "Checkout of base commit [$BASE] failed"
200200
201201 $BUILD_BENCH || die "build failed"
202− run_targets streamly-benchmarks "$bench_list" target_exe_extra_args
202+ run_targets streamly-benchmarks b "$bench_list" target_exe_extra_args
203203
204204 echo "Checking out candidate commit [$CANDIDATE] for benchmarking"
205205 git checkout "$CANDIDATE" || \
206206 die "Checkout of candidate [$CANDIDATE] commit failed"
207207
208208 $BUILD_BENCH || die "build failed"
209− run_targets streamly-benchmarks "$bench_list" target_exe_extra_args
209+ run_targets streamly-benchmarks b "$bench_list" target_exe_extra_args
210210 # XXX reset back to the original commit
211211}
212212
@@ -230,7 +230,7 @@ run_measurements() {
230230
231231 if test "$COMPARE" = "0"
232232 then
233− run_targets streamly-benchmarks "$bench_list" target_exe_extra_args
233+ run_targets streamly-benchmarks b "$bench_list" target_exe_extra_args
234234 else
235235 run_benches_comparing "$bench_list"
236236 fi
bin/build-lib.sh+24−15
@@ -116,9 +116,11 @@ set_targets() {
116116# The path is dependent on the architecture and cabal version.
117117
118118# $1: package name
119−# $2: target
119+# $2: component
120+# $3: target
120121cabal_target_prog () {
121− local target_prog=`cabal_which $1 $2`
122+ local target_prog=`cabal_which $1 $2 $3`
123+ echo $target_prog 1>&2
122124 if test -x "$target_prog"
123125 then
124126 echo $target_prog
@@ -157,15 +159,18 @@ set_common_vars () {
157159
158160# $1: builddir
159161# $2: package name
160−# $3: command to find
162+# $3: component ("" (lib), t (test), b (benchmark), x (executable))
163+# $4: command to find
161164cabal_which_builddir() {
162− find $1 -type f -path "*${GHC_VERSION}/${2}*/$3" 2>/dev/null
165+ local path=$(echo $1/build/*/ghc-${GHC_VERSION}/${2}-0.0.0/$3/$4/build/$4/$4)
166+ test -f "$path" && echo $path
163167}
164168
165169# $1: package name
166−# $2: command to find
170+# $2: component
171+# $3: command to find
167172cabal_which() {
168− cabal_which_builddir $BUILD_DIR $1 $2
173+ cabal_which_builddir $BUILD_DIR $1 $2 $3
169174}
170175
171176# $1: build program
@@ -187,32 +192,36 @@ run_build () {
187192}
188193
189194# $1: package name
190−# $2: target
191−# $3: args generator func
195+# $2: component
196+# $3: target
197+# $4: args generator func
192198run_target () {
193199 local package_name=$1
194− local target_name=$2
195− local extra_args=$3
200+ local component=$2
201+ local target_name=$3
202+ local extra_args=$4
196203
197204 local target_prog
198− target_prog=$(cabal_target_prog $package_name $target_name) || \
205+ target_prog=$(cabal_target_prog $package_name $component $target_name) || \
199206 die "Cannot find executable for target $target_name"
200207
201208 echo "Running executable $target_name ..."
202209
203210 # Needed by bench-exec-one.sh
204211 export BENCH_EXEC_PATH=$target_prog
212+ export HPCTIXFILE=$BUILD_DIR/coverage/$target_name.tix
205213
206214 run_verbose $target_prog $($extra_args $target_name $target_prog) \
207215 || die "Target exe failed"
208216}
209217
210218# $1: package name
211−# $2: targets
212−# $3: args generator func
219+# $2: component
220+# $3: targets
221+# $4: args generator func
213222run_targets() {
214− for i in $2
223+ for i in $3
215224 do
216− run_target $1 $i $3
225+ run_target $1 $2 $i $4
217226 done
218227}
bin/test.sh+53−2
@@ -31,6 +31,9 @@ RUNNING_TESTS=y
3131source $SCRIPT_DIR/build-lib.sh
3232
3333set_common_vars
34+COVERAGE=
35+MEASURE=1
36+HPC_REPORT_OPTIONS=
3437
3538# XXX add a bisect option
3639while test -n "$1"
@@ -40,11 +43,14 @@ do
4043 # options with arguments
4144 --targets) shift; TARGETS=$1; shift ;;
4245 --cabal-build-options) shift; CABAL_BUILD_OPTIONS=$1; shift ;;
46+ --hpc-report-options) shift; HPC_REPORT_OPTIONS=$1; shift ;;
4347 --rtsopts) shift; RTS_OPTIONS=$1; shift ;;
4448 # flags
4549 --slow) SLOW=1; shift ;;
4650 --quick) QUICK_MODE=1; shift ;;
4751 --dev-build) RUNNING_DEVBUILD=1; shift ;;
52+ --coverage) COVERAGE=1; shift ;;
53+ --no-measure) MEASURE=0; shift ;;
4854 --) shift; break ;;
4955 -*|--*) echo "Unknown flags: $*"; echo; print_help ;;
5056 *) break ;;
@@ -77,7 +83,12 @@ echo "Using targets [$TARGETS]"
7783
7884test_exe_rts_opts () {
7985 case "$1" in
80− *) echo -n "-K8M -M64M" ;;
86+ *) if test "$COVERAGE" -eq "1"
87+ then
88+ echo -n "-K8M -M1024M"
89+ else
90+ echo -n "-K8M -M64M"
91+ fi ;;
8192 esac
8293}
8394
@@ -93,11 +104,51 @@ target_exe_extra_args () {
93104 -RTS"
94105}
95106
107+if test "$COVERAGE" -eq "1"
108+then
109+ # With the --enable-coverage option the tests as well as the library get
110+ # compiled with -fhpc, and we get coverage for tests as well. But we want to
111+ # exclude that, so a project file is needed.
112+ CABAL_BUILD_OPTIONS+=" --project-file cabal.project.coverage"
113+ mkdir -p $BUILD_DIR/coverage
114+fi
96115BUILD_TEST="$CABAL_EXECUTABLE v2-build $CABAL_BUILD_OPTIONS --enable-tests"
116+
117+if test "$MEASURE" -eq "1"
118+then
97119run_build "$BUILD_TEST" streamly-tests test "$TARGETS"
120+fi
98121
99122#-----------------------------------------------------------------------------
100123# Run targets
101124#-----------------------------------------------------------------------------
102125
103−run_targets streamly-tests "$TARGETS" target_exe_extra_args
126+if test "$MEASURE" -eq "1"
127+then
128+run_targets streamly-tests t "$TARGETS" target_exe_extra_args
129+fi
130+
131+#-----------------------------------------------------------------------------
132+# Run coverage reports
133+#-----------------------------------------------------------------------------
134+
135+if test "$COVERAGE" -eq "1"
136+then
137+ TIXFILES=
138+ for i in $TARGETS
139+ do
140+ TIXFILES+="$BUILD_DIR/coverage/${i}.tix "
141+ done
142+
143+ case `uname` in
144+ Linux) SYSTEM=x86_64-linux ;;
145+ *) echo "Unsupported system"; exit 1 ;;
146+ esac
147+
148+ ALLTIX=$BUILD_DIR/coverage/all.tix
149+ hpc sum --output=$ALLTIX $TIXFILES
150+ run_verbose hpc markup $ALLTIX --hpcdir \
151+ $BUILD_DIR/build/$SYSTEM/ghc-${GHC_VERSION}/streamly-0.7.2/hpc/vanilla/mix/streamly-0.7.2/
152+ run_verbose hpc report $ALLTIX $HPC_REPORT_OPTIONS --hpcdir \
153+ $BUILD_DIR/build/$SYSTEM/ghc-${GHC_VERSION}/streamly-0.7.2/hpc/vanilla/mix/streamly-0.7.2/
154+fi