This patch adds support to the piglit.conf to add a default backend. If the config is empty and it is not set then 'json' will be returned (the standard piglit json backend everyone knows and hates).
Signed-off-by: Dylan Baker <[email protected]> --- framework/programs/run.py | 22 ++++++++- framework/tests/run_parser_tests.py | 98 ++++++++++++++++++++++++++++++------- piglit.conf.example | 7 ++- 3 files changed, 107 insertions(+), 20 deletions(-) diff --git a/framework/programs/run.py b/framework/programs/run.py index 82fc797..9a6276f 100644 --- a/framework/programs/run.py +++ b/framework/programs/run.py @@ -37,6 +37,7 @@ __all__ = ['run', _PLATFORMS = ["glx", "x11_egl", "wayland", "gbm", "mixed_glx_egl"] +_BACKENDS = ['json', 'junit'] def _default_platform(): @@ -70,6 +71,25 @@ def _default_platform(): return 'mixed_glx_egl' +def _default_backend(): + """ Logic to se the default backend to use + + There are two options, either the one set via the -b/--backend option, or + the one in the config file. The default if that fails is to use json + + """ + try: + backend = core.PIGLIT_CONFIG.get('core', 'backend') + if backend not in _BACKENDS: + print('Backend is not valid\n', + 'valid backends are: {}'.format(' '.join(_BACKENDS)), + file=sys.stderr) + sys.exit(1) + return backend + except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): + return 'json' + + def _run_parser(input_): """ Parser for piglit run command """ # Parse the config file before any other options, this allows the config @@ -109,7 +129,7 @@ def _run_parser(input_): help="Exclude matching tests " "(can be used more than once)") parser.add_argument('-b', '--backend', - default='json', + default=_default_backend(), choices=framework.results.BACKENDS, help='select a results backend to use') conc_parser = parser.add_mutually_exclusive_group() diff --git a/framework/tests/run_parser_tests.py b/framework/tests/run_parser_tests.py index 07d4750..d355bb2 100644 --- a/framework/tests/run_parser_tests.py +++ b/framework/tests/run_parser_tests.py @@ -30,16 +30,14 @@ import framework.programs.run as run import framework.core as core -class TestPlatform(utils.TestWithEnvClean): - """ Test piglitrun -p/--platform options """ - _CONF = '[core]\nplatform=gbm' - - def __unset_config(self): +class _Helpers(utils.TestWithEnvClean): + """ Some helpers to be shared between tests """ + def _unset_config(self): """ Ensure that no config files are being accidently loaded """ self.add_teardown('HOME') self.add_teardown('XDG_CONFIG_HOME') - def __move_piglit_conf(self): + def _move_piglit_conf(self): """ Move piglit.conf from local and from piglit root They are moved and put back so they aren't accidentally loaded @@ -54,19 +52,83 @@ class TestPlatform(utils.TestWithEnvClean): shutil.move(root, root + '.restore') self.defer(shutil.move, root + '.restore', root) + def setup(self): + # Set core.PIGLIT_CONFIG back to pristine between tests + core.PIGLIT_CONFIG = ConfigParser.SafeConfigParser() + + +class TestBackend(_Helpers): + """ Test piglit run -b/--backend option """ + _CONF = '[core]\nbackend=junit' + + def test_default(self): + """ run parser: backend final fallback path """ + self._unset_config() + self._move_piglit_conf() + + args = run._run_parser(['quick.py', 'foo']) + nt.assert_equal(args.backend, 'json') + + def test_option_default(self): + """ Run parser: backend replaces default """ + args = run._run_parser(['-b', 'json', 'quick.py', 'foo']) + nt.assert_equal(args.backend, 'json') + + def test_option_conf(self): + """ Run parser: backend option replaces conf """ + with utils.tempdir() as tdir: + os.environ['XDG_CONFIG_HOME'] = tdir + with open(os.path.join(tdir, 'piglit.conf'), 'w') as f: + f.write(self._CONF) + + args = run._run_parser(['-b', 'json', 'quick.py', 'foo']) + nt.assert_equal(args.backend, 'json') + + def test_conf_default(self): + """ Run parser platform: conf is used as a default when applicable """ + self._unset_config() + self._move_piglit_conf() + + with utils.tempdir() as tdir: + os.environ['XDG_CONFIG_HOME'] = tdir + with open(os.path.join(tdir, 'piglit.conf'), 'w') as f: + f.write(self._CONF) + + args = run._run_parser(['quick.py', 'foo']) + nt.assert_equal(args.backend, 'junit') + + @nt.raises(SystemExit) + def test_bad_value_in_conf(self): + """ run parser: an error is raised when the platform in conf is bad """ + self._unset_config() + self._move_piglit_conf() + + # This has sideffects, it shouldn't effect anything in this module, but + # it may cause later problems. But without this we get ugly error spew + # from this test. + sys.stderr = open(os.devnull, 'w') + + with utils.tempdir() as tdir: + with open(os.path.join(tdir, 'piglit.conf'), 'w') as f: + f.write('[core]\nbackend=foobar') + + run._run_parser(['-f', os.path.join(tdir, 'piglit.conf'), + 'quick.py', 'foo']) + + +class TestPlatform(_Helpers): + """ Test piglitrun -p/--platform options """ + _CONF = '[core]\nplatform=gbm' + def __set_env(self): """ Set PIGLIT_PLATFORM """ self.add_teardown('PIGLIT_PLATFORM') os.environ['PIGLIT_PLATFORM'] = 'glx' - def setup(self): - # Set core.PIGLIT_CONFIG back to pristine between tests - core.PIGLIT_CONFIG = ConfigParser.SafeConfigParser() - def test_default(self): """ run parser: platform final fallback path """ - self.__unset_config() - self.__move_piglit_conf() + self._unset_config() + self._move_piglit_conf() args = run._run_parser(['quick.py', 'foo']) nt.assert_equal(args.platform, 'mixed_glx_egl') @@ -103,8 +165,8 @@ class TestPlatform(utils.TestWithEnvClean): def test_conf_default(self): """ Run parser platform: conf is used as a default when applicable """ - self.__unset_config() - self.__move_piglit_conf() + self._unset_config() + self._move_piglit_conf() with utils.tempdir() as tdir: os.environ['XDG_CONFIG_HOME'] = tdir @@ -116,8 +178,8 @@ class TestPlatform(utils.TestWithEnvClean): def test_env_conf(self): """ Run parser: env overwrides a conf value """ - self.__unset_config() - self.__move_piglit_conf() + self._unset_config() + self._move_piglit_conf() self.__set_env() with utils.tempdir() as tdir: @@ -131,8 +193,8 @@ class TestPlatform(utils.TestWithEnvClean): @nt.raises(SystemExit) def test_bad_value_in_conf(self): """ run parser: an error is raised when the platform in conf is bad """ - self.__unset_config() - self.__move_piglit_conf() + self._unset_config() + self._move_piglit_conf() # This has sideffects, it shouldn't effect anything in this module, but # it may cause later problems. But without this we get ugly error spew diff --git a/piglit.conf.example b/piglit.conf.example index 3844bd0..e7a2101 100644 --- a/piglit.conf.example +++ b/piglit.conf.example @@ -51,8 +51,13 @@ run_test=./%(test_name)s [core] ; Set the default platform to use. -; Options can be found by running piglit -h and reading the section +; Options can be found by running piglit run -h and reading the section ; for -p/--platform ; ; The default on Linux will be mixed_glx_egl ;platform=gbm + +; Set the default backend to use +; Options can be found running piglit run -h and reading the section for +; -b/--backend +;backend=json -- 2.1.0 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
