[poppler] 2 commits - regtest/commands regtest/TestRun.py regtest/Utils.py

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Sun Oct 26 03:34:14 PDT 2014


 regtest/TestRun.py            |   53 +++++++++++++++++++++++++++++++++---------
 regtest/Utils.py              |    7 +++--
 regtest/commands/run-tests.py |   29 +++++++++++++++-------
 3 files changed, 67 insertions(+), 22 deletions(-)

New commits:
commit 68e58ec5465efc289d85ae104941db92450a3168
Author: Carlos Garcia Campos <cgarcia at igalia.com>
Date:   Sun Oct 26 11:21:23 2014 +0100

    regtest: Limit the number of worker threads to the number of documents to test
    
    We are always spawning all the threads even if the documents to test is
    less than the worker threads. Also optimize the case of running only one
    test to not spwn any thread.

diff --git a/regtest/TestRun.py b/regtest/TestRun.py
index 7a2f5df..2531911 100644
--- a/regtest/TestRun.py
+++ b/regtest/TestRun.py
@@ -199,22 +199,31 @@ class TestRun:
         backends = self._get_backends()
         self._total_tests = total_docs * len(backends)
 
+        if total_docs == 1:
+            n_workers = 0
+        else:
+            n_workers = min(self.config.threads, total_docs)
+
         self.printer.printout_ln('Found %d documents' % (total_docs))
         self.printer.printout_ln('Backends: %s' % ', '.join([backend.get_name() for backend in backends]))
-        self.printer.printout_ln('Process %d using %d worker threads' % (os.getpid(), self.config.threads))
+        self.printer.printout_ln('Process %d using %d worker threads' % (os.getpid(), n_workers))
         self.printer.printout_ln()
 
-        self.printer.printout('Spawning %d workers...' % (self.config.threads))
+        if n_workers > 0:
+            self.printer.printout('Spawning %d workers...' % (self.config.threads))
 
-        for n_thread in range(self.config.threads):
-            thread = Thread(target=self._worker_thread)
-            thread.daemon = True
-            thread.start()
+            for n_thread in range(n_workers):
+                thread = Thread(target=self._worker_thread)
+                thread.daemon = True
+                thread.start()
 
-        for doc in docs:
-            self._queue.put(doc)
+            for doc in docs:
+                self._queue.put(doc)
 
-        self._queue.join()
+            self._queue.join()
+        else:
+            for doc in docs:
+                self.run_test(doc)
 
         return int(self._n_passed != self._n_run)
 
commit 7c21b95852e891060cd2e276949acf0945306ab7
Author: Carlos Garcia Campos <cgarcia at igalia.com>
Date:   Sun Oct 26 11:08:45 2014 +0100

    regtest: Allow to run groups of tests individually
    
    Now it's possible to pass more than one argument to run-tests command and
    optionally the docs directory. When more than one test is passed and the
    docs directory is not provided, the common base path of all passed tests
    is used as docs directory. The tests passed can be documents or
    directories, using absolute paths or paths relative to the docs
    directory.
    This also allows us to update the refs for a group of tests.

diff --git a/regtest/TestRun.py b/regtest/TestRun.py
index 6aba62f..7a2f5df 100644
--- a/regtest/TestRun.py
+++ b/regtest/TestRun.py
@@ -172,8 +172,30 @@ class TestRun:
             self.run_test(doc)
             self._queue.task_done()
 
-    def run_tests(self):
-        docs, total_docs = get_document_paths_from_dir(self._docsdir)
+    def run_tests(self, tests = []):
+        if not tests:
+            docs, total_docs = get_document_paths_from_dir(self._docsdir)
+        else:
+            docs = []
+            total_docs = 0
+            for test in tests:
+                if os.path.isdir(test):
+                    test_dir = test
+                elif os.path.isdir(os.path.join(self._docsdir, test)):
+                    test_dir = os.path.join(self._docsdir, test)
+                else:
+                    test_dir = None
+
+                if test_dir is not None:
+                    dir_docs, dir_n_docs = get_document_paths_from_dir(test_dir, self._docsdir)
+                    docs.extend(dir_docs)
+                    total_docs += dir_n_docs
+                else:
+                    if test.startswith(self._docsdir):
+                        test = test[len(self._docsdir):].lstrip(os.path.sep)
+                    docs.append(test)
+                    total_docs += 1
+
         backends = self._get_backends()
         self._total_tests = total_docs * len(backends)
 
diff --git a/regtest/Utils.py b/regtest/Utils.py
index 90a6eea..f491a6d 100644
--- a/regtest/Utils.py
+++ b/regtest/Utils.py
@@ -18,7 +18,10 @@
 
 import os
 
-def get_document_paths_from_dir(docsdir):
+def get_document_paths_from_dir(docsdir, basedir = None):
+    if basedir is None:
+        basedir = docsdir
+
     paths = []
     n_paths = 0
     for root, dirs, files in os.walk(docsdir, False):
@@ -26,7 +29,7 @@ def get_document_paths_from_dir(docsdir):
             if not entry.lower().endswith('.pdf'):
                 continue
 
-            test_path = os.path.join(root[len(docsdir):], entry)
+            test_path = os.path.join(root[len(basedir):], entry)
             paths.append(test_path.lstrip(os.path.sep))
             n_paths += 1
     paths.sort()
diff --git a/regtest/commands/run-tests.py b/regtest/commands/run-tests.py
index 29e7dfa..5f1914f 100644
--- a/regtest/commands/run-tests.py
+++ b/regtest/commands/run-tests.py
@@ -39,6 +39,9 @@ class RunTests(Command):
         parser.add_argument('-o', '--out-dir',
                             action = 'store', dest = 'out_dir', default = os.path.join(tempfile.gettempdir(), 'out'),
                             help = 'Directory where test results will be created')
+        parser.add_argument('--docs-dir',
+                            action = 'store', dest = 'docs_dir',
+                            help = 'Base documents directory')
         parser.add_argument('--keep-results',
                             action = 'store_true', dest = 'keep_results', default = False,
                             help = 'Do not remove result files for passing tests')
@@ -48,7 +51,8 @@ class RunTests(Command):
         parser.add_argument('--update-refs',
                             action = 'store_true', dest = 'update_refs', default = False,
                             help = 'Update references for failed tests')
-        parser.add_argument('tests')
+        parser.add_argument('tests', metavar = 'TEST', nargs = '+',
+                            help = 'Tests directory or individual test to run')
 
     def run(self, options):
         config = Config()
@@ -57,17 +61,24 @@ class RunTests(Command):
         config.update_refs = options['update_refs']
 
         t = Timer()
-        doc = options['tests']
-        if os.path.isdir(doc):
-            docs_dir = doc
+        docs = options['tests']
+        docs_dir = options['docs_dir']
+
+        if len(docs) == 1:
+            if os.path.isdir(docs[0]):
+                if docs_dir is None:
+                    docs_dir = docs[0]
+                if docs_dir == docs[0]:
+                    docs = []
+            else:
+                if docs_dir is None:
+                    docs_dir = os.path.dirname(docs[0])
         else:
-            docs_dir = os.path.dirname(doc)
+            if docs_dir is None:
+                docs_dir = os.path.commonprefix(docs).rpartition(os.path.sep)[0]
 
         tests = TestRun(docs_dir, options['refs_dir'], options['out_dir'])
-        if doc == docs_dir:
-            status = tests.run_tests()
-        else:
-            status = tests.run_test(os.path.basename(doc))
+        status = tests.run_tests(docs)
         tests.summary()
         get_printer().printout_ln("Tests run in %s" % (t.elapsed_str()))
 


More information about the poppler mailing list