diff mbox series

[RFC,1/6] patchtest: use logger instead of printing to stdout

Message ID 20250203-b4-patchtest-v1-1-ef6ee5fcdd78@cherry.de
State New
Headers show
Series prepare patchtest to be run with b4 prep --check | expand

Commit Message

Quentin Schulz Feb. 3, 2025, 4 p.m. UTC
From: Quentin Schulz <quentin.schulz@cherry.de>

This will allow use to specify which messages we want to see later on.
This will be useful for using this script with b4 for example which
expects output on stdout/stderr only when an error happened.

To that end, success string is set to the info level, warning string to
warning level and error to error level.

The summary is printed with the appropriate log level, error if warnings
or errors were found, info otherwise.

Signed-off-by: Quentin Schulz <quentin.schulz@cherry.de>
---
 scripts/patchtest | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/scripts/patchtest b/scripts/patchtest
index 9218db232a77516d2a8bdcd967521b884f0de89d..bcd48dbcc39573d7abd3247bc34cb9ac8a8a5c2e 100755
--- a/scripts/patchtest
+++ b/scripts/patchtest
@@ -82,7 +82,7 @@  def getResult(patch, mergepatch, logfile=None):
             fail_str = '{}: {}: {} ({})'.format(self.fail,
             test_description, json.loads(str(err[1]))["issue"],
             test.id())
-            print(fail_str)
+            logger.error(fail_str)
             if logfile:
                 with open(logfile, "a") as f:
                     f.write(fail_str + "\n")
@@ -94,7 +94,7 @@  def getResult(patch, mergepatch, logfile=None):
             "non-AUH").replace("presence format", "presence")
             success_str = '{}: {} ({})'.format(self.success,
             test_description, test.id())
-            print(success_str)
+            logger.info(success_str)
             if logfile:
                 with open(logfile, "a") as f:
                     f.write(success_str + "\n")
@@ -107,7 +107,7 @@  def getResult(patch, mergepatch, logfile=None):
             skip_str = '{}: {}: {} ({})'.format(self.skip,
             test_description, json.loads(str(reason))["issue"],
             test.id())
-            print(skip_str)
+            logger.warning(skip_str)
             if logfile:
                 with open(logfile, "a") as f:
                     f.write(skip_str + "\n")
@@ -169,18 +169,22 @@  def run(patch, logfile=None):
     return premerge_result or postmerge_result
 
 def print_result_message(preresult, postresult):
-    print("----------------------------------------------------------------------\n")
     if preresult == 2 and postresult == 2:
+        logger.error("----------------------------------------------------------------------\n")
         logger.error(
             "patchtest: No test cases found - did you specify the correct suite directory?"
         )
+        logger.error("----------------------------------------------------------------------\n")
     if preresult == 1 or postresult == 1:
+        logger.error("----------------------------------------------------------------------\n")
         logger.error(
             "WARNING: patchtest: At least one patchtest caused a failure or an error - please check https://wiki.yoctoproject.org/wiki/Patchtest for further guidance"
         )
+        logger.error("----------------------------------------------------------------------\n")
     else:
+        logger.info("----------------------------------------------------------------------\n")
         logger.info("OK: patchtest: All patchtests passed")
-    print("----------------------------------------------------------------------\n")
+        logger.info("----------------------------------------------------------------------\n")
 
 def main():
     tmp_patch = False