validate 8.18 KB
Newer Older
1 2 3
#!/bin/sh

set -e
4

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
show_help () {
    cat <<EOF
Usage: $0 [FLAGS]...

Validate GHC source tree against testsuite; see
http://ghc.haskell.org/trac/ghc/wiki/TestingPatches for more
information.

Flags:
  --no-clean        don't make clean first, just carry on from
                    a previous interrupted validation run
  --testsuite-only  don't build the compiler, just run the test suite
  --hpc             build stage2 with -fhpc, and see how much of the
                    compiler the test suite covers.
                    2008-07-01: 63% slower than the default.
                    HTML generated here: testsuite/hpc_output/hpc_index.html
21 22 23
  --fast            Omit binary distribution. Omit certain tests.
  --slow            Build stage2 with -DDEBUG. Run tests for all WAYS,
                    but skip those that call compiler_stats_num_field.
24
                    2008-07-01: 14% slower than the default.
25 26
  --dph             Also build libraries/dph and run associated tests.
  --quiet           More pretty build log.
27
                    See Note [Default build system verbosity].
28 29
  --help            shows this usage help.

30 31 32
  validate runs 'make -j\$THREADS', where by default THREADS is the number of
  cpus your computer has +1. You can set the environment variable THREADS to
  override this. For a sequential build you would for example use
33

34
    THREADS=1 ./validate
35

36 37 38 39 40
  You can also use environment variables to pass extra options to the
  testsuite. For example:

    TEST='read001 read002' ./validate --testsuite-only --fast

41 42 43
EOF
}

44 45
no_clean=0
testsuite_only=0
46
hpc=NO
47
speed=NORMAL
48
use_dph=0
49
be_quiet=0
50 51 52 53 54 55 56 57 58 59

while [ $# -gt 0 ]
do
    case "$1" in
    --no-clean)
        no_clean=1
        ;;
    --testsuite-only)
        testsuite_only=1
        ;;
60
    --hpc)
61 62 63
        hpc=YES
        ;;
    --slow)
64
        speed=SLOW
65 66
        ;;
    --fast)
67 68
        speed=FAST
        ;;
69
    --normal) # for backward compat
70
        speed=NORMAL
71
        ;;
72 73 74
    --no-dph) # for backward compat
        use_dph=0
        ;;
75 76
    --dph)
        use_dph=1
77
        ;;
78 79 80
    --quiet)
        be_quiet=1
        ;;
81 82 83
    --help)
        show_help
        exit 0;;
84
    *)
85 86
        echo "$0: unrecognized argument '$1'" >&2
        echo "Try '$0 --help' for more information." >&2
87 88 89 90 91
        exit 1;;
    esac
    shift
done

92 93 94
check_packages () {
    if [ "$bindistdir" = "" ]
    then
thomie's avatar
thomie committed
95
        ghc_pkg=inplace/bin/ghc-pkg
96
    else
thomie's avatar
thomie committed
97 98 99 100 101 102 103 104 105 106
        ghc_pkg="$bindistdir"/bin/ghc-pkg
    fi

    if [ $be_quiet -eq 1 ]
    then
        "$ghc_pkg" check
    else
        echo "== Start $1 package check"
        "$ghc_pkg" check -v
        echo "== End $1 package check"
107 108 109
    fi
}

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
detect_cpu_count () {
    if [ "$CPUS" = "" ]; then
        # Windows standard environment variable
        CPUS="$NUMBER_OF_PROCESSORS"
    fi

    if [ "$CPUS" = "" ]; then
        # Linux
        CPUS=`getconf _NPROCESSORS_ONLN 2>/dev/null`
    fi

    if [ "$CPUS" = "" ]; then
        # FreeBSD
        CPUS=`getconf NPROCESSORS_ONLN 2>/dev/null`
    fi

    if [ "$CPUS" = "" ]; then
        # nothing helped
        CPUS="1"
    fi
}

detect_cpu_count

134 135
if ! [ -d testsuite ]
then
136
    echo 'Could not find the testsuite for validation' >&2
137 138 139
    exit 1
fi

140
if [ "$THREADS" = "" ]; then
141
    threads=$(($CPUS + 1)) # `expr $CPUS + 1`
142
else
143
    threads="$THREADS"
144 145
fi

146 147
echo "using THREADS=${threads}" >&2

148 149
if type gmake > /dev/null 2> /dev/null
then
150
    make="gmake"
151
else
152 153 154 155 156 157
    make="make"
fi

if [ $be_quiet -eq 1 ]; then
    # See Note [Default build system verbosity].
    make="$make -s"
158 159
fi

160 161
if [ $testsuite_only -eq 0 ]; then

162
if [ $no_clean -eq 0 ]; then
163
    $make maintainer-clean NO_CLEAN_GMP=YES
164

Ian Lynagh's avatar
Ian Lynagh committed
165
    INSTDIR=`pwd`/inst
Simon Marlow's avatar
Simon Marlow committed
166

167
    if [ $use_dph -eq 1 ]; then
168
        perl -w boot --validate --required-tag=dph
169
    else
170
        perl -w boot --validate
171
    fi
Ian Lynagh's avatar
Ian Lynagh committed
172
    ./configure --prefix="$INSTDIR" $config_args
Simon Marlow's avatar
Simon Marlow committed
173 174
fi

175
thisdir=`utils/ghc-pwd/dist-boot/ghc-pwd`
176

177
make_settings="Validating=YES ValidateSpeed=$speed ValidateHpc=$hpc"
178 179 180 181 182 183 184 185 186 187 188 189 190

