@@ -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