All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] oeqa: enable testresults.json for testexport
@ 2020-03-11 16:37 Stefan Kral
  2020-03-11 17:22 ` Richard Purdie
  2020-03-12  9:12 ` Richard Purdie
  0 siblings, 2 replies; 7+ messages in thread
From: Stefan Kral @ 2020-03-11 16:37 UTC (permalink / raw)
  To: openembedded-core; +Cc: Stefan Kral

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@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)
+        except ImportError:
+            has_bb = False
+            os.makedirs(write_dir)
         test_results = self._get_existing_testresults_if_available(write_dir)
         test_results[result_id] = {'configuration': configuration, 'result': test_result}
         json_testresults = json.dumps(test_results, sort_keys=True, indent=4)
         self._write_file(write_dir, self.testresult_filename, json_testresults)
-        bb.utils.unlockfile(lf)
+        if has_bb:
+            bb.utils.unlockfile(lf)
-- 
2.17.2 (Apple Git-113)



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] oeqa: enable testresults.json for testexport
  2020-03-11 16:37 [PATCH] oeqa: enable testresults.json for testexport Stefan Kral
@ 2020-03-11 17:22 ` Richard Purdie
  2020-03-11 20:38   ` Stefan Kral
  2020-03-12  9:12 ` Richard Purdie
  1 sibling, 1 reply; 7+ messages in thread
From: Richard Purdie @ 2020-03-11 17:22 UTC (permalink / raw)
  To: Stefan Kral, openembedded-core

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@typedivision.de>

Out of interest are you actively using testexport? I've been wondering
if we should remove that support as it does complicate the code a lot
and ironically, isn't well tested.

Cheers,

Richard



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] oeqa: enable testresults.json for testexport
  2020-03-11 17:22 ` Richard Purdie
@ 2020-03-11 20:38   ` Stefan Kral
  2020-03-11 20:46     ` Alexander Kanavin
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Kral @ 2020-03-11 20:38 UTC (permalink / raw)
  To: Richard Purdie, openembedded-core

Hi Richard,

I just started to evaluate the use of testexport.

If you think about removing that feature, what is the preferred way to 
test a deployed target image?
The idea here is to have two separate pipelines:

1. build
- a target-image-test (same as target-image but additional test 
facilities enabled, like ptest)
- the testexport output

2. test
- fetch build results and install the target-image-test to the real hardware
- run the exported runtime tests (host and target based cases)
- check/save the generated testresults.json

BR
Stefan

Am 11.03.20 um 18:22 schrieb Richard Purdie:
> 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@typedivision.de>
> Out of interest are you actively using testexport? I've been wondering
> if we should remove that support as it does complicate the code a lot
> and ironically, isn't well tested.
>
> Cheers,
>
> Richard
>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] oeqa: enable testresults.json for testexport
  2020-03-11 20:38   ` Stefan Kral
@ 2020-03-11 20:46     ` Alexander Kanavin
  2020-03-11 21:27       ` Stefan Kral
  0 siblings, 1 reply; 7+ messages in thread
From: Alexander Kanavin @ 2020-03-11 20:46 UTC (permalink / raw)
  To: Stefan Kral; +Cc: OE-core

[-- Attachment #1: Type: text/plain, Size: 960 bytes --]

On Wed, 11 Mar 2020 at 21:38, Stefan Kral <sk@typedivision.de> wrote:

> I just started to evaluate the use of testexport.
>
> If you think about removing that feature, what is the preferred way to
> test a deployed target image?
> The idea here is to have two separate pipelines:
>
> 1. build
> - a target-image-test (same as target-image but additional test
> facilities enabled, like ptest)
> - the testexport output
>
> 2. test
> - fetch build results and install the target-image-test to the real
> hardware
> - run the exported runtime tests (host and target based cases)
> - check/save the generated testresults.json
>

You can do all of these in a single pipeline using testimage:

1. built target-image-test
2. flash target-image-test to real hardware
3. bitbake -c testimage target-image-test (set TEST_TARGET to
'simpleremote', and ip/port for ssh access in local.conf)

Is there a reason you need two pipelines?

Alex

[-- Attachment #2: Type: text/html, Size: 1359 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] oeqa: enable testresults.json for testexport
  2020-03-11 20:46     ` Alexander Kanavin
