From e3092aadc71d481695597b59c8c6609cb035ef7a Mon Sep 17 00:00:00 2001 From: Thomas Nagy Date: Thu, 1 Sep 2016 22:08:03 +0200 Subject: [PATCH] Parallel tests can now have an execution order --- demos/c/wscript | 6 ++++++ waflib/Tools/c_config.py | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/demos/c/wscript b/demos/c/wscript index 43878786..b09e54ed 100644 --- a/demos/c/wscript +++ b/demos/c/wscript @@ -42,10 +42,16 @@ def configure(conf): #ctx.check_large_file(mandatory=False) conf.multicheck( + # list of conf.check() arguments {'header_name':'stdio.h', 'msg':'... stdio', 'uselib_store': 'STDIO'}, {'header_name':'xyztabcd.h', 'msg':'... optional xyztabcd.h', 'mandatory': False}, {'header_name':'stdlib.h', 'msg':'... stdlib', 'okmsg': 'aye', 'errmsg': 'nope'}, {'func': test_build, 'msg':'... testing an arbitrary build function', 'okmsg':'ok'}, + + # parallelism control with after_tests/before_tests + {'header_name':'malloc.h', 'msg':'... malloc', 'uselib_store': 'MALLOC', 'id': 'malloc_t'}, + {'header_name':'unistd.h', 'msg':'... unistd', 'uselib_store': 'UNISTD', 'before_tests': ['malloc_t']}, + msg = 'Checking for headers in parallel', #mandatory = False, # set to False to make all tests non-mandatory #run_all_tests = False # set to False to stop at the first error diff --git a/waflib/Tools/c_config.py b/waflib/Tools/c_config.py index 88d4774e..fa298622 100644 --- a/waflib/Tools/c_config.py +++ b/waflib/Tools/c_config.py @@ -1250,10 +1250,17 @@ class cfgtask(Task.TaskBase): Make sure to use locks if concurrent access to the same conf.env data is necessary. """ + def __init__(self, *k, **kw): + Task.TaskBase.__init__(self, *k, **kw) + self.run_after = set() + def display(self): return '' def runnable_status(self): + for x in self.run_after: + if not x.hasrun: + return Task.ASK_LATER return Task.RUN_ME def uid(self): @@ -1343,6 +1350,8 @@ def multicheck(self, *k, **kw): bld = par() bld.keep = kw.get('run_all_tests', True) tasks = [] + + id_to_task = {} for dct in k: x = Task.classes['cfgtask'](bld=bld) tasks.append(x) @@ -1354,6 +1363,22 @@ def multicheck(self, *k, **kw): # bind a logger that will keep the info in memory x.logger = Logs.make_mem_logger(str(id(x)), self.logger) + if 'id' in dct: + id_to_task[dct['id']] = x + + # second pass to set dependencies with after_test/before_test + for x in tasks: + for key in Utils.to_list(x.args.get('before_tests', [])): + tsk = id_to_task[key] + if not tsk: + raise ValueError('No test named %r' % key) + tsk.run_after.add(x) + for key in Utils.to_list(x.args.get('after_tests', [])): + tsk = id_to_task[key] + if not tsk: + raise ValueError('No test named %r' % key) + x.run_after.add(tsk) + def it(): yield tasks while 1: