Keep the flag lists as IntSets rather than lists
[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
95 $make -j$threads ValidateHpc=$hpc ValidateSpeed=$speed
96 # For a "debug make", add "--debug=b --debug=m"
97
98 # -----------------------------------------------------------------------------
99 # Build and test a binary distribution (not --fast)
100
101 if [ $speed != "FAST" ]; then
102
103     $make binary-dist-prep
104     $make test_bindist TEST_PREP=YES
105
106     #
107     # Install the mtl package into the bindist, because it is used by some
108     # tests.  It isn't essential that we do this (the failing tests will
109     # be treated as expected failures), but we get a bit more test
110     # coverage, and also verify that we can install a package into the
111     # bindist with Cabal.
112     #
113     bindistdir="bindisttest/install dir"
114     cd libraries/mtl
115     "$thisdir/$bindistdir/bin/ghc" --make Setup
116     ./Setup configure --with-ghc="$thisdir/$bindistdir/bin/ghc" --with-haddock="$thisdir/$bindistdir/bin/haddock" --global --builddir=dist-bindist --prefix="$thisdir/$bindistdir"
117     ./Setup build   --builddir=dist-bindist
118     ./Setup haddock --builddir=dist-bindist
119     ./Setup install --builddir=dist-bindist
120     ./Setup clean   --builddir=dist-bindist
121     rm -f Setup Setup.exe Setup.hi Setup.o
122     cd $thisdir
123 fi
124
125 fi # testsuite-only
126
127 # -----------------------------------------------------------------------------
128 # Run the testsuite
129
130 if [ "$hpc" = YES ]
131 then
132     # XXX With threads we'd need to give a different tix file to each thread
133     #     and then sum them up at the end
134     threads=1
135     HPCTIXFILE=$thisdir/testsuite/hpc_output/ghc.tix
136     export HPCTIXFILE
137     rm -f $HPCTIXFILE
138 fi
139
140 case "$speed" in
141 SLOW)
142         MAKE_TEST_TARGET=fulltest
143         BINDIST="BINDIST=YES"
144         ;;
145 NORMAL)
146         MAKE_TEST_TARGET=test
147         BINDIST="BINDIST=YES"
148         ;;
149 FAST)
150         MAKE_TEST_TARGET=test
151         BINDIST="BINDIST=NO"
152         ;;
153 esac
154
155 $make $MAKE_TEST_TARGET stage=2 $BINDIST THREADS=$threads 2>&1 | tee testlog
156
157 if [ "$hpc" = YES ]
158 then
159     utils/hpc/hpc markup --hpcdir=. --srcdir=compiler --srcdir=testsuite/hpc_output --destdir=testsuite/hpc_output testsuite/hpc_output/ghc.tix
160 fi
161
162 echo "-------------------------------------------------------------------"
163 if
164     grep '\<0 caused framework failures' testlog >/dev/null 2>/dev/null &&
165     grep '\<0 unexpected passes' testlog >/dev/null 2>/dev/null &&
166     grep '\<0 unexpected failures' testlog >/dev/null 2>/dev/null &&
167     ! grep 'Some files are written by multiple tests' testlog >/dev/null 2>/dev/null ; then
168     if [ $testsuite_only -eq 0 ] && [ $no_clean -eq 0 ]
169     then
170         cat <<EOF
171 Congratulations!  This tree has passed minimal testing.
172
173 NOTE: If you have made changes that may cause failures not tested for by
174 the minimal testing procedure, please do further testing as necessary.
175
176 When you are satisfied that you haven't broken anything, go ahead and
177 push/send your patches.
178 EOF
179         if [ -f mk/validate.mk ] && grep -q "^[^#]" mk/validate.mk
180         then
181             cat <<EOF
182
183 WARNING: You seem to have things set in mk/validate.mk. Please check
184 that it is OK before pushing.
185 EOF
186         fi
187         cat <<EOF
188 -------------------------------------------------------------------
189 EOF
190     else
191         cat <<EOF
192 I didn't find any problems, but this wasn't a complete validate run,
193 so be careful!
194
195 NOTE: If you have made changes that may cause failures not tested for by
196 the minimal testing procedure, please do further testing as necessary.
197 -------------------------------------------------------------------
198 EOF
199    fi
200 else
201     cat <<EOF
202 Oops!  Looks like you have some unexpected test results or framework failures.
203 Please fix them before pushing/sending patches.
204 -------------------------------------------------------------------
205 EOF
206     exit 1
207 fi
208