diff mbox series

[v3,6/6] patchtest/selftest: Ensure HEAD is attached before running attach tests case

Message ID 20251209105513.273859-6-naftaly.ralamboarivony@smile.fr
State Accepted, archived
Commit a850252348096e5d6b0bb267e5108bf73de88e85
Headers show
Series [v3,1/6] patchtest: fix failure when oe-core repo is in detached HEAD | expand

Commit Message

naftaly.ralamboarivony@smile.fr Dec. 9, 2025, 10:55 a.m. UTC
From: Naftaly RALAMBOARIVONY <naftaly.ralamboarivony@smile.fr>

If the repo is in a detached HEAD state, create and check out a temporary branch
to attach HEAD. If the branch already exists, the error is raised via run_sh.

Add a check to verify that the Git state has not changed before and
after the test in the attached HEAD.

Signed-off-by: Naftaly RALAMBOARIVONY <naftaly.ralamboarivony@smile.fr>
---
 meta/lib/patchtest/selftest/selftest | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Mathieu Dubois-Briand Dec. 10, 2025, 12:38 p.m. UTC | #1
On Tue Dec 9, 2025 at 11:55 AM CET, naftaly.ralamboarivony via lists.openembedded.org wrote:
> From: Naftaly RALAMBOARIVONY <naftaly.ralamboarivony@smile.fr>
>
> If the repo is in a detached HEAD state, create and check out a temporary branch
> to attach HEAD. If the branch already exists, the error is raised via run_sh.
>
> Add a check to verify that the Git state has not changed before and
> after the test in the attached HEAD.
>
> Signed-off-by: Naftaly RALAMBOARIVONY <naftaly.ralamboarivony@smile.fr>
> ---

Hi Naftaly,

Thanks for your patches.

> --- a/meta/lib/patchtest/selftest/selftest
> +++ b/meta/lib/patchtest/selftest/selftest
> @@ -120,6 +120,9 @@ def is_git_state_same(before, after):
>  
>  def run_tests(patches, counts):
> +    temp_branch = "test_patchtest_head_attached"
>      git_state = get_git_state()
> -    counts = test_head_attached(patches, counts)
> +    assert git_state['branch'] != temp_branch, f"Cannot run patchtest selftest while on branch '{temp_branch}'"

It looks like we are hitting this error on the autobuilder.

So it means either we have to selftest, or we have to modify how this is
running on the autobuilder.

+ /srv/pokybuild/yocto-worker/patchtest-selftest/build/layers/openembedded-core//meta/lib/patchtest/selftest/selftest
Not a Git repository
Traceback (most recent call last):
  File "/srv/pokybuild/yocto-worker/patchtest-selftest/build/layers/openembedded-core//meta/lib/patchtest/selftest/selftest", line 198, in <module>
    counts = run_tests(patches, counts)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/pokybuild/yocto-worker/patchtest-selftest/build/layers/openembedded-core//meta/lib/patchtest/selftest/selftest", line 173, in run_tests
    assert git_state['branch'] != temp_branch, f"Cannot run patchtest selftest while on branch '{temp_branch}'"
           ~~~~~~~~~^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

https://autobuilder.yoctoproject.org/valkyrie/#/builders/71/builds/2829

Any clue about what might be done here?

Thanks,
Mathieu
diff mbox series

Patch

diff --git a/meta/lib/patchtest/selftest/selftest b/meta/lib/patchtest/selftest/selftest
index 74b50f65e9..dc8a636821 100755
--- a/meta/lib/patchtest/selftest/selftest
+++ b/meta/lib/patchtest/selftest/selftest
@@ -120,6 +120,9 @@  def is_git_state_same(before, after):
 
     return ret
 
+def git_attach_head(temp_branch):
+    run_sh(f"git switch -C {temp_branch}")
+
 def git_detach_head():
     run_sh("git switch --detach HEAD")
     assert run_sh("git rev-parse --abbrev-ref HEAD") == "HEAD", "Failed to enter detached HEAD state"
@@ -136,10 +139,15 @@  def test(root, patch):
 
     return results
 
-def test_head_attached(patches, counts):
+def test_head_attached(patches, counts, branch):
+
+    git_attach_head(branch)
+    git_state_before = get_git_state()
     for patch_info in patches:
         results = test(patch_info["root"], patch_info["patch"])
         counts = analyze_result(results, patch_info, counts)
+    git_state_after = get_git_state()
+    assert is_git_state_same(git_state_before, git_state_after), "Repository state changed after attached HEAD test."
     return counts
 
 def test_head_detached(patches, counts):
@@ -160,10 +168,13 @@  def test_head_detached(patches, counts):
     return counts
 
 def run_tests(patches, counts):
+    temp_branch = "test_patchtest_head_attached"
     git_state = get_git_state()
-    counts = test_head_attached(patches, counts)
+    assert git_state['branch'] != temp_branch, f"Cannot run patchtest selftest while on branch '{temp_branch}'"
+    counts = test_head_attached(patches, counts, temp_branch)
     counts = test_head_detached(patches, counts)
     restore_git_state(git_state)
+    run_sh(f"git branch -D {temp_branch}")
 
     return counts