on master help sign in
Add coverage option to test.sh script
4dc0167Harendra Kumar
bin/bench.sh+5−5
@@ -66,10 +66,10 @@ list_comparisons () {
66# chart is expensive to build and usually not required to be rebuilt,
66# chart is expensive to build and usually not required to be rebuilt,
67# use master branch as fallback
67# use master branch as fallback
68cabal_which_report() {
68cabal_which_report() {
69− local path=$(cabal_which streamly-benchmarks $1)
69+ local path=$(cabal_which streamly-benchmarks x $1)
70 if test -z "$path"
70 if test -z "$path"
71 then
71 then
72− cabal_which_builddir dist-newstyle streamly-benchmarks $1
72+ cabal_which_builddir dist-newstyle streamly-benchmarks x $1
73 else
73 else
74 echo $path
74 echo $path
75 fi
75 fi
@@ -199,14 +199,14 @@ run_benches_comparing() {
199 git checkout "$BASE" || die "Checkout of base commit [$BASE] failed"
199 git checkout "$BASE" || die "Checkout of base commit [$BASE] failed"
200
200
201 $BUILD_BENCH || die "build failed"
201 $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
203
203
204 echo "Checking out candidate commit [$CANDIDATE] for benchmarking"
204 echo "Checking out candidate commit [$CANDIDATE] for benchmarking"
205 git checkout "$CANDIDATE" || \
205 git checkout "$CANDIDATE" || \
206 die "Checkout of candidate [$CANDIDATE] commit failed"
206 die "Checkout of candidate [$CANDIDATE] commit failed"
207
207
208 $BUILD_BENCH || die "build failed"
208 $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
210 # XXX reset back to the original commit
210 # XXX reset back to the original commit
211}
211}
212
212
@@ -230,7 +230,7 @@ run_measurements() {
230
230
231 if test "$COMPARE" = "0"
231 if test "$COMPARE" = "0"
232 then
232 then
233− run_targets streamly-benchmarks "$bench_list" target_exe_extra_args
233+ run_targets streamly-benchmarks b "$bench_list" target_exe_extra_args
234 else
234 else
235 run_benches_comparing "$bench_list"
235 run_benches_comparing "$bench_list"
236 fi
236 fi
bin/build-lib.sh+24−15
@@ -116,9 +116,11 @@ set_targets() {
116# The path is dependent on the architecture and cabal version.
116# The path is dependent on the architecture and cabal version.
117
117
118# $1: package name
118# $1: package name
119+# $2: component
119−# $2: target
120+# $3: target
120cabal_target_prog () {
121cabal_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
122 if test -x "$target_prog"
124 if test -x "$target_prog"
123 then
125 then
124 echo $target_prog
126 echo $target_prog
@@ -157,15 +159,18 @@ set_common_vars () {
157
159
158# $1: builddir
160# $1: builddir
159# $2: package name
161# $2: package name
162+# $3: component ("" (lib), t (test), b (benchmark), x (executable))
160−# $3: command to find
163+# $4: command to find
161cabal_which_builddir() {
164cabal_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
163}
167}
164
168
165# $1: package name
169# $1: package name
170+# $2: component
166−# $2: command to find
171+# $3: command to find
167cabal_which() {
172cabal_which() {
168− cabal_which_builddir $BUILD_DIR $1 $2
173+ cabal_which_builddir $BUILD_DIR $1 $2 $3
169}
174}
170
175
171# $1: build program
176# $1: build program
@@ -187,32 +192,36 @@ run_build () {
187}
192}
188
193
189# $1: package name
194# $1: package name
190−# $2: target
195+# $2: component
196+# $3: target
191−# $3: args generator func
197+# $4: args generator func
192run_target () {
198run_target () {
193 local package_name=$1
199 local package_name=$1
194− local target_name=$2
200+ local component=$2
195− local extra_args=$3
201+ local target_name=$3
202+ local extra_args=$4
196
203
197 local target_prog
204 local target_prog
198− target_prog=$(cabal_target_prog $package_name $target_name) || \
205+ target_prog=$(cabal_target_prog $package_name $component $target_name) || \
199 die "Cannot find executable for target $target_name"
206 die "Cannot find executable for target $target_name"
200
207
201 echo "Running executable $target_name ..."
208 echo "Running executable $target_name ..."
202
209
203 # Needed by bench-exec-one.sh
210 # Needed by bench-exec-one.sh
204 export BENCH_EXEC_PATH=$target_prog
211 export BENCH_EXEC_PATH=$target_prog
212+ export HPCTIXFILE=$BUILD_DIR/coverage/$target_name.tix
205
213
206 run_verbose $target_prog $($extra_args $target_name $target_prog) \
214 run_verbose $target_prog $($extra_args $target_name $target_prog) \
207 || die "Target exe failed"
215 || die "Target exe failed"
208}
216}
209
217
210# $1: package name
218# $1: package name
211−# $2: targets
219+# $2: component
220+# $3: targets
212−# $3: args generator func
221+# $4: args generator func
213run_targets() {
222run_targets() {
214− for i in $2
223+ for i in $3
215 do
224 do
216− run_target $1 $i $3
225+ run_target $1 $2 $i $4
217 done
226 done
218}
227}
bin/test.sh+53−2
@@ -31,6 +31,9 @@ RUNNING_TESTS=y
31source $SCRIPT_DIR/build-lib.sh
31source $SCRIPT_DIR/build-lib.sh
32
32
33set_common_vars
33set_common_vars
34+COVERAGE=
35+MEASURE=1
36+HPC_REPORT_OPTIONS=
34
37
35# XXX add a bisect option
38# XXX add a bisect option
36while test -n "$1"
39while test -n "$1"
@@ -40,11 +43,14 @@ do
40 # options with arguments
43 # options with arguments
41 --targets) shift; TARGETS=$1; shift ;;
44 --targets) shift; TARGETS=$1; shift ;;
42 --cabal-build-options) shift; CABAL_BUILD_OPTIONS=$1; shift ;;
45 --cabal-build-options) shift; CABAL_BUILD_OPTIONS=$1; shift ;;
46+ --hpc-report-options) shift; HPC_REPORT_OPTIONS=$1; shift ;;
43 --rtsopts) shift; RTS_OPTIONS=$1; shift ;;
47 --rtsopts) shift; RTS_OPTIONS=$1; shift ;;
44 # flags
48 # flags
45 --slow) SLOW=1; shift ;;
49 --slow) SLOW=1; shift ;;
46 --quick) QUICK_MODE=1; shift ;;
50 --quick) QUICK_MODE=1; shift ;;
47 --dev-build) RUNNING_DEVBUILD=1; shift ;;
51 --dev-build) RUNNING_DEVBUILD=1; shift ;;
52+ --coverage) COVERAGE=1; shift ;;
53+ --no-measure) MEASURE=0; shift ;;
48 --) shift; break ;;
54 --) shift; break ;;
49 -*|--*) echo "Unknown flags: $*"; echo; print_help ;;
55 -*|--*) echo "Unknown flags: $*"; echo; print_help ;;
50 *) break ;;
56 *) break ;;
@@ -77,7 +83,12 @@ echo "Using targets [$TARGETS]"
77
83
78test_exe_rts_opts () {
84test_exe_rts_opts () {
79 case "$1" in
85 case "$1" in
86+ *) if test "$COVERAGE" -eq "1"
87+ then
88+ echo -n "-K8M -M1024M"
89+ else
80− *) echo -n "-K8M -M64M" ;;
90+ echo -n "-K8M -M64M"
91+ fi ;;
81 esac
92 esac
82}
93}
83
94
@@ -93,11 +104,51 @@ target_exe_extra_args () {
93 -RTS"
104 -RTS"
94}
105}
95
106
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
96BUILD_TEST="$CABAL_EXECUTABLE v2-build $CABAL_BUILD_OPTIONS --enable-tests"
115BUILD_TEST="$CABAL_EXECUTABLE v2-build $CABAL_BUILD_OPTIONS --enable-tests"
116+
117+if test "$MEASURE" -eq "1"
118+then
97run_build "$BUILD_TEST" streamly-tests test "$TARGETS"
119run_build "$BUILD_TEST" streamly-tests test "$TARGETS"
120+fi
98
121
99#-----------------------------------------------------------------------------
122#-----------------------------------------------------------------------------
100# Run targets
123# Run targets
101#-----------------------------------------------------------------------------
124#-----------------------------------------------------------------------------
102
125
126+if test "$MEASURE" -eq "1"
127+then
103−run_targets streamly-tests "$TARGETS" target_exe_extra_args
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