Skip to content
Snippets Groups Projects
Commit c7449166 authored by Craig Tiller's avatar Craig Tiller
Browse files

PHP unit tests run with run_tests.py

parent c2e80bfb
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ class SimpleConfig(object): ...@@ -20,6 +20,7 @@ class SimpleConfig(object):
def __init__(self, config): def __init__(self, config):
self.build_config = config self.build_config = config
self.maxjobs = 32 * multiprocessing.cpu_count() self.maxjobs = 32 * multiprocessing.cpu_count()
self.allow_hashing = (config != 'gcov')
def run_command(self, binary): def run_command(self, binary):
return [binary] return [binary]
...@@ -32,11 +33,43 @@ class ValgrindConfig(object): ...@@ -32,11 +33,43 @@ class ValgrindConfig(object):
self.build_config = config self.build_config = config
self.tool = tool self.tool = tool
self.maxjobs = 4 * multiprocessing.cpu_count() self.maxjobs = 4 * multiprocessing.cpu_count()
self.allow_hashing = False
def run_command(self, binary): def run_command(self, binary):
return ['valgrind', binary, '--tool=%s' % self.tool] return ['valgrind', binary, '--tool=%s' % self.tool]
class CLanguage(object):
def __init__(self, make_target):
self.allow_hashing = True
self.make_target = make_target
def test_binaries(self, config):
return glob.glob('bins/%s/*_test' % config)
def make_targets(self):
return ['buildtests_%s' % self.make_target]
def build_steps(self):
return []
class PhpLanguage(object):
def __init__(self):
self.allow_hashing = False
def test_binaries(self, config):
return ['src/php/bin/run_tests.sh']
def make_targets(self):
return []
def build_steps(self):
return [['tools/run_tests/build_php.sh']]
# different configurations we can run under # different configurations we can run under
_CONFIGS = { _CONFIGS = {
'dbg': SimpleConfig('dbg'), 'dbg': SimpleConfig('dbg'),
...@@ -51,10 +84,10 @@ _CONFIGS = { ...@@ -51,10 +84,10 @@ _CONFIGS = {
_DEFAULT = ['dbg', 'opt'] _DEFAULT = ['dbg', 'opt']
_LANGUAGE_BUILD_RULE = { _LANGUAGES = {
'c++': ['make', 'buildtests_cxx'], 'c++': CLanguage('cxx'),
'c': ['make', 'buildtests_c'], 'c': CLanguage('c'),
'php': ['tools/run_tests/build_php.sh'] 'php': PhpLanguage()
} }
# parse command line # parse command line
...@@ -63,7 +96,6 @@ argp.add_argument('-c', '--config', ...@@ -63,7 +96,6 @@ argp.add_argument('-c', '--config',
choices=['all'] + sorted(_CONFIGS.keys()), choices=['all'] + sorted(_CONFIGS.keys()),
nargs='+', nargs='+',
default=_DEFAULT) default=_DEFAULT)
argp.add_argument('-t', '--test-filter', nargs='*', default=['*'])
argp.add_argument('-n', '--runs_per_test', default=1, type=int) argp.add_argument('-n', '--runs_per_test', default=1, type=int)
argp.add_argument('-f', '--forever', argp.add_argument('-f', '--forever',
default=False, default=False,
...@@ -74,9 +106,9 @@ argp.add_argument('--newline_on_success', ...@@ -74,9 +106,9 @@ argp.add_argument('--newline_on_success',
action='store_const', action='store_const',
const=True) const=True)
argp.add_argument('-l', '--language', argp.add_argument('-l', '--language',
choices=sorted(_LANGUAGE_BUILD_RULE.keys()), choices=sorted(_LANGUAGES.keys()),
nargs='+', nargs='+',
default=sorted(_LANGUAGE_BUILD_RULE.keys())) default=sorted(_LANGUAGES.keys()))
args = argp.parse_args() args = argp.parse_args()
# grab config # grab config
...@@ -86,21 +118,17 @@ run_configs = set(_CONFIGS[cfg] ...@@ -86,21 +118,17 @@ run_configs = set(_CONFIGS[cfg]
for x in args.config)) for x in args.config))
build_configs = set(cfg.build_config for cfg in run_configs) build_configs = set(cfg.build_config for cfg in run_configs)
make_targets = set() make_targets = []
build_steps = [] languages = set(_LANGUAGES[l] for l in args.language)
for language in args.language: build_steps = [['make',
cmd = _LANGUAGE_BUILD_RULE[language] '-j', '%d' % (multiprocessing.cpu_count() + 1),
if cmd[0] == 'make': 'CONFIG=%s' % cfg] + list(set(
make_targets.update(cmd[1:]) itertools.chain.from_iterable(l.make_targets()
else: for l in languages)))
build_steps.append(cmd) for cfg in build_configs] + list(
if make_targets: itertools.chain.from_iterable(l.build_steps()
build_steps = [['make', for l in languages))
'-j', '%d' % (multiprocessing.cpu_count() + 1),
'CONFIG=%s' % cfg] + list(make_targets)
for cfg in build_configs] + build_steps
filters = args.test_filter
runs_per_test = args.runs_per_test runs_per_test = args.runs_per_test
forever = args.forever forever = args.forever
...@@ -146,28 +174,26 @@ def _build_and_run(check_cancelled, newline_on_success, cache): ...@@ -146,28 +174,26 @@ def _build_and_run(check_cancelled, newline_on_success, cache):
return 1 return 1
# run all the tests # run all the tests
if not jobset.run( one_run = dict(
itertools.ifilter( (' '.join(config.run_command(x)), config.run_command(x))
lambda x: x is not None, ( for config in run_configs
config.run_command(x) for language in args.language
for config in run_configs for x in _LANGUAGES[language].test_binaries(config.build_config)
for filt in filters ).values()
for x in itertools.chain.from_iterable(itertools.repeat( all_runs = itertools.chain.from_iterable(
glob.glob('bins/%s/%s_test' % ( itertools.repeat(one_run, runs_per_test))
config.build_config, filt)), if not jobset.run(all_runs, check_cancelled,
runs_per_test)))), newline_on_success=newline_on_success,
check_cancelled, maxjobs=min(c.maxjobs for c in run_configs),
newline_on_success=newline_on_success, cache=cache):
maxjobs=min(c.maxjobs for c in run_configs),
cache=cache):
return 2 return 2
return 0 return 0
test_cache = (None if runs_per_test != 1 test_cache = (None
or 'gcov' in build_configs if not all(x.allow_hashing
or 'valgrind' in build_configs for x in itertools.chain(languages, run_configs))
else TestCache()) else TestCache())
if test_cache: if test_cache:
test_cache.maybe_load() test_cache.maybe_load()
...@@ -187,6 +213,7 @@ if forever: ...@@ -187,6 +213,7 @@ if forever:
'All tests are now passing properly', 'All tests are now passing properly',
do_newline=True) do_newline=True)
jobset.message('IDLE', 'No change detected') jobset.message('IDLE', 'No change detected')
if test_cache: test_cache.save()
while not have_files_changed(): while not have_files_changed():
time.sleep(1) time.sleep(1)
else: else:
...@@ -197,5 +224,5 @@ else: ...@@ -197,5 +224,5 @@ else:
jobset.message('SUCCESS', 'All tests passed', do_newline=True) jobset.message('SUCCESS', 'All tests passed', do_newline=True)
else: else:
jobset.message('FAILED', 'Some tests failed', do_newline=True) jobset.message('FAILED', 'Some tests failed', do_newline=True)
test_cache.save() if test_cache: test_cache.save()
sys.exit(result) sys.exit(result)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment