Record ValidateSpeed and ValidateHpc in mk/are-validating.mk
[ghc.git] / validate
1 #!/bin/sh
2
3 # Flags:
4 #   --no-clean:       don't make clean first, just carry on from
5 #                     a previous interrupted validation run
6 #   --testsuite-only: don't build the compiler, just run
7 #                     the test suite
8 #   --hpc:            build stage2 with -fhpc, and see how much of the
9 #                     compiler the test suite covers.
10 #                     2008-07-01: 63% slower than the default.
11 #                     HTML generated here: testsuite/hpc_output/hpc_index.html
12 #   --normal:         Default settings
13 #   --fast:           Omit dyn way, omit binary distribution
14 #   --slow:           Build stage2 with -DDEBUG.
15 #                     2008-07-01: 14% slower than the default.
16
17 set -e
18
19 no_clean=0
20 testsuite_only=0
21 hpc=NO
22 speed=NORMAL
23
24 while [ $# -gt 0 ]
25 do
26     case "$1" in
27     --no-clean)
28         no_clean=1
29         ;;
30     --testsuite-only)
31         testsuite_only=1
32         ;;
33     --hpc)
34         hpc=YES
35         ;;
36     --slow)
37         speed=SLOW
38         ;;
39     --fast)
40         speed=FAST
41         ;;
42     --normal)
43         speed=NORMAL
44         ;;
45     *)
46         echo "Bad argument: $1" >&2
47         exit 1;;
48     esac
49     shift
50 done
51
52 if ! [ -d testsuite ]
53 then
54     echo 'You need the testsuite to validate' >&2
55     echo 'Run "./sync-all --testsuite get" to get it' >&2
56     exit 1
57 fi
58
59 if [ "$THREADS" = "" ]; then
60     if [ "$CPUS" = "" ]; then
61         threads=2
62     else
63         threads=$(($CPUS + 1)) # `expr $CPUS + 1`
64     fi
65 else
66     threads="$THREADS"
67 fi
68
69 if type gmake > /dev/null 2> /dev/null
70 then
71     make="gmake"
72 else
73     make="make"
74 fi
75
76 if [ $testsuite_only -eq 0 ]; then
77
78 if [ $no_clean -eq 0 ]; then
79     $make maintainer-clean NO_CLEAN_GMP=YES
80
81     INSTDIR=`pwd`/inst
82     if [ "$OSTYPE" = "cygwin" ]
83     then
84         INSTDIR=`cygpath -m "$INSTDIR"`
85     fi
86
87     /usr/bin/perl -w boot --validate --required-tag=dph
88     ./configure --prefix="$INSTDIR" $config_args
89 fi
90
91 thisdir=`utils/ghc-pwd/dist-boot/ghc-pwd`
92
93 echo "Validating=YES"       >  mk/are-validating.mk
94 echo "ValidateSpeed=$speed" >> mk/are-validating.mk
95 echo "ValidateHpc=$hpc"     >> mk/are-validating.mk
96
97 $make -j$threads
98 # For a "debug make", add "--debug=b --debug=m"
99
100 # -----------------------------------------------------------------------------
101 # Build and test a binary distribution (not --fast)
102
103 if [ $speed != "FAST" ]; then
104
105     $make binary-dist-prep
106     $make test_bindist TEST_PREP=YES
107
108     #
109     # Install the mtl package into the bindist, because it is used by some
110     # tests.  It isn't essential that we do this (the failing tests will
111     # be treated as expected failures), but we get a bit more test
112     # coverage, and also verify that we can install a package into the
113     # bindist with Cabal.
114     #
115     bindistdir="bindisttest/install dir"
116     cd libraries/mtl
117     "$thisdir/$bindistdir/bin/ghc" --make Setup
118     ./Setup configure --with-ghc="$thisdir/$bindistdir/bin/ghc" --with-haddock="$thisdir/$bindistdir/bin/haddock" --global --builddir=dist-bindist --prefix="$thisdir/$bindistdir"
119     ./Setup build   --builddir=dist-bindist
120     ./Setup haddock --builddir=dist-bindist
121     ./Setup install --builddir=dist-bindist
122     ./Setup clean   --builddir=dist-bindist
123     rm -f Setup Setup.exe Setup.hi Setup.o
124     cd $thisdir
125 fi
126
127 fi # testsuite-only
128
129 # -----------------------------------------------------------------------------
130 # Run the testsuite
131
132 if [ "$hpc" = YES ]
133 then
134     # XXX With threads we'd need to give a different tix file to each thread
135     #     and then sum them up at the end
136     threads=1
137     HPCTIXFILE=$thisdir/testsuite/hpc_output/ghc.tix
138     export HPCTIXFILE
139     rm -f $HPCTIXFILE
140 fi
141
142 case "$speed" in
143 SLOW)
144         MAKE_TEST_TARGET=fulltest
145         BINDIST="BINDIST=YES"
146         ;;
147 NORMAL)
148         MAKE_TEST_TARGET=test
149         BINDIST="BINDIST=YES"
150         ;;
151 FAST)
152         MAKE_TEST_TARGET=test
153         BINDIST="BINDIST=NO"
154         ;;
155 esac
156
157 $make $MAKE_TEST_TARGET stage=2 $BINDIST THREADS=$threads 2>&1 | tee testlog
158
159 if [ "$hpc" = YES ]
160 then
161     utils/hpc/hpc markup --hpcdir=. --srcdir=compiler --srcdir=testsuite/hpc_output --destdir=testsuite/hpc_output testsuite/hpc_output/ghc.tix
162 fi
163
164 echo "-------------------------------------------------------------------"
165 if
166     grep '\<0 caused framework failures' testlog >/dev/null 2>/dev/null &&
167     grep '\<0 unexpected passes' testlog >/dev/null 2>/dev/null &&
168     grep '\<0 unexpected failures' testlog >/dev/null 2>/dev/null &&
169     ! grep 'Some files are written by multiple tests' testlog >/dev/null 2>/dev/null ; then
170     if [ $testsuite_only -eq 0 ] && [ $no_clean -eq 0 ]
171     then
172         cat <<EOF
173 Congratulations!  This tree has passed minimal testing.
174
175 NOTE: If you have made changes that may cause failures not tested for by
176 the minimal testing procedure, please do further testing as necessary.
177
178 When you are satisfied that you haven't broken anything, go ahead and
179 push/send your patches.
180 EOF
181         if [ -f mk/validate.mk ] && grep -q "^[^#]" mk/validate.mk
182         then
183             cat <<EOF
184
185 WARNING: You seem to have things set in mk/validate.mk. Please check
186 that it is OK before pushing.
187 EOF
188         fi
189         cat <<EOF
190 -------------------------------------------------------------------
191 EOF
192     else
193         cat <<EOF
194 I didn't find any problems, but this wasn't a complete validate run,
195 so be careful!
196
197 NOTE: If you have made changes that may cause failures not tested for by
198 the minimal testing procedure, please do further testing as necessary.
199 -------------------------------------------------------------------
200 EOF
201    fi
202 else
203     cat <<EOF
204 Oops!  Looks like you have some unexpected test results or framework failures.
205 Please fix them before pushing/sending patches.
206 -------------------------------------------------------------------
207 EOF
208     exit 1
209 fi
210