systemc: Extend the execute phase of verify.py.
authorGabe Black <gabeblack@google.com>
Thu, 26 Jul 2018 23:06:01 +0000 (16:06 -0700)
committerGabe Black <gabeblack@google.com>
Tue, 11 Sep 2018 21:50:04 +0000 (21:50 +0000)
Add -j and --timeout options to the execute phase of verify.py.

The --timeout option is implemented using the timeout utility program
which is assumed to be available on the host system. Python 3.3 added
a timeout argument to the subprocess module which is an alternative
approach, but then we would be dependent on python 3.3.

-j is implemented using the standard multiprocess.pool.ThreadPool
class.

Change-Id: I15b92f2b14de6710e2027a6a19984b2644b2a8df
Reviewed-on: https://gem5-review.googlesource.com/12051
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Gabe Black <gabeblack@google.com>

src/systemc/tests/verify.py

index 34ae931109c60999a9988fd14194b109e18aef89..cface476189712198df1c59de7d140aee8d0b770 100755 (executable)
@@ -35,6 +35,7 @@ import inspect
 import itertools
 import json
 import logging
+import multiprocessing.pool
 import os
 import subprocess
 import sys
@@ -120,16 +121,39 @@ class RunPhase(TestPhaseBase):
     number = 2
 
     def run(self, tests):
-        for test in tests:
-            if test.compile_only:
-                continue
-            args = [
+        parser = argparse.ArgumentParser()
+        parser.add_argument('--timeout', type=int, metavar='SECONDS',
+                            help='Time limit for each run in seconds.',
+                            default=0)
+        parser.add_argument('-j', type=int, default=1,
+                help='How many tests to run in parallel.')
+        args = parser.parse_args(self.args)
+
+        timeout_cmd = [
+            'timeout',
+            '--kill-after', str(args.timeout * 2),
+            str(args.timeout)
+        ]
+        def run_test(test):
+            cmd = []
+            if args.timeout:
+                cmd.extend(timeout_cmd)
+            cmd.extend([
                 test.full_path(),
                 '-red', test.m5out_dir(),
                 '--listener-mode=off',
                 config_path
-            ]
-            subprocess.check_call(args)
+            ])
+            subprocess.check_call(cmd)
+
+        runnable = filter(lambda t: not t.compile_only, tests)
+        if args.j == 1:
+            map(run_test, runnable)
+        else:
+            tp = multiprocessing.pool.ThreadPool(args.j)
+            map(lambda t: tp.apply_async(run_test, (t,)), runnable)
+            tp.close()
+            tp.join()
 
 class VerifyPhase(TestPhaseBase):
     name = 'verify'