Comments and layout only
[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 [ $speed != "FAST" ]; then
175     # Build the "extra" packages (see ./packages), to enable more tests.
176     echo "BUILD_EXTRA_PKGS=YES" >> mk/are-validating.mk
177 fi
178
179 if [ $use_dph -eq 1 ]; then
180     echo "BUILD_DPH=YES"    >> mk/are-validating.mk
181 else
182     echo "BUILD_DPH=NO"     >> mk/are-validating.mk
183 fi
184
185 $make -j$threads
186 # For a "debug make", add "--debug=b --debug=m"
187
188 check_packages post-build
189
190 # -----------------------------------------------------------------------------
191 # Build and test a binary distribution (not --fast)
192
193 if [ $speed != "FAST" ]; then
194
195     $make binary-dist-prep
196     $make test_bindist TEST_PREP=YES
197
198     #
199     # Install the xhtml package into the bindist.
200     # This verifies that we can install a package into the
201     # bindist with Cabal.
202     #
203     bindistdir="bindisttest/install   dir"
204
205     check_packages post-install
206
207     $make validate_build_xhtml BINDIST_PREFIX="$thisdir/$bindistdir"
208
209     check_packages post-xhtml
210 fi
211
212 fi # testsuite-only
213
214 # -----------------------------------------------------------------------------
215 # Run the testsuite
216
217 if [ "$hpc" = YES ]
218 then
219     # XXX With threads we'd need to give a different tix file to each thread
220     #     and then sum them up at the end
221     threads=1
222     HPCTIXFILE=$thisdir/testsuite/hpc_output/ghc.tix
223     export HPCTIXFILE
224     rm -f $HPCTIXFILE
225 fi
226
227 case "$speed" in
228 SLOW)
229         MAKE_TEST_TARGET=fulltest
230         BINDIST="BINDIST=YES"
231         ;;
232 NORMAL)
233         MAKE_TEST_TARGET=fasttest
234         BINDIST="BINDIST=YES"
235         ;;
236 FAST)
237         MAKE_TEST_TARGET=fasttest
238         BINDIST="BINDIST=NO"
239         ;;
240 esac
241
242 if [ $be_quiet -eq 1 ]; then
243     TEST_VERBOSITY="VERBOSE=1 NO_PRINT_SUMMARY=YES"
244 else
245     TEST_VERBOSITY="VERBOSE=2"
246 fi
247
248 $make $MAKE_TEST_TARGET stage=2 $BINDIST $TEST_VERBOSITY THREADS=$threads 2>&1 | tee testlog
249
250 check_packages post-testsuite
251
252 if [ "$hpc" = YES ]
253 then
254     utils/hpc/hpc markup --hpcdir=. --srcdir=compiler --srcdir=testsuite/hpc_output --destdir=testsuite/hpc_output testsuite/hpc_output/ghc.tix
255 fi
256
257 if
258     grep '\<0 caused framework failures' testsuite_summary.txt >/dev/null 2>/dev/null &&
259     grep '\<0 unexpected passes' testsuite_summary.txt >/dev/null 2>/dev/null &&
260     grep '\<0 unexpected failures' testsuite_summary.txt >/dev/null 2>/dev/null &&
261     grep '\<0 unexpected stat failures' testsuite_summary.txt >/dev/null 2>/dev/null &&
262     ! grep 'Some files are written by multiple tests' testsuite_summary.txt >/dev/null 2>/dev/null ; then
263     if [ $testsuite_only -eq 0 ] && [ $no_clean -eq 0 ]
264     then
265         cat <<EOF
266 -------------------------------------------------------------------
267 Congratulations!  This tree has passed minimal testing.
268
269 NOTE: If you have made changes that may cause failures not tested for by
270 the minimal testing procedure, please do further testing as necessary.
271
272 When you are satisfied that you haven't broken anything, go ahead and
273 push/send your patches.
274 EOF
275         if [ -f mk/validate.mk ] && grep -q "^[^#]" mk/validate.mk
276         then
277             cat <<EOF
278
279 WARNING: You seem to have things set in mk/validate.mk. Please check
280 that it is OK before pushing.
281 EOF
282         fi
283         cat <<EOF
284 -------------------------------------------------------------------
285 EOF
286     else
287         cat <<EOF
288 -------------------------------------------------------------------
289 I didn't find any problems, but this wasn't a complete validate run,
290 so be careful!
291
292 NOTE: If you have made changes that may cause failures not tested for by
293 the minimal testing procedure, please do further testing as necessary.
294 -------------------------------------------------------------------
295 EOF
296    fi
297 else
298     if [ $be_quiet -eq 0 ]
299     then
300        cat <<EOF
301 -------------------------------------------------------------------
302 Oops!  Looks like you have some unexpected test results or framework failures.
303 Please fix them before pushing/sending patches.
304 -------------------------------------------------------------------
305 EOF
306     fi
307     exit 1
308 fi