check: Use meson introspect to list meson tests

This commit is contained in:
Thibault Saunier 2018-03-18 10:38:42 -03:00
parent dede83a542
commit 3f66772fa1

View file

@ -17,46 +17,44 @@
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301, USA. # Boston, MA 02110-1301, USA.
import argparse import argparse
import json
import os import os
import re import re
import pickle import pickle
import platform import platform
import shutil import shutil
import subprocess
import threading import threading
import concurrent.futures as conc import concurrent.futures as conc
from launcher import config from launcher import config
from launcher.utils import printc, Colors from launcher.utils import printc, Colors
class MesonTest(Test): class MesonTest(Test):
def __init__(self, name, options, reporter, test, child_env=None): def __init__(self, name, options, reporter, test_infos, child_env=None):
ref_env = os.environ.copy() ref_env = os.environ.copy()
if child_env is None: if child_env is None:
child_env = {} child_env = {}
else: else:
ref_env.update(child_env) ref_env.update(child_env)
if not isinstance(test.env, dict): child_env.update(test_infos['env'])
test.env = test.env.get_env(ref_env)
child_env.update(test.env)
if len(test.extra_paths) > 0:
child_env['PATH'] = child_env['PATH'] + \
';'.join([''] + test.extra_paths)
self.child_env = child_env self.child_env = child_env
timeout = int(child_env.pop('CK_DEFAULT_TIMEOUT', test.timeout)) timeout = int(child_env.pop(
'CK_DEFAULT_TIMEOUT', test_infos['timeout']))
Test.__init__(self, test.fname[0], name, options, Test.__init__(self, test_infos['cmd'][0], name, options,
reporter, timeout=timeout, hard_timeout=timeout, reporter, timeout=timeout, hard_timeout=timeout,
is_parallel=test.is_parallel) is_parallel=getattr(test_infos, 'is_parallel', True))
self.mesontest = test self.test_infos = test_infos
def build_arguments(self): def build_arguments(self):
self.add_arguments(*self.mesontest.fname[1:]) self.add_arguments(*self.test_infos['cmd'][1:])
self.add_arguments(*self.mesontest.cmd_args)
def get_subproc_env(self): def get_subproc_env(self):
env = os.environ.copy() env = os.environ.copy()
@ -86,32 +84,34 @@ class MesonTestsManager(TestsManager):
arggroup = MesonTestsManager.arggroup = parser.add_argument_group( arggroup = MesonTestsManager.arggroup = parser.add_argument_group(
"meson tests specific options and behaviours") "meson tests specific options and behaviours")
arggroup.add_argument("--meson-build-dir", arggroup.add_argument("--meson-build-dir",
action="append", action="append",
dest='meson_build_dirs', dest='meson_build_dirs',
default=[], default=[],
help="defines the paths to look for GstValidate tools.") help="defines the paths to look for GstValidate tools.")
arggroup.add_argument("--meson-no-rebuild", arggroup.add_argument("--meson-no-rebuild",
action="store_true", action="store_true",
default=False, default=False,
help="Whether to avoid to rebuild tests before running them.") help="Whether to avoid to rebuild tests before running them.")
def get_meson_tests(self): def get_meson_tests(self):
meson = shutil.which('meson')
if not meson:
meson = shutil.which('meson.py')
if not meson:
printc("Can't find meson, can't run testsuite.\n", Colors.FAIL)
return False
if not self.options.meson_build_dirs: if not self.options.meson_build_dirs:
self.options.meson_build_dirs = [config.BUILDDIR] self.options.meson_build_dirs = [config.BUILDDIR]
mesontests = [] mesontests = []
for i, bdir in enumerate(self.options.meson_build_dirs): for i, bdir in enumerate(self.options.meson_build_dirs):
bdir = os.path.abspath(bdir) bdir = os.path.abspath(bdir)
datafile = os.path.join( output = subprocess.check_output(
bdir, 'meson-private/meson_test_setup.dat') [meson, 'introspect', '--tests', bdir])
if not os.path.isfile(datafile): for test_dict in json.loads(output.decode()):
self.error("%s does not exists, can't use meson test launcher", mesontests.append(test_dict)
datafile)
continue
with open(datafile, 'rb') as f:
tests = pickle.load(f)
mesontests.extend(tests)
return mesontests return mesontests
@ -157,9 +157,9 @@ class MesonTestsManager(TestsManager):
return TestsManager.run_tests(self, starting_test_num, total_num_tests) return TestsManager.run_tests(self, starting_test_num, total_num_tests)
def get_test_name(self, test): def get_test_name(self, test):
name = test.name.replace('/', '.') name = test['name'].replace('/', '.')
if test.suite: if test['suite']:
name = '.'.join(test.suite) + '.' + name name = '.'.join(test['suite']) + '.' + name
return name.replace('..', '.').replace(' ', '-') return name.replace('..', '.').replace(' ', '-')
@ -201,7 +201,7 @@ class GstCheckTestsManager(MesonTestsManager):
return last_touched, [] return last_touched, []
def _list_gst_check_tests(self, test, recurse=False): def _list_gst_check_tests(self, test, recurse=False):
binary = test.fname[0] binary = test['cmd'][0]
self.tests_info[binary] = self.check_binary_ts(binary) self.tests_info[binary] = self.check_binary_ts(binary)
@ -237,14 +237,14 @@ class GstCheckTestsManager(MesonTestsManager):
super().add_options(parser) super().add_options(parser)
arggroup = parser.add_argument_group("gstcheck specific options") arggroup = parser.add_argument_group("gstcheck specific options")
arggroup.add_argument("--gst-check-leak-trace-testnames", arggroup.add_argument("--gst-check-leak-trace-testnames",
default=None, default=None,
help="A regex to specifying testsnames of the test" help="A regex to specifying testsnames of the test"
"to run with the leak tracer activated, if 'known-not-leaky'" "to run with the leak tracer activated, if 'known-not-leaky'"
" is specified, the testsuite will automatically activate" " is specified, the testsuite will automatically activate"
" leak tracers on tests known to be not leaky.") " leak tracers on tests known to be not leaky.")
arggroup.add_argument("--gst-check-leak-options", arggroup.add_argument("--gst-check-leak-options",
default=None, default=None,
help="Leak tracer options") help="Leak tracer options")
def get_child_env(self, testname, check_name=None): def get_child_env(self, testname, check_name=None):
child_env = {} child_env = {}
@ -256,7 +256,8 @@ class GstCheckTestsManager(MesonTestsManager):
leak_tracer = "leaks" leak_tracer = "leaks"
if self.options.gst_check_leak_options: if self.options.gst_check_leak_options:
leak_tracer += "(%s)" % self.options.gst_check_leak_options leak_tracer += "(%s)" % self.options.gst_check_leak_options
tracers = set(os.environ.get('GST_TRACERS', '').split(';')) | set([leak_tracer]) tracers = set(os.environ.get('GST_TRACERS', '').split(
';')) | set([leak_tracer])
child_env['GST_TRACERS'] = ';'.join(tracers) child_env['GST_TRACERS'] = ';'.join(tracers)
return child_env return child_env
@ -270,7 +271,7 @@ class GstCheckTestsManager(MesonTestsManager):
mesontests = self.get_meson_tests() mesontests = self.get_meson_tests()
to_inspect = [] to_inspect = []
for test in mesontests: for test in mesontests:
binary = test.fname[0] binary = test['cmd'][0]
test_info = self.check_binary_ts(binary) test_info = self.check_binary_ts(binary)
if test_info is True: if test_info is True:
continue continue
@ -297,7 +298,7 @@ class GstCheckTestsManager(MesonTestsManager):
e.result() e.result()
for test in mesontests: for test in mesontests:
gst_tests = self.tests_info[test.fname[0]][1] gst_tests = self.tests_info[test['cmd'][0]][1]
if not gst_tests: if not gst_tests:
name = self.get_test_name(test) name = self.get_test_name(test)
child_env = self.get_child_env(name) child_env = self.get_child_env(name)