From: Naftaly RALAMBOARIVONY <[email protected]>

Add a test case to verify that patchtest --error-on-failure
returns the correct exit code for PASS,FAIL and SKIP scenarios.

Signed-off-by: Naftaly RALAMBOARIVONY <[email protected]>
---
 meta/lib/patchtest/selftest/selftest | 37 ++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/meta/lib/patchtest/selftest/selftest 
b/meta/lib/patchtest/selftest/selftest
index 51681bec38..39114a45a0 100755
--- a/meta/lib/patchtest/selftest/selftest
+++ b/meta/lib/patchtest/selftest/selftest
@@ -142,6 +142,42 @@ def test(root, patch, extra_args=None):
 
     return results
 
+def test_error_on_failure(root, patch):
+    try:
+        output = test(root, patch, "--error-on-failure")
+        return output, 0
+    except subprocess.CalledProcessError as e:
+        return e.output, e.returncode
+
+def test_returncode(patches, counts):
+
+    for target in ("FAIL", "PASS", "SKIP"):
+        for patch_info in patches:
+
+            testid = patch_info["testid"]
+            expected = str(patch_info["expected"]).upper()
+
+            if expected == target:
+                results, returncode = test_error_on_failure(
+                    patch_info["root"], patch_info["patch"]
+                )
+
+                if target == "FAIL" and returncode != 0:
+                    print("XFAIL: test_returncode.%s (file: %s)" % 
(testid.strip("."), os.path.basename(patch_info["patch"])))
+                    counts["xfail"] = counts["xfail"] + 1
+                elif target == "PASS" and returncode == 0:
+                    counts["xpass"] = counts["xpass"] + 1
+                    print("XPASS: test_returncode.%s (file: %s)" % 
(testid.strip("."), os.path.basename(patch_info["patch"])))
+                elif target == "SKIP" and returncode == 0:
+                    counts["xskip"] = counts["xskip"] + 1
+                    print("XSKIP: test_returncode.%s (file: %s)" % 
(testid.strip("."), os.path.basename(patch_info["patch"])))
+                else:
+                    print(f"Test failed: target '{target}', expected return 
code '{expected}', got '{returncode}'")
+
+                break
+
+    return counts
+
 def test_head_attached(patches, counts, branch):
 
     git_attach_head(branch)
@@ -178,6 +214,7 @@ def run_tests(patches, counts):
     counts = test_head_detached(patches, counts)
     restore_git_state(git_state)
     run_sh(f"git branch -D {temp_branch}")
+    counts = test_returncode(patches, counts)
 
     return counts
 
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#233414): 
https://lists.openembedded.org/g/openembedded-core/message/233414
Mute This Topic: https://lists.openembedded.org/mt/118385558/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to