on 83d6019 help sign in
streamly/bin/test.sh
245 lines 6.9 kB history raw
1#!/usr/bin/env bash
3SCRIPT_DIR=$(dirname $0)
5STREAMLY_VERSION=0.8.0
6BENCH_REPORT_DIR=benchmark/bench-report
7source $SCRIPT_DIR/targets.sh
9#------------------------------------------------------------------------------
10# Script
11#------------------------------------------------------------------------------
13print_help () {
14 echo "Usage: $0 "
15 echo " [--targets <"target1 target2 ..." | help>]"
16 echo
17 echo " [--quick]"
18 echo " [--with-compiler <compiler exe name>]"
19 echo " [--cabal-build-options <option>]"
20 echo " [--dev-build]"
21 echo
22 echo " [--coverage]"
23 echo " [--hpc-report-options <option>]"
24 echo " [--no-measure]"
25 echo " [--raw]"
26 echo
27 echo " [--rtsopts <option>]"
28 echo " -- <hspec options or test names>"
29 echo
30 echo "--targets: targets to run, use 'help' for list of targets"
31 echo
32 echo "--quick: disable optimizations to build quickly"
33 echo "--cabal-build-options: Pass any cabal build options to be used for build"
34 echo "--dev-build: runs some additional tests"
35 echo
36 echo "--coverage: enable coverage and report coverage info"
37 echo "--hpc-report-options: option for 'hpc report'"
38 echo "--no-measure: with --coverage, do not run tests, only show coverage info"
39 echo "--raw: with --coverage, do not run hpc"
40 echo
41 echo "--rtsopts: pass GHC RTS options to the test executable"
42 echo "Any arguments after a '--' are passed directly to hspec"
43 exit
46#-----------------------------------------------------------------------------
47# Read command line
48#-----------------------------------------------------------------------------
50RUNNING_TESTS=y
51source $BENCH_REPORT_DIR/bin/build-lib.sh
53USE_GIT_CABAL=1
54set_common_vars
55COVERAGE=0
56MEASURE=1
57HPC_REPORT_OPTIONS=
58RAW=0
59CABAL_BUILD_OPTIONS="--flag limit-build-mem"
60TEST_QUICK_MODE=0
62# XXX add a bisect option
63while test -n "$1"
64do
65 case $1 in
66 -h|--help|help) print_help ;;
67 # options with arguments
68 --targets) shift; TARGETS=$1; shift ;;
69 --with-compiler) shift; CABAL_WITH_COMPILER=$1; shift ;;
70 --cabal-build-options) shift; CABAL_BUILD_OPTIONS+=" $1"; shift ;;
71 --hpc-report-options) shift; HPC_REPORT_OPTIONS="$1"; shift ;;
72 --rtsopts) shift; RTS_OPTIONS="$1"; shift ;;
73 # flags
74 --raw) RAW=1; shift ;;
75 #--slow) SLOW=1; shift ;; # not implemented
76 --quick) TEST_QUICK_MODE=1; shift ;;
77 --dev-build) RUNNING_DEVBUILD=1 CABAL_BUILD_OPTIONS+=" --flag dev"; shift ;;
78 --coverage) COVERAGE=1; shift ;;
79 --no-measure) MEASURE=0; shift ;;
80 --) shift; break ;;
81 -*|--*) echo "Unknown flags: $*"; echo; print_help ;;
82 *) break ;;
83 esac
84done
85TARGET_EXE_ARGS=$*
87set_derived_vars
89if test "$TEST_QUICK_MODE" -eq 1
90then
91 CABAL_BUILD_OPTIONS+=" --disable-optimization --flags -opt"
92fi
94#-----------------------------------------------------------------------------
95# Determine targets
96#-----------------------------------------------------------------------------
98# Defined in targets.sh
99targets
101if test "$(has_item "$TARGETS" help)" = "help"
102then
103 list_target_groups
104 list_targets
105 exit
106fi
108DEFAULT_TARGETS="$(all_grp)"
109TARGETS=$(set_targets)
111echo "Using targets [$TARGETS]"
113#-----------------------------------------------------------------------------
114# Build targets
115#-----------------------------------------------------------------------------
117test_exe_rts_opts () {
118 case "$1" in
119 # XXX Data.Array.* heap requirement increased for GHC-8.10
120 Data.Array.Foreign) echo -n "-M128M" ;;
121 Data.Array.Prim) echo -n "-M128M" ;;
122 Data.Array.Prim.Pinned) echo -n "-M128M" ;;
123 Prelude.Rate) echo -n "-M512M" ;;
124 # For -O0 case writeChunks test fails, maybe we should have a separate flag
125 # for O0 case?
126 FileSystem.Handle) echo -n "-K16M" ;;
127 *) if test "$COVERAGE" -eq "1"
128 then
129 echo -n "-K8M -M1024M"
130 else
131 echo -n "-K8M -M64M"
132 fi ;;
133 esac
136# $1: bench name
137# $2: bench executable
138target_exe_extra_args () {
139 local bench_name=$1
140 local bench_prog=$2
142 echo "+RTS \
143 $(test_exe_rts_opts $(basename $bench_prog)) \
144 $RTS_OPTIONS \
145 -RTS"
148if test "$COVERAGE" -eq "1"
149then
150 # Used to determine the hpc tix dir
151 PACKAGE_FULL_NAME=streamly-$STREAMLY_VERSION
152 case `uname` in
153 Linux) SYSTEM=x86_64-linux ;;
154 *) echo "Unsupported system"; exit 1 ;;
155 esac
157 # With the --enable-coverage option the tests as well as the library get
158 # compiled with -fhpc, and we get coverage for tests as well. But we want to
159 # exclude that, so a project file is needed.
160 CABAL_BUILD_OPTIONS+=" --project-file cabal.project.coverage"
161 mkdir -p $BUILD_DIR/hpc
162fi
163BUILD_TEST="$CABAL_EXECUTABLE v2-build $CABAL_BUILD_OPTIONS --enable-tests"
165if test "$MEASURE" -eq "1"
166then
167run_build "$BUILD_TEST" streamly-tests test "$TARGETS"
168fi
170#-----------------------------------------------------------------------------
171# Run targets
172#-----------------------------------------------------------------------------
174# $1: target name
175get_tix_file () {
176 echo $BUILD_DIR/build/$SYSTEM/ghc-${GHC_VERSION}/$PACKAGE_FULL_NAME/hpc/vanilla/tix/$1/$1.tix
179# $1: package name
180# $2: component
181# $3: target
182# $4: args generator func
183run_target () {
184 local package_name=$1
185 local component=$2
186 local target_name=$3
187 local extra_args=$4
189 local target_prog
191 target_prog=$(cabal_target_prog $package_name $component $target_name) || \
192 die "Cannot find executable for target $target_name"
194 echo "Running executable $target_name ..."
196 mkdir -p $(dirname $(get_tix_file $target_name))
197 export HPCTIXFILE=$(get_tix_file $target_name)
199 run_verbose $target_prog $($extra_args $target_name $target_prog) \
200 || die "Target exe failed"
202 # hpc-coveralls fails if there is an empty dir and no .tix file generated
203 rmdir $(dirname $(get_tix_file $target_name)) 2>/dev/null || true
206# $1: package name with version
207# $2: component
208# $3: targets
209# $4: args generator func
210run_targets() {
211 for i in $3
212 do
213 run_target $1 $2 $i $4
214 done
217if test "$MEASURE" -eq "1"
218then
219run_targets "streamly-tests-0.0.0" t "$TARGETS" target_exe_extra_args
220fi
222#-----------------------------------------------------------------------------
223# Run coverage reports
224#-----------------------------------------------------------------------------
226PACKAGE_NAME=streamly-$STREAMLY_VERSION
227MIX_DIR=$BUILD_DIR/build/$SYSTEM/ghc-${GHC_VERSION}/$PACKAGE_NAME/hpc/vanilla/mix/$PACKAGE_NAME/
228ALLTIX=$BUILD_DIR/hpc/all.tix
230if test "$COVERAGE" -eq "1" -a "$RAW" -eq 0
231then
232 TIXFILES=
233 for i in $TARGETS
234 do
235 tixfile="$(get_tix_file ${i})"
236 if test -f "$tixfile"
237 then
238 TIXFILES+="$tixfile "
239 fi
240 done
242 hpc sum --output=$ALLTIX $TIXFILES
243 run_verbose hpc markup $ALLTIX --hpcdir $MIX_DIR
244 run_verbose hpc report $ALLTIX $HPC_REPORT_OPTIONS --hpcdir $MIX_DIR
245fi