on ec19422 help sign in
streamly/bin/test.sh
163 lines 4.5 kB history raw
1#!/usr/bin/env bash
3#------------------------------------------------------------------------------
4# Script
5#------------------------------------------------------------------------------
7SCRIPT_DIR=$(dirname $0)
9print_help () {
10 echo "Usage: $0 "
11 echo " [--targets <"target1 target2 ..." | help>]"
12 echo " [--slow]"
13 echo " [--quick]"
14 echo " [--cabal-build-options <option>]"
15 echo " -- <hspec options or test names>"
16 echo
17 echo "--targets: targets to run, use 'help' for list of targets"
18 echo "--slow: take longer but run more tests"
19 echo "--quick: faster but run fewer tests"
20 echo "--cabal-build-options: Pass any cabal build options to be used for build"
21 echo
22 echo "Any arguments after a '--' are passed directly to hspec"
23 exit
26#-----------------------------------------------------------------------------
27# Read command line
28#-----------------------------------------------------------------------------
30RUNNING_TESTS=y
31source $SCRIPT_DIR/build-lib.sh
33USE_GIT_CABAL=1
34set_common_vars
35COVERAGE=0
36MEASURE=1
37HPC_REPORT_OPTIONS=
38RAW=0
40# XXX add a bisect option
41while test -n "$1"
42do
43 case $1 in
44 -h|--help|help) print_help ;;
45 # options with arguments
46 --targets) shift; TARGETS=$1; shift ;;
47 --cabal-build-options) shift; CABAL_BUILD_OPTIONS=$1; shift ;;
48 --hpc-report-options) shift; HPC_REPORT_OPTIONS=$1; shift ;;
49 --rtsopts) shift; RTS_OPTIONS=$1; shift ;;
50 # flags
51 --raw) RAW=1; shift ;;
52 --slow) SLOW=1; shift ;;
53 --quick) QUICK_MODE=1; shift ;;
54 --dev-build) RUNNING_DEVBUILD=1; shift ;;
55 --coverage) COVERAGE=1; shift ;;
56 --no-measure) MEASURE=0; shift ;;
57 --) shift; break ;;
58 -*|--*) echo "Unknown flags: $*"; echo; print_help ;;
59 *) break ;;
60 esac
61done
62TARGET_EXE_ARGS=$*
64#-----------------------------------------------------------------------------
65# Determine targets
66#-----------------------------------------------------------------------------
68# Requires RUNNING_DEVBUILD var
69source $SCRIPT_DIR/targets.sh
71if test "$(has_item "$TARGETS" help)" = "help"
72then
73 list_target_groups
74 list_targets
75 exit
76fi
78DEFAULT_TARGETS="$(all_grp)"
79TARGETS=$(set_targets)
81echo "Using targets [$TARGETS]"
83#-----------------------------------------------------------------------------
84# Build targets
85#-----------------------------------------------------------------------------
87test_exe_rts_opts () {
88 case "$1" in
89 *) if test "$COVERAGE" -eq "1"
90 then
91 echo -n "-K8M -M1024M"
92 else
93 echo -n "-K8M -M64M"
94 fi ;;
95 esac
98# $1: bench name
99# $2: bench executable
100target_exe_extra_args () {
101 local bench_name=$1
102 local bench_prog=$2
104 echo "+RTS \
105 $(test_exe_rts_opts $(basename $bench_prog)) \
106 $RTS_OPTIONS \
107 -RTS"
110if test "$COVERAGE" -eq "1"
111then
112 # Used to determine the hpc tix dir
113 PACKAGE_FULL_NAME=streamly-0.7.2
114 case `uname` in
115 Linux) SYSTEM=x86_64-linux ;;
116 *) echo "Unsupported system"; exit 1 ;;
117 esac
119 # With the --enable-coverage option the tests as well as the library get
120 # compiled with -fhpc, and we get coverage for tests as well. But we want to
121 # exclude that, so a project file is needed.
122 CABAL_BUILD_OPTIONS+=" --project-file cabal.project.coverage"
123 mkdir -p $BUILD_DIR/hpc
124fi
125BUILD_TEST="$CABAL_EXECUTABLE v2-build $CABAL_BUILD_OPTIONS --enable-tests"
127if test "$MEASURE" -eq "1"
128then
129run_build "$BUILD_TEST" streamly-tests test "$TARGETS"
130fi
132#-----------------------------------------------------------------------------
133# Run targets
134#-----------------------------------------------------------------------------
136if test "$MEASURE" -eq "1"
137then
138run_targets streamly-tests t "$TARGETS" target_exe_extra_args
139fi
141#-----------------------------------------------------------------------------
142# Run coverage reports
143#-----------------------------------------------------------------------------
145if test "$COVERAGE" -eq "1" -a "$RAW" -eq 0
146then
147 TIXFILES=
148 for i in $TARGETS
149 do
150 tixfile="$(get_tix_file ${i})"
151 if test -f "$tixfile"
152 then
153 TIXFILES+="$tixfile "
154 fi
155 done
157 ALLTIX=$BUILD_DIR/hpc/all.tix
158 hpc sum --output=$ALLTIX $TIXFILES
159 run_verbose hpc markup $ALLTIX --hpcdir \
160 $BUILD_DIR/build/$SYSTEM/ghc-${GHC_VERSION}/streamly-0.7.2/hpc/vanilla/mix/streamly-0.7.2/
161 run_verbose hpc report $ALLTIX $HPC_REPORT_OPTIONS --hpcdir \
162 $BUILD_DIR/build/$SYSTEM/ghc-${GHC_VERSION}/streamly-0.7.2/hpc/vanilla/mix/streamly-0.7.2/
163fi