# Note [Default build system verbosity].
#
# From https://ghc.haskell.org/trac/ghc/wiki/Design/BuildSystem:
#
#   "The build system should clearly report what it's doing (and sometimes
#   why), without being too verbose. It should emit actual command lines as
#   much as possible, so that they can be inspected and cut & pasted."
#
# That should be the default. Only suppress commands, by setting V=0 and using
# `make -s`, when user explicitly asks for it with `./validate --quiet`.
if [ $be_quiet -eq 1 ]; then
    # See Note [Default build system verbosity].
191
    make_settings="$make_settings V=0"
192
fi
193

194
if [ $use_dph -eq 1 ]; then
195
    make_settings="$make_settings BUILD_DPH=YES"
196 197
fi

198
$make -j$threads $make_settings
199
# For a "debug make", add "--debug=b --debug=m"
200

201 202
check_packages post-build

203 204 205 206 207
# -----------------------------------------------------------------------------
# Build and test a binary distribution (not --fast)

if [ $speed != "FAST" ]; then

208 209
    $make binary-dist-prep $make_settings
    $make test_bindist TEST_PREP=YES $make_settings
210

211
    #
212 213
    # Install the xhtml package into the bindist.
    # This verifies that we can install a package into the
214 215 216 217
    # bindist with Cabal.
    #
    bindistdir="bindisttest/install   dir"

218 219
    check_packages post-install

220
    $make validate_build_xhtml BINDIST_PREFIX="$thisdir/$bindistdir" $make_settings
221 222

    check_packages post-xhtml
223
fi
224

225
fi # testsuite-only
226

227 228 229
# -----------------------------------------------------------------------------
# Run the testsuite

230
if [ "$hpc" = YES ]
231 232 233 234 235 236 237 238 239
then
    # XXX With threads we'd need to give a different tix file to each thread
    #     and then sum them up at the end
    threads=1
    HPCTIXFILE=$thisdir/testsuite/hpc_output/ghc.tix
    export HPCTIXFILE
    rm -f $HPCTIXFILE
fi

240 241
case "$speed" in
SLOW)
242
        MAKE_TEST_TARGET=slowtest
243 244 245
        BINDIST="BINDIST=YES"
        ;;
NORMAL)
246
        MAKE_TEST_TARGET=test
247 248 249
        BINDIST="BINDIST=YES"
        ;;
FAST)
250
        MAKE_TEST_TARGET=fasttest
251 252 253
        BINDIST="BINDIST=NO"
        ;;
esac
254

255
if [ $be_quiet -eq 1 ] && [ -z $VERBOSE ]; then
thomie's avatar
thomie committed
256
    TEST_VERBOSITY="VERBOSE=1 NO_PRINT_SUMMARY=YES"
257 258
fi

thomie's avatar
thomie committed
259
$make $MAKE_TEST_TARGET stage=2 $BINDIST $TEST_VERBOSITY THREADS=$threads 2>&1 | tee testlog
260

261 262
check_packages post-testsuite

263
if [ "$hpc" = YES ]
264 265 266 267
then
    utils/hpc/hpc markup --hpcdir=. --srcdir=compiler --srcdir=testsuite/hpc_output --destdir=testsuite/hpc_output testsuite/hpc_output/ghc.tix
fi

268
if
thomie's avatar
thomie committed
269 270 271 272 273
    grep '\<0 caused framework failures' testsuite_summary.txt >/dev/null 2>/dev/null &&
    grep '\<0 unexpected passes' testsuite_summary.txt >/dev/null 2>/dev/null &&
    grep '\<0 unexpected failures' testsuite_summary.txt >/dev/null 2>/dev/null &&
    grep '\<0 unexpected stat failures' testsuite_summary.txt >/dev/null 2>/dev/null &&
    ! grep 'Some files are written by multiple tests' testsuite_summary.txt >/dev/null 2>/dev/null ; then
274 275 276
    if [ $testsuite_only -eq 0 ] && [ $no_clean -eq 0 ]
    then
        cat <<EOF
thomie's avatar
thomie committed
277
-------------------------------------------------------------------
278 279 280 281 282 283 284 285
Congratulations!  This tree has passed minimal testing.

NOTE: If you have made changes that may cause failures not tested for by
the minimal testing procedure, please do further testing as necessary.

When you are satisfied that you haven't broken anything, go ahead and
push/send your patches.
EOF
286
        if [ -f mk/validate.mk ] && grep -q "^[^#]" mk/validate.mk
287 288 289 290 291 292 293
        then
            cat <<EOF

WARNING: You seem to have things set in mk/validate.mk. Please check
that it is OK before pushing.
EOF
        fi
294 295 296
        cat <<EOF
-------------------------------------------------------------------
EOF
297 298
    else
        cat <<EOF
thomie's avatar
thomie committed
299
-------------------------------------------------------------------
300 301 302 303 304
I didn't find any problems, but this wasn't a complete validate run,
so be careful!

NOTE: If you have made changes that may cause failures not tested for by
the minimal testing procedure, please do further testing as necessary.
305
-------------------------------------------------------------------
306 307
EOF
   fi
308
else
thomie's avatar
thomie committed
309 310 311 312
    if [ $be_quiet -eq 0 ]
    then
       cat <<EOF
-------------------------------------------------------------------
313 314
Oops!  Looks like you have some unexpected test results or framework failures.
Please fix them before pushing/sending patches.
315
-------------------------------------------------------------------
316
EOF
thomie's avatar
thomie committed
317
    fi
318
    exit 1
319
fi