validate:launcher: Refactor the "main" function

- Move the parser code into a `LauncherConfig.create_parser()` method
- Remove the need to pass libsdir to the _TestsLauncher object
- Extract out a `setup_launcher_from_args` function
This commit is contained in:
Thibault Saunier 2019-01-25 22:13:28 -03:00 committed by Thibault Saunier
parent 1b3867b82d
commit 6665652cff
2 changed files with 220 additions and 208 deletions

View file

@ -1399,11 +1399,10 @@ class GstValidateTestsGenerator(TestsGenerator):
class _TestsLauncher(Loggable):
def __init__(self, libsdir):
def __init__(self):
Loggable.__init__(self)
self.libsdir = libsdir
self.options = None
self.testers = []
self.tests = []
@ -1419,15 +1418,12 @@ class _TestsLauncher(Loggable):
self.httpsrv = None
self.vfb_server = None
def _list_app_dirs(self):
app_dirs = []
app_dirs.append(os.path.join(self.libsdir, "apps"))
env_dirs = os.environ.get("GST_VALIDATE_APPS_DIR")
env_dirs = os.environ["GST_VALIDATE_APPS_DIR"]
if env_dirs is not None:
for dir_ in env_dirs.split(":"):
app_dirs.append(dir_)
sys.path.append(dir_)
return app_dirs
@ -1600,12 +1596,12 @@ class _TestsLauncher(Loggable):
if options.no_display:
self.vfb_server = get_virual_frame_buffer_server(options)
res = vfb_server.start()
res = self.vfb_server.start()
if res[0] is False:
printc("Could not start virtual frame server: %s" % res[1],
Colors.FAIL)
return False
os.environ["DISPLAY"] = vfb_server.display_id
os.environ["DISPLAY"] = self.vfb_server.display_id
return True
@ -1837,7 +1833,7 @@ class _TestsLauncher(Loggable):
if self.httpsrv:
self.httpsrv.stop()
if self.vfb_server:
vfb_server.stop()
self.vfb_server.stop()
self.clean_tests()
def final_report(self):

View file

@ -135,6 +135,9 @@ http://wiki.pitivi.org/wiki/Bug_reporting#Debug_logs).
dir(Protocols) if isinstance(getattr(Protocols, att), str) and not
att.startswith("_")]))
if "--help" not in sys.argv:
HELP = "Use --help for the full help"
QA_ASSETS = "gst-integration-testsuites"
MEDIAS_FOLDER = "medias"
DEFAULT_GST_QA_ASSETS_REPO = "https://gitlab.freedesktop.org/gstreamer/gst-integration-testsuites.git"
@ -342,33 +345,26 @@ class LauncherConfig(Loggable):
if path not in self.paths:
self.paths.append(path)
def main(libsdir):
if "--help" in sys.argv:
_help_message = HELP
else:
_help_message = "Use --help for the full help"
DEFAULT_TESTSUITES_DIRS.append(os.path.join(libsdir, "testsuites"))
@staticmethod
def create_parser():
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter,
prog='gst-validate-launcher', description=_help_message)
prog='gst-validate-launcher', description=HELP)
parser.add_argument('testsuites', metavar='N', nargs='*',
help="""Lets you specify a test to run, a testsuite name or a file where the testsuite to execute is defined.
In the module if you want to work with a specific test manager(s) (for example,
'ges' or 'validate'), you should define the TEST_MANAGER variable in the
testsuite file (it can be a list of test manager names)
In the module if you want to work with a specific test manager(s) (for example,
'ges' or 'validate'), you should define the TEST_MANAGER variable in the
testsuite file (it can be a list of test manager names)
In this file you should implement a setup_tests function. That function takes
a TestManager and the GstValidateLauncher option as parameters and return True
if it succeeded loading the tests, False otherwise.
You will be able to configure the TestManager with its various methods. This
function will be called with each TestManager usable, for example you will be
passed the 'validate' TestManager in case the GstValidateManager launcher is
available. You should configure it using:
In this file you should implement a setup_tests function. That function takes
a TestManager and the GstValidateLauncher option as parameters and return True
if it succeeded loading the tests, False otherwise.
You will be able to configure the TestManager with its various methods. This
function will be called with each TestManager usable, for example you will be
passed the 'validate' TestManager in case the GstValidateManager launcher is
available. You should configure it using:
* test_manager.add_scenarios: which allows you to register a list of scenario names to be run
* test_manager.set_default_blacklist: Lets you set a list of tuple of the form:
@ -377,14 +373,14 @@ available. You should configure it using:
to be used to generate tests
* test_manager.add_encoding_formats:: which allows you to register a list #MediaFormatCombination to be used for transcoding tests
You can also set default values with:
You can also set default values with:
* test_manager.register_defaults: Sets default values for all parametters
* test_manager.register_default_test_generators: Sets default values for the TestsGenerators to be used
* test_manager.register_default_scenarios: Sets default values for the scenarios to be executed
* test_manager.register_default_encoding_formats: Sets default values for the encoding formats to be tested
Note that all testsuite should be inside python modules, so the directory should contain a __init__.py file
""",
Note that all testsuite should be inside python modules, so the directory should contain a __init__.py file
""",
default=["validate"])
parser.add_argument("-d", "--debug", dest="debug",
action="store_true",
@ -541,36 +537,56 @@ Note that all testsuite should be inside python modules, so the directory should
" including big media files")
assets_group.add_argument("--usage", action=PrintUsage,
help="Print usage documentation")
return parser
def setup_launcher_from_args(args):
loggable.init("GST_VALIDATE_LAUNCHER_DEBUG", True, False)
tests_launcher = _TestsLauncher(libsdir)
parser = LauncherConfig.create_parser()
tests_launcher = _TestsLauncher()
tests_launcher.add_options(parser)
if _help_message == HELP and which(LESS):
if "--help" in sys.argv and which(LESS):
tmpf = tempfile.NamedTemporaryFile(mode='r+')
parser.print_help(file=tmpf)
exit(os.system("%s %s" % (LESS, tmpf.name)))
os.system("%s %s" % (LESS, tmpf.name))
return False, None, None
options = LauncherConfig()
parser.parse_args(namespace=options)
parser.parse_args(args=args, namespace=options)
if not options.cleanup():
exit(1)
return False, None, None
if options.remote_assets_url and options.sync and not os.path.exists(options.clone_dir):
if not download_assets(options):
exit(1)
return False, None, None
# Ensure that the scenario manager singleton is ready to be used
ScenarioManager().config = options
if not tests_launcher.set_settings(options, []):
exit(1)
return False, None, None
return True, options, tests_launcher
def main(libsdir):
global LIBSDIR
LIBSDIR = libsdir
DEFAULT_TESTSUITES_DIRS.append(os.path.join(LIBSDIR, "testsuites"))
os.environ["GST_VALIDATE_APPS_DIR"] = os.path.join(
LIBSDIR, "apps") + os.pathsep + os.environ.get("GST_VALIDATE_APPS_DIR", "")
res, options, tests_launcher = setup_launcher_from_args(sys.argv[1:])
if res is False:
return 1
if options.list_tests:
if tests_launcher.list_tests() == -1:
printc("\nFailling as tests have been removed/added "
" (--fail-on-testlist-change)", Colors.FAIL)
exit(1)
return 1
tests = tests_launcher.tests
for test in tests: