Hi all,

Attached is a patch that can give a per-process CPU limit to things run
by the testsuite. I use it like this (300 is a fairly conservative
figure - 120-130 seems to be about what is necessary):

    echo 'import IO; main = hPutStr stderr ""' > foo.hs
    $(MAKE) -C testsuite boot
    $(MAKE) -C testsuite/tests/ghc-regress \
            TIMEOUT=`python -c "import os; import math; from os import *; from 
resource import *; \
               spawnl(os.P_WAIT, 'ghc/compiler/ghc-inplace', 'ghc-inplace', \
                                 'foo.hs', \
                                 '-o', 'foo', '-O2'); \
               spawnl(os.P_WAIT, 'foo', 'foo'); \
               xs = getrusage(RUSAGE_CHILDREN); \
               print (300*int(math.ceil(xs[0] + xs[1])))"`

I assume resource is not available on all OSes, in particular not
Windows, but I'm not a python guru so I don't know what the best way to
handle that is?

Also, is runCmdNoFail meant to be different to runCmd?


Thanks
Ian

--- ghc-cvs-20041017.orig/testsuite/driver/runtests.py
+++ ghc-cvs-20041017/testsuite/driver/runtests.py
@@ -60,6 +60,9 @@
             sys.exit(1)
         config.run_ways = filter(eq(arg), config.run_ways + config.other_ways)
         config.compile_ways = filter(eq(arg), config.compile_ways + config.other_ways)
+
+if config.timeout != 0:
+    print 'Running with timeout ' + str(config.timeout)
         
 # -----------------------------------------------------------------------------
 # The main dude
--- ghc-cvs-20041017.orig/testsuite/driver/testlib.py
+++ ghc-cvs-20041017/testsuite/driver/testlib.py
@@ -9,6 +9,7 @@
 import traceback
 import copy
 import glob
+import resource
 
 from string import join
 from testutil import *
@@ -66,6 +67,9 @@
         # Lists of flags for each way
         self.way_flags = {}
 
+        # After how long should a process timeout on a test?
+        self.timeout = 0
+
 global config
 config = TestConfig()
 
@@ -886,11 +890,22 @@
 
 def runCmd( cmd ):
     if_verbose( 1, cmd )
-    return os.system( cmd )
+    if config.timeout == 0:
+        return os.system( cmd )
+    else:
+        pid = os.fork()
+        if pid == 0:
+            resource.setrlimit(resource.RLIMIT_CPU, (config.timeout, config.timeout))
+            res = os.system( cmd )
+            os._exit(os.WEXITSTATUS(res))
+        elif pid > 0:
+            (cpid, res) = os.waitpid(pid, 0)
+            return res
+        else:
+            print "Error: Fork failed"
 
 def runCmdNoFail( cmd ):
-    if_verbose( 1, cmd )
-    return os.system( cmd )
+    return runCmd( cmd )
 
 def rm_no_fail( file ):
    try:
--- ghc-cvs-20041017.orig/testsuite/mk/test.mk
+++ ghc-cvs-20041017/testsuite/mk/test.mk
@@ -67,6 +67,7 @@
        -e config.compiler_always_flags.append"(\"$(EXTRA_HC_OPTS)\")" \
        -e config.platform=\"$(TARGETPLATFORM)\" \
        -e config.wordsize=\"$(WORDSIZE)\" \
+       -e config.timeout=int\(\"0$(TIMEOUT)\"\) \
        -e default_testopts.cleanup=\"$(CLEANUP)\" \
        $(EXTRA_RUNTEST_OPTS)
 
_______________________________________________
Cvs-ghc mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/cvs-ghc

Reply via email to