Use a python timeout for the testsuite when we don't have a threaded RTS
authorIan Lynagh <igloo@earth.li>
Thu, 7 Sep 2006 11:30:01 +0000 (11:30 +0000)
committerIan Lynagh <igloo@earth.li>
Thu, 7 Sep 2006 11:30:01 +0000 (11:30 +0000)
testsuite/timeout/Makefile
testsuite/timeout/timeout.py [new file with mode: 0644]

index 06281e0..f3424ad 100644 (file)
@@ -11,6 +11,14 @@ endif
 
 HS_PROG = timeout
 
+ifeq "$(findstring thr,$(GhcRTSWays))" "thr"
 boot :: $(HS_PROG)
+else
+boot :: python-timeout
+endif
+
+python-timeout:
+       cp timeout.py timeout
+       chmod +x timeout
 
 include $(TOP)/mk/target.mk
diff --git a/testsuite/timeout/timeout.py b/testsuite/timeout/timeout.py
new file mode 100644 (file)
index 0000000..212cf4a
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/python
+
+import os
+import signal
+import sys
+
+secs = int(sys.argv[1])
+cmd = sys.argv[2]
+
+pid = os.fork()
+# XXX error checking
+if pid == 0:
+    # child
+    os.setpgrp()
+    os.execvp('/bin/sh', ['/bin/sh', '-c', cmd])
+else:
+    # parent
+    def handler(signum, frame):
+        os.killpg(pid, signal.SIGKILL) # XXX Kill better like .hs
+        sys.exit(99)
+    old = signal.signal(signal.SIGALRM, handler)
+    signal.alarm(secs)
+    (pid2, res) = os.waitpid(pid, 0)
+    if (os.WIFEXITED(res)):
+        sys.exit(os.WEXITSTATUS(res))
+    else:
+        sys.exit(res)
+