Fix Trac #10618 (out of scope operator)
[ghc.git] / validate
index eafbdb9..fbf3c1b 100755 (executable)
--- a/validate
+++ b/validate
@@ -20,11 +20,10 @@ Flags:
                     HTML generated here: testsuite/hpc_output/hpc_index.html
   --normal          Default settings
   --fast            Omit dyn way, omit binary distribution
-  --slow            Build stage2 with -DDEBUG.
+  --slow            Build stage2 with -DDEBUG. Skips tests that call
+                    `compiler_stats_num_field`.
                     2008-07-01: 14% slower than the default.
-  --no-dph:         Skip requiring libraries/dph. In --slow mode, these tests
-                    can take a substantial amount of time, and on some platforms
-                    with broken linkers, we don't want to try compiling it.
+  --dph:            Also build libraries/dph and run associated tests.
   --help            shows this usage help.
 
   Set environment variable 'CPUS' to number of cores, to exploit
@@ -39,7 +38,8 @@ no_clean=0
 testsuite_only=0
 hpc=NO
 speed=NORMAL
-skip_dph=0
+use_dph=0
+be_quiet=0
 
 while [ $# -gt 0 ]
 do
@@ -62,8 +62,14 @@ do
     --normal)
         speed=NORMAL
         ;;
-    --no-dph)
-        skip_dph=1
+    --no-dph) # for backward compat
+        use_dph=0
+        ;;
+    --dph)
+        use_dph=1
+        ;;
+    --quiet)
+        be_quiet=1
         ;;
     --help)
         show_help
@@ -77,38 +83,66 @@ do
 done
 
 check_packages () {
-    echo "== Start $1 package check"
     if [ "$bindistdir" = "" ]
     then
-        inplace/bin/ghc-pkg check -v
+        ghc_pkg=inplace/bin/ghc-pkg
+    else
+        ghc_pkg="$bindistdir"/bin/ghc-pkg
+    fi
+
+    if [ $be_quiet -eq 1 ]
+    then
+        "$ghc_pkg" check
     else
-        "$bindistdir"/bin/ghc-pkg check -v
+        echo "== Start $1 package check"
+        "$ghc_pkg" check -v
+        echo "== End $1 package check"
     fi
-    echo "== End $1 package check"
 }
 
+detect_cpu_count () {
+    if [ "$CPUS" = "" ]; then
+        # Windows standard environment variable
+        CPUS="$NUMBER_OF_PROCESSORS"
+    fi
+
+    if [ "$CPUS" = "" ]; then
+        # Linux
+        CPUS=`getconf _NPROCESSORS_ONLN 2>/dev/null`
+    fi
+
+    if [ "$CPUS" = "" ]; then
+        # FreeBSD
+        CPUS=`getconf NPROCESSORS_ONLN 2>/dev/null`
+    fi
+
+    if [ "$CPUS" = "" ]; then
+        # nothing helped
+        CPUS="1"
+    fi
+
+    echo "using ${CPUS} CPUs" >&2
+}
+
+detect_cpu_count
+
 if ! [ -d testsuite ]
 then
-    echo 'You need the testsuite to validate' >&2
-    echo 'Run "./sync-all --testsuite get" to get it' >&2
+    echo 'Could not find the testsuite for validation' >&2
     exit 1
 fi
 
 if [ "$THREADS" = "" ]; then
-    if [ "$CPUS" = "" ]; then
-        threads=2
-    else
-        threads=$(($CPUS + 1)) # `expr $CPUS + 1`
-    fi
+    threads=$(($CPUS + 1)) # `expr $CPUS + 1`
 else
     threads="$THREADS"
 fi
 
 if type gmake > /dev/null 2> /dev/null
 then
-    make="gmake"
+    make="gmake -s"
 else
-    make="make"
+    make="make -s"
 fi
 
 if [ $testsuite_only -eq 0 ]; then
@@ -122,10 +156,10 @@ if [ $no_clean -eq 0 ]; then
         INSTDIR=`cygpath -m "$INSTDIR"`
     fi
 
-    if [ $skip_dph -eq 1 ]; then
-        /usr/bin/perl -w boot --validate
+    if [ $use_dph -eq 1 ]; then
+        perl -w boot --validate --required-tag=dph
     else
