Improve kind-checking for 'deriving' clauses
[ghc.git] / validate
1 #!/bin/sh
2
3 set -e
4
5 show_help () {
6     cat <<EOF
7 Usage: $0 [FLAGS]...
8
9 Validate GHC source tree against testsuite; see
10 http://ghc.haskell.org/trac/ghc/wiki/TestingPatches for more
11 information.
12
13 Flags:
14   --no-clean        don't make clean first, just carry on from
15                     a previous interrupted validation run
16   --testsuite-only  don't build the compiler, just run the test suite
17   --hpc             build stage2 with -fhpc, and see how much of the
18                     compiler the test suite covers.
19                     2008-07-01: 63% slower than the default.
20                     HTML generated here: testsuite/hpc_output/hpc_index.html
21   --normal          Default settings
22   --fast            Omit dyn way, omit binary distribution
23   --slow            Build stage2 with -DDEBUG. Skips tests that call
24                     `compiler_stats_num_field`.
25                     2008-07-01: 14% slower than the default.
26   --dph:            Also build libraries/dph and run associated tests.
27   --help            shows this usage help.
28
29   Set environment variable 'CPUS' to number of cores, to exploit
30   multiple cpu cores, e.g.
31
32     CPUS=8 ./validate
33
34 EOF
35 }
36
37 no_clean=0
38 testsuite_only=0
39 hpc=NO
40 speed=NORMAL
41 use_dph=0
42 be_quiet=0
43
44 while [ $# -gt 0 ]
45 do
46     case "$1" in
47     --no-clean)
48         no_clean=1
49         ;;
50     --testsuite-only)
51         testsuite_only=1
52         ;;
53     --hpc)
54         hpc=YES
55         ;;
56     --slow)
57         speed=SLOW
58         ;;
59     --fast)
60         speed=FAST
61         ;;
62     --normal)
63         speed=NORMAL
64         ;;
65     --no-dph) # for backward compat
66         use_dph=0
67         ;;
68     --dph)
69         use_dph=1
70         ;;
71     --quiet)
72         be_quiet=1
73         ;;
74     --help)
75         show_help
76         exit 0;;
77     *)
78         echo "$0: unrecognized argument '$1'" >&2
79         echo "Try '$0 --help' for more information." >&2
80         exit 1;;
81     esac
82     shift
83 done
84
85 check_packages () {
86     if [ "$bindistdir" = "" ]
87     then
88         ghc_pkg=inplace/bin/ghc-pkg
89     else
90         ghc_pkg="$bindistdir"/bin/ghc-pkg
91     fi
92
93     if [ $be_quiet -eq 1 ]
94     then
95         "$ghc_pkg" check
96     else
97         echo "== Start $1 package check"
98         "$ghc_pkg" check -v
99         echo "== End $1 package check"
100     fi
101 }
102
103 detect_cpu_count () {
104     if [ "$CPUS" = "" ]; then
105         # Windows standard environment variable
106         CPUS="$NUMBER_OF_PROCESSORS"
107     fi
108
109     if [ "$CPUS" = "" ]; then
110         # Linux
111         CPUS=`getconf _NPROCESSORS_ONLN 2>/dev/null`
112     fi
113
114     if [ "$CPUS" = "" ]; then
115         # FreeBSD
116         CPUS=`getconf NPROCESSORS_ONLN 2>/dev/null`
117     fi
118
119     if [ "$CPUS" = "" ]; then
120         # nothing helped
121         CPUS="1"
122     fi
123
124     echo "using ${CPUS} CPUs" >&2
125 }
126
127 detect_cpu_count
128
129 if ! [ -d testsuite ]
130 then
131     echo 'Could not find the testsuite for validation' >&2
132     exit 1
133 fi
134
135 if [ "$THREADS" = "" ]; then
136     threads=$(($CPUS + 1)) # `expr $CPUS + 1`
137 else
138     threads="$THREADS"
139 fi
140
141 if type gmake > /dev/null 2> /dev/null
142 then
143     make="gmake -s"
144 else
145     make="make -s"
146 fi
147
148 if [ $testsuite_only -eq 0 ]; then
149
150 if [ $no_clean -eq 0 ]; then
151     $make maintainer-clean NO_CLEAN_GMP=YES
152
153     INSTDIR=`pwd`/inst
154     if [ "$OSTYPE" = "cygwin" ]
155     then
156         INSTDIR=`cygpath -m "$INSTDIR"`
157     fi
158
159     if [ $use_dph -eq 1 ]; then
160         perl -w boot --validate --required-tag=dph
161     else
162         perl -w boot --validate
163     fi
164     ./configure --prefix="$INSTDIR" $config_args
165 fi
166
167 thisdir=`utils/ghc-pwd/dist-boot/ghc-pwd`
168
169 echo "Validating=YES"       >  mk/are-validating.mk
170 echo "ValidateSpeed=$speed" >> mk/are-validating.mk
171 echo "ValidateHpc=$hpc"     >> mk/are-validating.mk
172 echo "V=0"                  >> mk/are-validating.mk # Less gunk
173
174 if [ $use_dph -eq 1 ]; then
175     echo "BUILD_DPH=YES"    >> mk/are-validating.mk
176 else
177     echo "BUILD_DPH=NO"     >> mk/are-validating.mk
178 fi
179
180 $make -j$threads
181 # For a "debug make", add "--debug=b --debug=m"
182
183 check_packages post-build
184
185 # -----------------------------------------------------------------------------
186 # Build and test a binary distribution (not --fast)
187
188 if [ $speed != "FAST" ]; then
189
190     $make binary-dist-prep
191     $make test_bindist TEST_PREP=YES
192
193     #
194     # Install the xhtml package into the bindist.
195     # This verifies that we can install a package into the
196     # bindist with Cabal.
197     #
198     bindistdir="bindisttest/install   dir"
199
200     check_packages post-install
201
202     $make validate_build_xhtml BINDIST_PREFIX="$thisdir/$bindistdir"
203
204     check_packages post-xhtml
205 fi
206
207 fi # testsuite-only
208
209 # -----------------------------------------------------------------------------
210 # Run the testsuite
211
212 if [ "$hpc" = YES ]
213 then
214     # XXX With threads we'd need to give a different tix file to each thread
215     #     and then sum them up at the end
216     threads=1
217     HPCTIXFILE=$thisdir/testsuite/hpc_output/ghc.tix
218     export HPCTIXFILE
219     rm -f $HPCTIXFILE
220 fi
221
222 case "$speed" in
223 SLOW)
224         MAKE_TEST_TARGET=fulltest
225         BINDIST="BINDIST=YES"
226         ;;
227 NORMAL)
228         MAKE_TEST_TARGET=fasttest
229         BINDIST="BINDIST=YES"
230         ;;
231 FAST)
232         MAKE_TEST_TARGET=fasttest
233         BINDIST="BINDIST=NO"
234         ;;
235 esac
236
237 if [ $be_quiet -eq 1 ]; then
238     TEST_VERBOSITY="VERBOSE=1 NO_PRINT_SUMMARY=YES"
239 else
240     TEST_VERBOSITY="VERBOSE=2"
241 fi
242
243 $make $MAKE_TEST_TARGET stage=2 $BINDIST $TEST_VERBOSITY THREADS=$threads 2>&1 | tee testlog
244
245 check_packages post-testsuite
246
247 if [ "$hpc" = YES ]
248 then
249     utils/hpc/hpc markup --hpcdir=. --srcdir=compiler --srcdir=testsuite/hpc_output --destdir=testsuite/hpc_output testsuite/hpc_output/ghc.tix
250 fi
251
252 if
253     grep '\<0 caused framework failures' testsuite_summary.txt >/dev/null 2>/dev/null &&
254     grep '\<0 unexpected passes' testsuite_summary.txt >/dev/null 2>/dev/null &&
255     grep '\<0 unexpected failures' testsuite_summary.txt >/dev/null 2>/dev/null &&
256     grep '\<0 unexpected stat failures' testsuite_summary.txt >/dev/null 2>/dev/null &&
257     ! grep 'Some files are written by multiple tests' testsuite_summary.txt >/dev/null 2>/dev/null ; then
258     if [ $testsuite_only -eq 0 ] && [ $no_clean -eq 0 ]
259     then
260         cat <<EOF
261 -------------------------------------------------------------------
262 Congratulations!  This tree has passed minimal testing.
263
264 NOTE: If you have made changes that may cause failures not tested for by
265 the minimal testing procedure, please do further testing as necessary.
266
267 When you are satisfied that you haven't broken anything, go ahead and
268 push/send your patches.
269 EOF
270         if [ -f mk/validate.mk ] && grep -q "^[^#]" mk/validate.mk
271         then
272             cat <<EOF
273
274 WARNING: You seem to have things set in mk/validate.mk. Please check
275 that it is OK before pushing.
276 EOF
277         fi
278         cat <<EOF
279 -------------------------------------------------------------------
280 EOF
281     else
282         cat <<EOF
283 -------------------------------------------------------------------
284 I didn't find any problems, but this wasn't a complete validate run,
285 so be careful!
286
287 NOTE: If you have made changes that may cause failures not tested for by
288 the minimal testing procedure, please do further testing as necessary.
289 -------------------------------------------------------------------
290 EOF
291    fi
292 else
293     if [ $be_quiet -eq 0 ]
294     then
295        cat <<EOF
296 -------------------------------------------------------------------
297 Oops!  Looks like you have some unexpected test results or framework failures.
298 Please fix them before pushing/sending patches.
299 -------------------------------------------------------------------
300 EOF
301     fi
302     exit 1
303 fi