[OE-core] [PATCH] oeqa: enable testresults.json for testexport

Richard Purdie richard.purdie at linuxfoundation.org
Thu Mar 12 09:12:08 UTC 2020


On Wed, 2020-03-11 at 17:37 +0100, Stefan Kral wrote:
> Add the option --json-result-dir to oeqa core context to enable
> testresults.json creation for test runs via testexport.
> 
> Eg. oe-test runtime --json-result-dir .
> 
> Signed-off-by: Stefan Kral <sk at typedivision.de>
> ---
>  meta/lib/oeqa/core/context.py | 30 +++++++++++++++++++++++++++++-
>  meta/lib/oeqa/core/runner.py  | 13 ++++++++++---
>  2 files changed, 39 insertions(+), 4 deletions(-)
> 
> diff --git a/meta/lib/oeqa/core/context.py b/meta/lib/oeqa/core/context.py
> index 16320af115..b9a28ce319 100644
> --- a/meta/lib/oeqa/core/context.py
> +++ b/meta/lib/oeqa/core/context.py
> @@ -116,6 +116,9 @@ class OETestContextExecutor(object):
>                  default=self.default_output_log,
>                  help="results output log, default: %s" % self.default_output_log)
>  
> +        self.parser.add_argument('--json-result-dir', action='store',
> +                help="json result output dir, create testresults.json here if set")
> +
>          group = self.parser.add_mutually_exclusive_group()
>          group.add_argument('--run-tests', action='store', nargs='+',
>                  default=self.default_tests,
> @@ -178,6 +181,22 @@ class OETestContextExecutor(object):
>  
>          self.module_paths = args.CASES_PATHS
>  
> +    def _get_json_result_dir(self, args):
> +        return args.json_result_dir
> +
> +    def _get_configuration(self):
> +        td = self.tc_kwargs['init']['td']
> +        configuration = {'TEST_TYPE': self.name,
> +                        'MACHINE': td.get("MACHINE"),
> +                        'DISTRO': td.get("DISTRO"),
> +                        'IMAGE_BASENAME': td.get("IMAGE_BASENAME"),
> +                        'DATETIME': td.get("DATETIME")}
> +        return configuration
> +
> +    def _get_result_id(self, configuration):
> +        return '%s_%s_%s_%s' % (configuration['TEST_TYPE'], configuration['IMAGE_BASENAME'],
> +                                configuration['MACHINE'], configuration['DATETIME'])
> +
>      def _pre_run(self):
>          pass
>  
> @@ -196,7 +215,16 @@ class OETestContextExecutor(object):
>          else:
>              self._pre_run()
>              rc = self.tc.runTests(**self.tc_kwargs['run'])
> -            rc.logDetails()
> +
> +            json_result_dir = self._get_json_result_dir(args)
> +            if json_result_dir:
> +                configuration = self._get_configuration()
> +                rc.logDetails(json_result_dir,
> +                              configuration,
> +                              self._get_result_id(configuration))
> +            else:
> +                rc.logDetails()
> +
>              rc.logSummary(self.name)
>  
>          output_link = os.path.join(os.path.dirname(args.output_log),
> diff --git a/meta/lib/oeqa/core/runner.py b/meta/lib/oeqa/core/runner.py
> index f656e1a9c5..fc3872aa73 100644
> --- a/meta/lib/oeqa/core/runner.py
> +++ b/meta/lib/oeqa/core/runner.py
> @@ -319,10 +319,17 @@ class OETestResultJSONHelper(object):
>              the_file.write(file_content)
>  
>      def dump_testresult_file(self, write_dir, configuration, result_id, test_result):
> -        bb.utils.mkdirhier(write_dir)
> -        lf = bb.utils.lockfile(os.path.join(write_dir, 'jsontestresult.lock'))
> +        try:
> +            import bb
> +            has_bb = True
> +            lf = bb.utils.lockfile(os.path.join(write_dir, 'jsontestresult.lock'))
> +            bb.utils.mkdirhier(write_dir, exist_ok=True)

This threw errors under testing since mkdirhier doesn't have an
exist_ok parameter. The ordering is also reversed, we should mkdir,
then lock.

> +        except ImportError:
> +            has_bb = False
> +            os.makedirs(write_dir)

I suspect the parameter was meant to go here. 

I've added a fix to -next for this.

Cheers,

Richard



More information about the Openembedded-core mailing list