-        /usr/bin/perl -w boot --validate --required-tag=dph
+        perl -w boot --validate
     fi
     ./configure --prefix="$INSTDIR" $config_args
 fi
@@ -135,6 +169,13 @@ thisdir=`utils/ghc-pwd/dist-boot/ghc-pwd`
 echo "Validating=YES"       >  mk/are-validating.mk
 echo "ValidateSpeed=$speed" >> mk/are-validating.mk
 echo "ValidateHpc=$hpc"     >> mk/are-validating.mk
+echo "V=0"                  >> mk/are-validating.mk # Less gunk
+
+if [ $use_dph -eq 1 ]; then
+    echo "BUILD_DPH=YES"    >> mk/are-validating.mk
+else
+    echo "BUILD_DPH=NO"     >> mk/are-validating.mk
+fi
 
 $make -j$threads
 # For a "debug make", add "--debug=b --debug=m"
@@ -184,16 +225,22 @@ SLOW)
         BINDIST="BINDIST=YES"
         ;;
 NORMAL)
-        MAKE_TEST_TARGET=test
+        MAKE_TEST_TARGET=fasttest
         BINDIST="BINDIST=YES"
         ;;
 FAST)
-        MAKE_TEST_TARGET=test
+        MAKE_TEST_TARGET=fasttest
         BINDIST="BINDIST=NO"
         ;;
 esac
 
-$make $MAKE_TEST_TARGET stage=2 $BINDIST THREADS=$threads 2>&1 | tee testlog
+if [ $be_quiet -eq 1 ]; then
+    TEST_VERBOSITY="VERBOSE=1 NO_PRINT_SUMMARY=YES"
+else
+    TEST_VERBOSITY="VERBOSE=2"
+fi
+
+$make $MAKE_TEST_TARGET stage=2 $BINDIST $TEST_VERBOSITY THREADS=$threads 2>&1 | tee testlog
 
 check_packages post-testsuite
 
@@ -202,15 +249,16 @@ then
     utils/hpc/hpc markup --hpcdir=. --srcdir=compiler --srcdir=testsuite/hpc_output --destdir=testsuite/hpc_output testsuite/hpc_output/ghc.tix
 fi
 
-echo "-------------------------------------------------------------------"
 if
-    grep '\<0 caused framework failures' testlog >/dev/null 2>/dev/null &&
-    grep '\<0 unexpected passes' testlog >/dev/null 2>/dev/null &&
-    grep '\<0 unexpected failures' testlog >/dev/null 2>/dev/null &&
-    ! grep 'Some files are written by multiple tests' testlog >/dev/null 2>/dev/null ; then
+    grep '\<0 caused framework failures' testsuite_summary.txt >/dev/null 2>/dev/null &&
+    grep '\<0 unexpected passes' testsuite_summary.txt >/dev/null 2>/dev/null &&
+    grep '\<0 unexpected failures' testsuite_summary.txt >/dev/null 2>/dev/null &&
+    grep '\<0 unexpected stat failures' testsuite_summary.txt >/dev/null 2>/dev/null &&
+    ! grep 'Some files are written by multiple tests' testsuite_summary.txt >/dev/null 2>/dev/null ; then
     if [ $testsuite_only -eq 0 ] && [ $no_clean -eq 0 ]
     then
         cat <<EOF
+-------------------------------------------------------------------
 Congratulations!  This tree has passed minimal testing.
 
 NOTE: If you have made changes that may cause failures not tested for by
@@ -232,6 +280,7 @@ EOF
 EOF
     else
         cat <<EOF
+-------------------------------------------------------------------
 I didn't find any problems, but this wasn't a complete validate run,
 so be careful!
 
@@ -241,11 +290,14 @@ the minimal testing procedure, please do further testing as necessary.
 EOF
    fi
 else
-    cat <<EOF
+    if [ $be_quiet -eq 0 ]
+    then
+       cat <<EOF
+-------------------------------------------------------------------
 Oops!  Looks like you have some unexpected test results or framework failures.
 Please fix them before pushing/sending patches.
 -------------------------------------------------------------------
 EOF
+    fi
     exit 1
 fi
-