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