diff options
-rw-r--r-- | testsuite/Makefile | 2 | ||||
-rw-r--r-- | testsuite/driver/runtests.py | 1 | ||||
-rw-r--r-- | testsuite/driver/testlib.py | 14 | ||||
-rw-r--r-- | testsuite/mk/test.mk | 1 | ||||
-rw-r--r-- | testsuite/timeout/Makefile | 12 | ||||
-rw-r--r-- | testsuite/timeout/timeout.hs | 25 |
6 files changed, 49 insertions, 6 deletions
diff --git a/testsuite/Makefile b/testsuite/Makefile index f49015d9a5..83ed1b360a 100644 --- a/testsuite/Makefile +++ b/testsuite/Makefile @@ -1,6 +1,8 @@ TOP = . include $(TOP)/mk/boilerplate.mk +SUBDIRS = timeout + CLEAN_FILES += mk/wordsize.mk all :: diff --git a/testsuite/driver/runtests.py b/testsuite/driver/runtests.py index f0b2cd58da..f579810d21 100644 --- a/testsuite/driver/runtests.py +++ b/testsuite/driver/runtests.py @@ -60,7 +60,6 @@ for opt,arg in opts: 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) - # ----------------------------------------------------------------------------- # The main dude diff --git a/testsuite/driver/testlib.py b/testsuite/driver/testlib.py index f3919df002..173a6a57ce 100644 --- a/testsuite/driver/testlib.py +++ b/testsuite/driver/testlib.py @@ -66,6 +66,10 @@ class TestConfig: # Lists of flags for each way self.way_flags = {} + # the timeout program + self.timeout_prog = '' + self.timeout = 300 + global config config = TestConfig() @@ -913,11 +917,11 @@ def guess_compiler_flags(): def runCmd( cmd ): if_verbose( 1, cmd ) - return os.system( cmd ) - -def runCmdNoFail( cmd ): - if_verbose( 1, cmd ) - return os.system( cmd ) + if (config.timeout_prog == ''): + return os.system( cmd ) + else: + return os.spawnv(os.P_WAIT, config.timeout_prog, + [config.timeout_prog,`config.timeout`,cmd] ) def rm_no_fail( file ): try: diff --git a/testsuite/mk/test.mk b/testsuite/mk/test.mk index 12e4c353c3..336a6f04b1 100644 --- a/testsuite/mk/test.mk +++ b/testsuite/mk/test.mk @@ -76,6 +76,7 @@ RUNTEST_OPTS += \ -e config.platform=\"$(TARGETPLATFORM)\" \ -e config.wordsize=\"$(WORDSIZE)\" \ -e default_testopts.cleanup=\"$(CLEANUP)\" \ + -e config.timeout_prog=\"$(TOP)/timeout/timeout\" \ $(EXTRA_RUNTEST_OPTS) TESTS = diff --git a/testsuite/timeout/Makefile b/testsuite/timeout/Makefile new file mode 100644 index 0000000000..9d438fa8c6 --- /dev/null +++ b/testsuite/timeout/Makefile @@ -0,0 +1,12 @@ +TOP = .. +include $(TOP)/mk/boilerplate.mk + +HC = $(GHC_INPLACE) +MKDEPENDHS = $(GHC_INPLACE) +SRC_HC_OPTS += -threaded + +HS_PROG = timeout + +boot :: $(HS_PROG) + +include $(TOP)/mk/target.mk diff --git a/testsuite/timeout/timeout.hs b/testsuite/timeout/timeout.hs new file mode 100644 index 0000000000..21a58a430a --- /dev/null +++ b/testsuite/timeout/timeout.hs @@ -0,0 +1,25 @@ +import Control.Concurrent +import System.Environment +import System.Process +import System.Exit + +main = do + args <- getArgs + case args of + [secs,cmd] -> do + p <- runCommand cmd + m <- newEmptyMVar + forkIO (do threadDelay (read secs * 1000000) + putMVar m Nothing + ) + forkIO (do r <- waitForProcess p + putMVar m (Just r)) + r <- takeMVar m + case r of + Nothing -> do + terminateProcess p + exitWith (ExitFailure 99) + Just r -> do + exitWith r + _other -> exitWith (ExitFailure 1) + |