@ 2020-03-11 21:27       ` Stefan Kral
  2020-03-12  8:23         ` Alexander Kanavin
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Kral @ 2020-03-11 21:27 UTC (permalink / raw)
  To: Alexander Kanavin; +Cc: OE-core

[-- Attachment #1: Type: text/plain, Size: 1888 bytes --]

Am 11.03.20 um 21:46 schrieb Alexander Kanavin:
> On Wed, 11 Mar 2020 at 21:38, Stefan Kral <sk@typedivision.de 
> <mailto:sk@typedivision.de>> wrote:
>
>     I just started to evaluate the use of testexport.
>
>     If you think about removing that feature, what is the preferred
>     way to
>     test a deployed target image?
>     The idea here is to have two separate pipelines:
>
>     1. build
>     - a target-image-test (same as target-image but additional test
>     facilities enabled, like ptest)
>     - the testexport output
>
>     2. test
>     - fetch build results and install the target-image-test to the
>     real hardware
>     - run the exported runtime tests (host and target based cases)
>     - check/save the generated testresults.json
>
>
> You can do all of these in a single pipeline using testimage:
>
> 1. built target-image-test
> 2. flash target-image-test to real hardware
> 3. bitbake -c testimage target-image-test (set TEST_TARGET to 
> 'simpleremote', and ip/port for ssh access in local.conf)
>
> Is there a reason you need two pipelines?
>
> Alex

Doing build and test in one pipeline turns out to be more complicated 
due to:

- build machine may be different from test machine (with access to hardware)
- build the image is a one time job, tests may have to be repeated 
reproducibly
- executing long running tests slows down image creation (for development)
- tests on dedicated hardware should be runable asynchronously when hw 
is available

Running tests by bitbake -c testimage could be an option but to provide 
a full repo/bitbake/cache setup to run test cases sounds not as easy as 
having just python installed. And for that, testexport does its job 
quite well.

Btw. have you ever thought about to integrate/support some external test 
framework (like robot framework)?

Stefan


[-- Attachment #2: Type: text/html, Size: 3312 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] oeqa: enable testresults.json for testexport
  2020-03-11 21:27       ` Stefan Kral
@ 2020-03-12  8:23         ` Alexander Kanavin
  0 siblings, 0 replies; 7+ messages in thread
From: Alexander Kanavin @ 2020-03-12  8:23 UTC (permalink / raw)
  To: Stefan Kral; +Cc: OE-core

[-- Attachment #1: Type: text/plain, Size: 1076 bytes --]

On Wed, 11 Mar 2020 at 22:27, Stefan Kral <sk@typedivision.de> wrote:

> Doing build and test in one pipeline turns out to be more complicated due
> to:
>
> - build machine may be different from test machine (with access to
> hardware)
> - build the image is a one time job, tests may have to be repeated
> reproducibly
> - executing long running tests slows down image creation (for development)
> - tests on dedicated hardware should be runable asynchronously when hw is
> available
>
> Running tests by bitbake -c testimage could be an option but to provide a
> full repo/bitbake/cache setup to run test cases sounds not as easy as
> having just python installed. And for that, testexport does its job quite
> well.
>
> Btw. have you ever thought about to integrate/support some external test
> framework (like robot framework)?
>

Core project does all testing on qemu (using direct testimage); there are
no resources to set up testing on real hardware. So those scenarios aren't
well supported or tested, but patches/proposals welcome :)

Alex

[-- Attachment #2: Type: text/html, Size: 1498 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] oeqa: enable testresults.json for testexport
  2020-03-11 16:37 [PATCH] oeqa: enable testresults.json for testexport Stefan Kral
  2020-03-11 17:22 ` Richard Purdie
@ 2020-03-12  9:12 ` Richard Purdie
  1 sibling, 0 replies; 7+ messages in thread
From: Richard Purdie @ 2020-03-12  9:12 UTC (permalink / raw)
  To: Stefan Kral, openembedded-core

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@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



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-03-12  9:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11 16:37 [PATCH] oeqa: enable testresults.json for testexport Stefan Kral
2020-03-11 17:22 ` Richard Purdie
2020-03-11 20:38   ` Stefan Kral
2020-03-11 20:46     ` Alexander Kanavin
2020-03-11 21:27       ` Stefan Kral
2020-03-12  8:23         ` Alexander Kanavin
2020-03-12  9:12 ` Richard Purdie

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.