Merge pull request #1402 from centricular/test-setup-fixes

Various fixes to how mesontest handles test setups.
pull/1389/head
Jussi Pakkanen 8 years ago committed by GitHub
commit d6614ba811
  1. 4
      mesonbuild/build.py
  2. 6
      mesonbuild/interpreter.py
  3. 21
      mesontest.py
  4. 10
      run_unittests.py
  5. 4
      test cases/unit/2 testsetups/buggy.c
  6. 4
      test cases/unit/2 testsetups/meson.build

@ -229,6 +229,10 @@ class EnvironmentVariables:
def __init__(self):
self.envvars = []
def __repr__(self):
repr_str = "<{0}: {1}>"
return repr_str.format(self.__class__.__name__, self.envvars)
def get_value(self, name, values, kwargs):
separator = kwargs.get('separator', os.pathsep)

@ -134,6 +134,10 @@ class EnvironmentVariablesHolder(MutableInterpreterObject):
'prepend': self.prepend_method,
})
def __repr__(self):
repr_str = "<{0}: {1}>"
return repr_str.format(self.__class__.__name__, self.held_object.envvars)
@stringArgs
def add_var(self, method, args, kwargs):
if not isinstance(kwargs.get("separator", ""), str):
@ -2056,7 +2060,7 @@ requirements use the version keyword argument instead.''')
self.add_test(node, args, kwargs, True)
def unpack_env_kwarg(self, kwargs):
envlist = kwargs.get('env', [])
envlist = kwargs.get('env', EnvironmentVariablesHolder())
if isinstance(envlist, EnvironmentVariablesHolder):
env = envlist.held_object
else:

@ -83,7 +83,7 @@ parser.add_argument('-v', '--verbose', default=False, action='store_true',
help='Do not redirect stdout and stderr')
parser.add_argument('-q', '--quiet', default=False, action='store_true',
help='Produce less output to the terminal.')
parser.add_argument('-t', '--timeout-multiplier', type=float, default=1.0,
parser.add_argument('-t', '--timeout-multiplier', type=float, default=None,
help='Define a multiplier for test timeout, for example '
' when running tests in particular conditions they might take'
' more time to execute.')
@ -393,15 +393,18 @@ TIMEOUT: %4d
if not self.options.logbase or self.options.verbose:
return None, None, None, None
namebase = None
logfile_base = os.path.join(self.options.wd, 'meson-logs', self.options.logbase)
if self.options.wrapper is None:
logfilename = logfile_base + '.txt'
jsonlogfilename = logfile_base + '.json'
else:
if self.options.wrapper:
namebase = os.path.split(self.get_wrapper()[0])[1]
logfilename = logfile_base + '-' + namebase.replace(' ', '_') + '.txt'
jsonlogfilename = logfile_base + '-' + namebase.replace(' ', '_') + '.json'
elif self.options.setup:
namebase = self.options.setup
if namebase:
logfile_base += '-' + namebase.replace(' ', '_')
logfilename = logfile_base + '.txt'
jsonlogfilename = logfile_base + '.json'
jsonlogfile = open(jsonlogfilename, 'w')
logfile = open(logfilename, 'w')
@ -497,6 +500,8 @@ TIMEOUT: %4d
if os.path.isfile('build.ninja'):
subprocess.check_call([environment.detect_ninja(), 'all'])
tests = self.get_tests()
if not tests:
return 0
self.run_tests(tests)
return self.fail_count
@ -555,6 +560,8 @@ def run(args):
global_env = merge_suite_options(options)
else:
global_env = build.EnvironmentVariables()
if options.timeout_multiplier is None:
options.timeout_multiplier = 1
setattr(options, 'global_env', global_env)

@ -602,9 +602,11 @@ class AllPlatformTests(BasePlatformTests):
testdir = os.path.join(self.unit_test_dir, '2 testsetups')
self.init(testdir)
self.build()
# Run tests without setup
self.run_tests()
with open(os.path.join(self.logdir, 'testlog.txt')) as f:
basic_log = f.read()
# Run buggy test with setup that has env that will make it fail
self.assertRaises(subprocess.CalledProcessError,
self._run, self.mtest_command + ['--setup=valgrind'])
with open(os.path.join(self.logdir, 'testlog-valgrind.txt')) as f:
@ -613,6 +615,14 @@ class AllPlatformTests(BasePlatformTests):
self.assertFalse('Memcheck' in basic_log)
self.assertTrue('TEST_ENV is set' in vg_log)
self.assertTrue('Memcheck' in vg_log)
# Run buggy test with setup without env that will pass
self._run(self.mtest_command + ['--setup=wrapper'])
# Setup with no properties works
self._run(self.mtest_command + ['--setup=empty'])
# Setup with only env works
self._run(self.mtest_command + ['--setup=onlyenv'])
# Setup with only a timeout works
self._run(self.mtest_command + ['--setup=timeout'])
def assertFailedTestCount(self, failure_count, command):
try:

@ -5,10 +5,10 @@
int main(int argc, char **argv) {
char *ten = malloc(10);
do_nasty(ten);
free(ten);
if(getenv("TEST_ENV")) {
do_nasty(ten);
printf("TEST_ENV is set.\n");
}
free(ten);
return 0;
}

@ -14,3 +14,7 @@ add_test_setup('valgrind',
buggy = executable('buggy', 'buggy.c', 'impl.c')
test('Test buggy', buggy)
add_test_setup('empty')
add_test_setup('onlyenv', env : env)
add_test_setup('wrapper', exe_wrapper : [vg, '--error-exitcode=1'])
add_test_setup('timeout', timeout_multiplier : 20)

Loading…
Cancel
Save