[Piglit] [PATCH 2/2] Run all tests out of a ThreadPool
Dylan Baker
baker.dylan.c at gmail.com
Mon Sep 16 09:09:35 PDT 2013
This patch removes the ConcurrentThreadPool singleton and opts instead
for creating two ThreadPools, one with multiple threads and a second one
that contains only one thread.
The reasoning for this change is two fold, first it gets rid of a rather
questionable use of a singleton, and second it cleans up the Test
derived classes. since they don't have to have a method to add
themselves to the ThreadPool, instead the ThreadPool has a method for
adding tests to itself.
Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
framework/core.py | 36 ++++++++++++++++--------------------
framework/threads.py | 17 -----------------
2 files changed, 16 insertions(+), 37 deletions(-)
diff --git a/framework/core.py b/framework/core.py
index bebe1b8..1c9537b 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -36,9 +36,12 @@ import traceback
from log import log
from cStringIO import StringIO
from textwrap import dedent
-from threads import ConcurrentTestPool
from threads import synchronized_self
import threading
+import multiprocessing
+
+from threadpool import ThreadPool
+
__all__ = ['Environment',
'checkDir',
@@ -421,19 +424,9 @@ class Test:
def run(self):
raise NotImplementedError
- def schedule(self, env, path, json_writer):
- '''
- Schedule test to be run via the concurrent thread pool.
- This is a no-op if the test isn't marked as concurrent.
-
- See ``Test.doRun`` for a description of the parameters.
- '''
- if self.runConcurrent:
- ConcurrentTestPool().put(self.doRun, args=(env, path, json_writer))
-
- def doRun(self, env, path, json_writer):
+ def execute(self, env, path, json_writer):
'''
- Run the test immediately.
+ Run a the test.
:path:
Fully qualified test name as a string. For example,
@@ -558,18 +551,21 @@ class TestProfile:
self.prepare_test_list(env)
- # Queue up all the concurrent tests, so the pool is filled
- # at the start of the test run.
+ # If using concurrency, add all the cocurrent tests to the pool and
+ # execute that pool
if env.concurrent:
+ pool = ThreadPool(multiprocessing.cpu_count())
for (path, test) in self.test_list.items():
- test.schedule(env, path, json_writer)
+ pool.add(test.execute, (env, path, json_writer))
+ pool.join()
- # Run any remaining non-concurrent tests serially from this
- # thread, while the concurrent tests
+ # Run any remaining non-concurrent tests serially from a single thread
+ # pool after the concurrent tests have finished
+ pool = ThreadPool(1)
for (path, test) in self.test_list.items():
if not env.concurrent or not test.runConcurrent:
- test.doRun(env, path, json_writer)
- ConcurrentTestPool().join()
+ pool.add(test.execute, (env, path, json_writer))
+ pool.join()
def remove_test(self, test_path):
"""Remove a fully qualified test from the profile.
diff --git a/framework/threads.py b/framework/threads.py
index ef037d1..ec7dfcc 100644
--- a/framework/threads.py
+++ b/framework/threads.py
@@ -22,10 +22,6 @@
#
from weakref import WeakKeyDictionary
-import multiprocessing
-
-from threadpool import ThreadPool
-from patterns import Singleton
from threading import RLock
@@ -45,16 +41,3 @@ def synchronized_self(function):
# track the locks for each instance
synchronized_self.locks = WeakKeyDictionary()
-
-
-class ConcurrentTestPool(Singleton):
- @synchronized_self
- def init(self):
- self.pool = ThreadPool(multiprocessing.cpu_count())
-
- @synchronized_self
- def put(self, callable, args=None):
- self.pool.add(callable, args)
-
- def join(self):
- self.pool.join()
--
1.8.1.5
More information about the Piglit
mailing list