Chrome platform driver development
 help / color / mirror / Atom feed
From: Tzung-Bi Shih <tzungbi@kernel.org>
To: bleung@chromium.org, groeck@chromium.org
Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org,
	guillaume.tucker@collabora.com, denys.f@collabora.com,
	ricardo.canuelo@collabora.com
Subject: [PATCH 03/14] lava_runner: use TextTestResult
Date: Mon, 13 Mar 2023 17:44:20 +0800	[thread overview]
Message-ID: <20230313094431.507952-4-tzungbi@kernel.org> (raw)
In-Reply-To: <20230313094431.507952-1-tzungbi@kernel.org>

To simplify, make LavaTestResult is-a TextTestResult.

As a side-effect result, it prints errors and fails by the end of test
running.  See [1].

[1]: https://github.com/python/cpython/blob/main/Lib/unittest/runner.py#L139

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
 cros/runners/lava_runner.py | 44 +++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 24 deletions(-)

diff --git a/cros/runners/lava_runner.py b/cros/runners/lava_runner.py
index 7524f65dcd39..70f8aa61132e 100755
--- a/cros/runners/lava_runner.py
+++ b/cros/runners/lava_runner.py
@@ -13,38 +13,34 @@ from cros.tests.cros_ec_power import *
 from cros.tests.cros_ec_extcon import *
 
 
-class LavaTestResult(unittest.TestResult):
-    def __init__(self, stream, descriptions, verbosity):
-        unittest.TestResult.__init__(self)
-        self.stream = stream
+class LavaTestResult(unittest.TextTestResult):
+    def writeLavaSignal(self, test, result):
+        test_case_id = test.id().rsplit(".")[-1]
 
-    def addSuccess(self, test):
-        unittest.TestResult.addSuccess(self, test)
-        self.stream.write(
-            "<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=%s RESULT=pass>\n"
-            % test.id().rsplit(".")[-1]
+        # LAVA signal must be start-of-line.  Print a newline if verbosity >= 1.
+        if self.showAll or self.dots:
+            self.stream.writeln()
+
+        self.stream.writeln(
+            f"<LAVA_SIGNAL_TESTCASE TEST_CASE_ID={test_case_id} RESULT={result}>"
         )
+        self.stream.flush()
+
+    def addSuccess(self, test):
+        super().addSuccess(test)
+        self.writeLavaSignal(test, "pass")
 
     def addError(self, test, err):
-        unittest.TestResult.addError(self, test, err)
-        self.stream.write(
-            "<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=%s RESULT=unknown>\n"
-            % test.id().rsplit(".")[-1]
-        )
+        super().addError(test, err)
+        self.writeLavaSignal(test, "unknown")
 
     def addFailure(self, test, err):
-        unittest.TestResult.addFailure(self, test, err)
-        self.stream.write(
-            "<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=%s RESULT=fail>\n"
-            % test.id().rsplit(".")[-1]
-        )
+        super().addFailure(test, err)
+        self.writeLavaSignal(test, "fail")
 
     def addSkip(self, test, reason):
-        unittest.TestResult.addSkip(self, test, reason)
-        self.stream.write(
-            "<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=%s RESULT=skip>\n"
-            % test.id().rsplit(".")[-1]
-        )
+        super().addSkip(test, reason)
+        self.writeLavaSignal(test, "skip")
 
 
 if __name__ == "__main__":
-- 
2.40.0.rc1.284.g88254d51c5-goog


  parent reply	other threads:[~2023-03-13  9:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-13  9:44 [PATCH 00/14] cros-ec-tests: fix some exceptions and clean-ups Tzung-Bi Shih
2023-03-13  9:44 ` [PATCH 01/14] lava_runner: rename to LavaTestResult Tzung-Bi Shih
2023-03-13  9:44 ` [PATCH 02/14] lava_runner: use TextTestRunner Tzung-Bi Shih
2023-03-13  9:44 ` Tzung-Bi Shih [this message]
2023-03-13  9:44 ` [PATCH 04/14] lava_runner: respect to verbosity flag from unittest framework Tzung-Bi Shih
2023-03-13  9:44 ` [PATCH 05/14] helpers/sysfs: fix NameError Tzung-Bi Shih
2023-03-13  9:44 ` [PATCH 06/14] helpers/mcu: fix ResourceWarning on /dev/cros_ec Tzung-Bi Shih
2023-03-13  9:44 ` [PATCH 07/14] cros_ec_pwm: fix ResourceWarning on /sys/kernel/debug/pwm Tzung-Bi Shih
2023-03-13  9:44 ` [PATCH 08/14] treewide: use context manager on file objects Tzung-Bi Shih
2023-03-13  9:44 ` [PATCH 09/14] cros_ec_pwm: use RE to search EC backlight PWM Tzung-Bi Shih
2023-03-13  9:44 ` [PATCH 10/14] helpers/mcu: fix packet too long error Tzung-Bi Shih
2023-03-13  9:44 ` [PATCH 11/14] helpers/mcu: fix EC_CMD_GET_FEATURES usage Tzung-Bi Shih
2023-03-13  9:44 ` [PATCH 12/14] treewide: remove "r" in open() if reading mode Tzung-Bi Shih
2023-03-13  9:44 ` [PATCH 13/14] treewide: don't use "+" operator for constructing paths Tzung-Bi Shih
2023-03-13  9:44 ` [PATCH 14/14] treewide: don't use "+" operator for concatenating strings Tzung-Bi Shih
2023-03-13 11:53 ` [PATCH 00/14] cros-ec-tests: fix some exceptions and clean-ups Ricardo Cañuelo
2023-03-14  3:09   ` Tzung-Bi Shih
2023-03-14  6:47     ` Guillaume Charles Tucker

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=20230313094431.507952-4-tzungbi@kernel.org \
    --to=tzungbi@kernel.org \
    --cc=bleung@chromium.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=denys.f@collabora.com \
    --cc=groeck@chromium.org \
    --cc=guillaume.tucker@collabora.com \
    --cc=ricardo.canuelo@collabora.com \
    /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