diff mbox series

[1/3] patchtest: add --error-on-failure option

Message ID 20260318161209.54396-1-naftaly.ralamboarivony@smile.fr
State Under Review
Headers show
Series [1/3] patchtest: add --error-on-failure option | expand

Commit Message

naftaly.ralamboarivony@smile.fr March 18, 2026, 4:12 p.m. UTC
From: Naftaly RALAMBOARIVONY <naftaly.ralamboarivony@smile.fr>

Add a command line option to make patchtest return a non-zero exit
status when a test fails.

This keeps the current default behavior unchanged while allowing calling
scripts and shells to detect test failures through the process exit
status when explicitly requested.

Signed-off-by: Naftaly RALAMBOARIVONY <naftaly.ralamboarivony@smile.fr>
---
 meta/lib/patchtest/patchtest_parser.py | 3 +++
 scripts/patchtest                      | 8 ++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/meta/lib/patchtest/patchtest_parser.py b/meta/lib/patchtest/patchtest_parser.py
index 2a11cb76c2..ba5a171e27 100644
--- a/meta/lib/patchtest/patchtest_parser.py
+++ b/meta/lib/patchtest/patchtest_parser.py
@@ -73,6 +73,9 @@  class PatchtestParser(object):
                             action='store_true', 
                             help='Enable logging to a file matching the target patch name with ".testresult" appended')
 
+        parser.add_argument('--error-on-failure',
+                            action='store_true',
+                            help='Return non-zero exit status if a test fails')
 
         return parser
 
diff --git a/scripts/patchtest b/scripts/patchtest
index 9218db232a..653f2b217a 100755
--- a/scripts/patchtest
+++ b/scripts/patchtest
@@ -183,6 +183,7 @@  def print_result_message(preresult, postresult):
     print("----------------------------------------------------------------------\n")
 
 def main():
+    ret = 0
     tmp_patch = False
     patch_path = PatchtestParser.patch_path
     log_results = PatchtestParser.log_results
@@ -214,13 +215,16 @@  def main():
 
         try:
             if log_path:
-                run(patch, log_path)
+                ret = run(patch, log_path)
             else:
-                run(patch)
+                ret = run(patch)
         finally:
             if tmp_patch:
                 os.remove(patch)
 
+        if PatchtestParser.error_on_failure and ret != 0:
+            return ret
+
 if __name__ == '__main__':
     ret = 1