Openembedded Core Discussions
 help / color / mirror / Atom feed
From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: Yeoh Ee Peng <ee.peng.yeoh@intel.com>,
	openembedded-core@lists.openembedded.org
Subject: Re: [PATCH 1/4] oeqa/core/runner: write testresult to json files
Date: Mon, 22 Oct 2018 23:54:07 +0100	[thread overview]
Message-ID: <e222c50a97c8b1b555cac324659e723b49b28413.camel@linuxfoundation.org> (raw)
In-Reply-To: <1540204485-22641-1-git-send-email-ee.peng.yeoh@intel.com>

On Mon, 2018-10-22 at 18:34 +0800, Yeoh Ee Peng wrote:
> As part of the solution to replace Testopia to store testresult,
> OEQA need to output testresult into single json file, where json
> testresult file will be stored in git repository by the future
> test-case-management tools.
> 
> The json testresult file will store more than one set of results,
> where each set of results was uniquely identified by the result_id.
> The result_id would be like "runtime-qemux86-core-image-sato", where
> it was a runtime test with target machine equal to qemux86 and running
> on core-image-sato image. The json testresult file will only store
> the latest test content for a given result_id. The json testresult
> file contains the configuration (eg. COMMIT, BRANCH, MACHINE, IMAGE),
> result (eg. PASSED, FAILED, ERROR), test log, and result_id.
> 
> Based on the destination json testresult file directory provided,
> it could have multiple instances of bitbake trying to write json
> testresult to a single testresult file, using locking a lockfile
> alongside the results file directory to prevent races.
> 
> Also the library class inside this patch will be reused by the future
> test-case-management tools to write json testresult for manual test
> case executed.
> 
> Signed-off-by: Yeoh Ee Peng <ee.peng.yeoh@intel.com>
> ---
>  meta/lib/oeqa/core/runner.py | 39 ++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 38 insertions(+), 1 deletion(-)
> 
> diff --git a/meta/lib/oeqa/core/runner.py b/meta/lib/oeqa/core/runner.py
> index f1dd080..2243a10 100644
> --- a/meta/lib/oeqa/core/runner.py
> +++ b/meta/lib/oeqa/core/runner.py
> @@ -6,6 +6,7 @@ import time
>  import unittest
>  import logging
>  import re
> +import json
>  
>  from unittest import TextTestResult as _TestResult
>  from unittest import TextTestRunner as _TestRunner
> @@ -119,8 +120,9 @@ class OETestResult(_TestResult):
>          self.successes.append((test, None))
>          super(OETestResult, self).addSuccess(test)
>  
> -    def logDetails(self):
> +    def logDetails(self, json_file_dir=None, configuration=None, result_id=None):
>          self.tc.logger.info("RESULTS:")
> +        result = {}
>          for case_name in self.tc._registry['cases']:
>              case = self.tc._registry['cases'][case_name]
>  
> @@ -137,6 +139,11 @@ class OETestResult(_TestResult):
>                  t = " (" + "{0:.2f}".format(self.endtime[case.id()] - self.starttime[case.id()]) + "s)"
>  
>              self.tc.logger.info("RESULTS - %s - Testcase %s: %s%s" % (case.id(), oeid, status, t))
> +            result[case.id()] = {'status': status, 'log': log}
> +
> +        if json_file_dir:
> +            tresultjsonhelper = OETestResultJSONHelper()
> +            tresultjsonhelper.dump_testresult_file(result_id, result, configuration, json_file_dir)
>  
>  class OEListTestsResult(object):
>      def wasSuccessful(self):
> @@ -249,3 +256,33 @@ class OETestRunner(_TestRunner):
>              self._list_tests_module(suite)
>  
>          return OEListTestsResult()
> +
> +class OETestResultJSONHelper(object):
> +
> +    testresult_filename = 'testresults.json'
> +
> +    def _get_existing_testresults_if_available(self, write_dir):
> +        testresults = {}
> +        file = os.path.join(write_dir, self.testresult_filename)
> +        if os.path.exists(file):
> +            with open(file, "r") as f:
> +                testresults = json.load(f)
> +        return testresults
> +
> +    def _create_json_testresults_string(self, test_results, result_id, test_result, configuration):
> +        test_results[result_id] = {'configuration': configuration, 'result': test_result}
> +        return json.dumps(test_results, sort_keys=True, indent=4)

I think the above function can be removed as its no longer used
anywhere.

I've queued these patches for testing on the main autobuilder as I
think we're close and wanted to check it doesn't show issues. I still
wonder if we couldn't write out the files to a specific directory more
reliably but I think I'd need to look at the code for longer to come up
with any proposal. Right now I guess we can at least configure the
autobuilder to put the files in a common location (so it can collect
them up).

Cheers,

Richard

> +    def _write_file(self, write_dir, file_name, file_content):
> +        file_path = os.path.join(write_dir, file_name)
> +        with open(file_path, 'w') as the_file:
> +            the_file.write(file_content)
> +
> +    def dump_testresult_file(self, result_id, test_result, configuration, write_dir):
> +        bb.utils.mkdirhier(write_dir)
> +        lf = bb.utils.lockfile(os.path.join(write_dir, 'jsontestresult.lock'))
> +        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)
> -- 
> 2.7.4
> 



  parent reply	other threads:[~2018-10-22 22:54 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-22 10:34 [PATCH 1/4] oeqa/core/runner: write testresult to json files Yeoh Ee Peng
2018-10-22 10:34 ` [PATCH 2/4] oeqa/selftest/context: " Yeoh Ee Peng
2018-10-22 10:34 ` [PATCH 3/4] testimage.bbclass: " Yeoh Ee Peng
2018-10-22 10:34 ` [PATCH 4/4] testsdk.bbclass: " Yeoh Ee Peng
2018-10-22 22:54 ` Richard Purdie [this message]
2018-10-23  6:39   ` [PATCH 1/4] oeqa/core/runner: " Yeoh, Ee Peng
2018-10-29 10:44     ` richard.purdie
2018-10-29 13:58       ` Richard Purdie
2018-10-30  8:55         ` Yeoh, Ee Peng
  -- strict thread matches above, loose matches on Subject: below --
2018-10-23  5:57 Yeoh Ee Peng
2018-10-22  6:54 Yeoh Ee Peng
2018-10-22  8:31 ` Richard Purdie
2018-10-22  8:59   ` Yeoh, Ee Peng
2018-10-22  9:34     ` richard.purdie
2018-10-22  9:47       ` Yeoh, Ee Peng
2018-10-22 10:53       ` Yeoh, Ee Peng
2018-10-12  6:33 Yeoh Ee Peng
2018-10-12 15:00 ` Richard Purdie
2018-10-15  8:42   ` Yeoh, Ee Peng
2018-10-15  8:59     ` richard.purdie
2018-10-15 10:00       ` Yeoh, Ee Peng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e222c50a97c8b1b555cac324659e723b49b28413.camel@linuxfoundation.org \
    --to=richard.purdie@linuxfoundation.org \
    --cc=ee.peng.yeoh@intel.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox