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): class _TestsLauncher(Loggable):
def __init__(self, libsdir): def __init__(self):
Loggable.__init__(self) Loggable.__init__(self)
self.libsdir = libsdir
self.options = None self.options = None
self.testers = [] self.testers = []
self.tests = [] self.tests = []
@ -1419,15 +1418,12 @@ class _TestsLauncher(Loggable):
self.httpsrv = None self.httpsrv = None
self.vfb_server = None self.vfb_server = None
def _list_app_dirs(self): def _list_app_dirs(self):
app_dirs = [] app_dirs = []
app_dirs.append(os.path.join(self.libsdir, "apps")) env_dirs = os.environ["GST_VALIDATE_APPS_DIR"]
env_dirs = os.environ.get("GST_VALIDATE_APPS_DIR")
if env_dirs is not None: if env_dirs is not None:
for dir_ in env_dirs.split(":"): for dir_ in env_dirs.split(":"):
app_dirs.append(dir_) app_dirs.append(dir_)
sys.path.append(dir_)
return app_dirs return app_dirs
@ -1600,12 +1596,12 @@ class _TestsLauncher(Loggable):
if options.no_display: if options.no_display:
self.vfb_server = get_virual_frame_buffer_server(options) self.vfb_server = get_virual_frame_buffer_server(options)
res = vfb_server.start() res = self.vfb_server.start()
if res[0] is False: if res[0] is False:
printc("Could not start virtual frame server: %s" % res[1], printc("Could not start virtual frame server: %s" % res[1],
Colors.FAIL) Colors.FAIL)
return False return False
os.environ["DISPLAY"] = vfb_server.display_id os.environ["DISPLAY"] = self.vfb_server.display_id
return True return True
@ -1837,7 +1833,7 @@ class _TestsLauncher(Loggable):
if self.httpsrv: if self.httpsrv:
self.httpsrv.stop() self.httpsrv.stop()
if self.vfb_server: if self.vfb_server:
vfb_server.stop() self.vfb_server.stop()
self.clean_tests() self.clean_tests()
def final_report(self): 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 dir(Protocols) if isinstance(getattr(Protocols, att), str) and not
att.startswith("_")])) att.startswith("_")]))
if "--help" not in sys.argv:
HELP = "Use --help for the full help"
QA_ASSETS = "gst-integration-testsuites" QA_ASSETS = "gst-integration-testsuites"
MEDIAS_FOLDER = "medias" MEDIAS_FOLDER = "medias"
DEFAULT_GST_QA_ASSETS_REPO = "https://gitlab.freedesktop.org/gstreamer/gst-integration-testsuites.git" 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: if path not in self.paths:
self.paths.append(path) self.paths.append(path)
@staticmethod
def main(libsdir): def create_parser():
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"))
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter, formatter_class=argparse.RawTextHelpFormatter,
prog='gst-validate-launcher', description=_help_message) prog='gst-validate-launcher', description=HELP)
parser.add_argument('testsuites', metavar='N', nargs='*', 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. 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, 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 'ges' or 'validate'), you should define the TEST_MANAGER variable in the
testsuite file (it can be a list of test manager names) testsuite file (it can be a list of test manager names)
In this file you should implement a setup_tests function. That function takes In this file you should implement a setup_tests function. That function takes
a TestManager and the GstValidateLauncher option as parameters and return True a TestManager and the GstValidateLauncher option as parameters and return True
if it succeeded loading the tests, False otherwise. if it succeeded loading the tests, False otherwise.
You will be able to configure the TestManager with its various methods. This 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 function will be called with each TestManager usable, for example you will be
passed the 'validate' TestManager in case the GstValidateManager launcher is passed the 'validate' TestManager in case the GstValidateManager launcher is
available. You should configure it using: 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.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: * 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 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 * 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_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_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_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 * 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"]) default=["validate"])
parser.add_argument("-d", "--debug", dest="debug", parser.add_argument("-d", "--debug", dest="debug",
action="store_true", action="store_true",
@ -541,36 +537,56 @@ Note that all testsuite should be inside python modules, so the directory should
" including big media files") " including big media files")
assets_group.add_argument("--usage", action=PrintUsage, assets_group.add_argument("--usage", action=PrintUsage,
help="Print usage documentation") help="Print usage documentation")
return parser
def setup_launcher_from_args(args):
loggable.init("GST_VALIDATE_LAUNCHER_DEBUG", True, False) loggable.init("GST_VALIDATE_LAUNCHER_DEBUG", True, False)
parser = LauncherConfig.create_parser()
tests_launcher = _TestsLauncher(libsdir) tests_launcher = _TestsLauncher()
tests_launcher.add_options(parser) 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+') tmpf = tempfile.NamedTemporaryFile(mode='r+')
parser.print_help(file=tmpf) 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() options = LauncherConfig()
parser.parse_args(namespace=options) parser.parse_args(args=args, namespace=options)
if not options.cleanup(): 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 options.remote_assets_url and options.sync and not os.path.exists(options.clone_dir):
if not download_assets(options): if not download_assets(options):
exit(1) return False, None, None
# Ensure that the scenario manager singleton is ready to be used # Ensure that the scenario manager singleton is ready to be used
ScenarioManager().config = options ScenarioManager().config = options
if not tests_launcher.set_settings(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 options.list_tests:
if tests_launcher.list_tests() == -1: if tests_launcher.list_tests() == -1:
printc("\nFailling as tests have been removed/added " printc("\nFailling as tests have been removed/added "
" (--fail-on-testlist-change)", Colors.FAIL) " (--fail-on-testlist-change)", Colors.FAIL)
exit(1) return 1
tests = tests_launcher.tests tests = tests_launcher.tests
for test in tests: for test in tests: