on a7efa76 help sign in
streamly/bin/test.sh
175 lines 5.1 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 " [--with-compiler <compiler exe name>]"
13 echo " [--cabal-build-options <option>]"
14 echo " [--dev-build]"
15 echo " [--coverage]"
16 echo " [--hpc-report-options <option>]"
17 echo " [--no-measure]"
18 echo " [--raw]"
19 echo " [--rtsopts <option>]"
20 echo " -- <hspec options or test names>"
21 echo
22 echo "--targets: targets to run, use 'help' for list of targets"
23 echo "--cabal-build-options: Pass any cabal build options to be used for build"
24 echo "--dev-build: runs some additional tests"
25 echo "--coverage: enable coverage and report coverage info"
26 echo "--hpc-report-options: option for 'hpc report'"
27 echo "--no-measure: with --coverage, do not run tests, only show coverage info"
28 echo "--raw: with --coverage, do not run hpc"
29 echo "--rtsopts: pass GHC RTS options to the test executable"
30 echo
31 echo "Any arguments after a '--' are passed directly to hspec"
32 exit
35#-----------------------------------------------------------------------------
36# Read command line
37#-----------------------------------------------------------------------------
39RUNNING_TESTS=y
40source $SCRIPT_DIR/build-lib.sh
42USE_GIT_CABAL=1
43set_common_vars
44COVERAGE=0
45MEASURE=1
46HPC_REPORT_OPTIONS=
47RAW=0
49# XXX add a bisect option
50while test -n "$1"
51do
52 case $1 in
53 -h|--help|help) print_help ;;
54 # options with arguments
55 --targets) shift; TARGETS=$1; shift ;;
56 --with-compiler) shift; CABAL_WITH_COMPILER=$1; shift ;;
57 --cabal-build-options) shift; CABAL_BUILD_OPTIONS=$1; shift ;;
58 --hpc-report-options) shift; HPC_REPORT_OPTIONS=$1; shift ;;
59 --rtsopts) shift; RTS_OPTIONS=$1; shift ;;
60 # flags
61 --raw) RAW=1; shift ;;
62 #--slow) SLOW=1; shift ;; # not implemented
63 #--quick) QUICK_MODE=1; shift ;; # not implemented
64 --dev-build) RUNNING_DEVBUILD=1; shift ;;
65 --coverage) COVERAGE=1; shift ;;
66 --no-measure) MEASURE=0; shift ;;
67 --) shift; break ;;
68 -*|--*) echo "Unknown flags: $*"; echo; print_help ;;
69 *) break ;;
70 esac
71done
72TARGET_EXE_ARGS=$*
74set_derived_vars
76#-----------------------------------------------------------------------------
77# Determine targets
78#-----------------------------------------------------------------------------
80# Requires RUNNING_DEVBUILD var
81source $SCRIPT_DIR/targets.sh
83if test "$(has_item "$TARGETS" help)" = "help"
84then
85 list_target_groups
86 list_targets
87 exit
88fi
90DEFAULT_TARGETS="$(all_grp)"
91TARGETS=$(set_targets)
93echo "Using targets [$TARGETS]"
95#-----------------------------------------------------------------------------
96# Build targets
97#-----------------------------------------------------------------------------
99test_exe_rts_opts () {
100 case "$1" in
101 *) if test "$COVERAGE" -eq "1"
102 then
103 echo -n "-K8M -M1024M"
104 else
105 echo -n "-K8M -M64M"
106 fi ;;
107 esac
110# $1: bench name
111# $2: bench executable
112target_exe_extra_args () {
113 local bench_name=$1
114 local bench_prog=$2
116 echo "+RTS \
117 $(test_exe_rts_opts $(basename $bench_prog)) \
118 $RTS_OPTIONS \
119 -RTS"
122if test "$COVERAGE" -eq "1"
123then
124 # Used to determine the hpc tix dir
125 PACKAGE_FULL_NAME=streamly-0.7.2
126 case `uname` in
127 Linux) SYSTEM=x86_64-linux ;;
128 *) echo "Unsupported system"; exit 1 ;;
129 esac
131 # With the --enable-coverage option the tests as well as the library get
132 # compiled with -fhpc, and we get coverage for tests as well. But we want to
133 # exclude that, so a project file is needed.
134 CABAL_BUILD_OPTIONS+=" --project-file cabal.project.coverage"
135 mkdir -p $BUILD_DIR/hpc
136fi
137BUILD_TEST="$CABAL_EXECUTABLE v2-build $CABAL_BUILD_OPTIONS --enable-tests"
139if test "$MEASURE" -eq "1"
140then
141run_build "$BUILD_TEST" streamly-tests test "$TARGETS"
142fi
144#-----------------------------------------------------------------------------
145# Run targets
146#-----------------------------------------------------------------------------
148if test "$MEASURE" -eq "1"
149then
150run_targets streamly-tests t "$TARGETS" target_exe_extra_args
151fi
153#-----------------------------------------------------------------------------
154# Run coverage reports
155#-----------------------------------------------------------------------------
157if test "$COVERAGE" -eq "1" -a "$RAW" -eq 0
158then
159 TIXFILES=
160 for i in $TARGETS
161 do
162 tixfile="$(get_tix_file ${i})"
163 if test -f "$tixfile"
164 then
165 TIXFILES+="$tixfile "
166 fi
167 done
169 ALLTIX=$BUILD_DIR/hpc/all.tix
170 hpc sum --output=$ALLTIX $TIXFILES
171 run_verbose hpc markup $ALLTIX --hpcdir \
172 $BUILD_DIR/build/$SYSTEM/ghc-${GHC_VERSION}/streamly-0.7.2/hpc/vanilla/mix/streamly-0.7.2/
173 run_verbose hpc report $ALLTIX $HPC_REPORT_OPTIONS --hpcdir \
174 $BUILD_DIR/build/$SYSTEM/ghc-${GHC_VERSION}/streamly-0.7.2/hpc/vanilla/mix/streamly-0.7.2/
175fi