Skip to contentSkip to conversation

tests/functional/test_x86_64_hotplug_cpu: Fix race condition during unplug

PATCH In review Thomas Huth 3 participants 5 messages Jan 7, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/functional/test_x86_64_hotplug_cpu: Fix race condition during unplug

When unplugging the CPU, the test tries to check for a successful unplug by changing to the /sys/devices/system/cpu/cpu1 directory to see whether that fails. However, the "cd" could be faster than the unplug operation in the kernel, so there is a race condition and the test sometimes fails here.
Fix it by trying to change the directory in a loop until the the CPU has really been unplugged.

---
 tests/functional/test_x86_64_hotplug_cpu.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tests/functional/test_x86_64_hotplug_cpu.py +4 -2
index b1d5156c72..7b9200ac2e 100755
@@ -59,11 +59,13 @@ def test_hotplug(self):
                                           'cd /sys/devices/system/cpu/cpu1',
                                           'cpu1#')
 
+        exec_command_and_wait_for_pattern(self, 'cd ..', prompt)
         self.vm.cmd('device_del', id='c1')
 
         exec_command_and_wait_for_pattern(self,
-                                          'cd /sys/devices/system/cpu/cpu1',
-                                          'No such file or directory')
+                                    'while cd /sys/devices/system/cpu/cpu1 ;'
+                                    ' do sleep 0.2 ; done',
+                                    'No such file or directory')
 
 if __name__ == '__main__':
     LinuxKernelTest.main()
Signature · 1 line
2.47.1
#1 lore raw
Quoted 19 lines · Thomas Huth

When unplugging the CPU, the test tries to check for a successful unplug by changing to the /sys/devices/system/cpu/cpu1 directory to see whether that fails. However, the "cd" could be faster than the unplug operation in the kernel, so there is a race condition and the test sometimes fails here.
Fix it by trying to change the directory in a loop until the the CPU has really been unplugged.

---
 tests/functional/test_x86_64_hotplug_cpu.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tests/functional/test_x86_64_hotplug_cpu.py +0 -0
index b1d5156c72..7b9200ac2e 100755

tests/functional/test_x86_64_hotplug_cpu.py def test_hotplug(self): · line 62

Quoted 4 lines
tests/functional/test_x86_64_hotplug_cpu.py +1 -0
@@ -59,11 +59,13 @@ def test_hotplug(self):
                                           'cd /sys/devices/system/cpu/cpu1',
                                           'cpu1#')
 
+        exec_command_and_wait_for_pattern(self, 'cd ..', prompt)

Is this actually needed ? Are we keeping the CPU from being unplugged by being in that dir ? If so, why isn't it also needed in the while loop below ?

Quoted 14 lines
tests/functional/test_x86_64_hotplug_cpu.py +3 -2
         self.vm.cmd('device_del', id='c1')
 
         exec_command_and_wait_for_pattern(self,
-                                          'cd /sys/devices/system/cpu/cpu1',
-                                          'No such file or directory')
+                                    'while cd /sys/devices/system/cpu/cpu1 ;'
+                                    ' do sleep 0.2 ; done',
+                                    'No such file or directory')
 
 if __name__ == '__main__':
     LinuxKernelTest.main()
Signature · 1 line
2.47.1

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#2 lore raw
Quoted 23 lines · Daniel P. Berrangé
Quoted 22 lines · Thomas Huth

When unplugging the CPU, the test tries to check for a successful unplug by changing to the /sys/devices/system/cpu/cpu1 directory to see whether that fails. However, the "cd" could be faster than the unplug operation in the kernel, so there is a race condition and the test sometimes fails here.
Fix it by trying to change the directory in a loop until the the CPU has really been unplugged.

---
  tests/functional/test_x86_64_hotplug_cpu.py | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
tests/functional/test_x86_64_hotplug_cpu.py +0 -0
index b1d5156c72..7b9200ac2e 100755
@@ -59,11 +59,13 @@ def test_hotplug(self):
                                            'cd /sys/devices/system/cpu/cpu1',
                                            'cpu1#')
 
Quoted 5 lines

tests/functional/test_x86_64_hotplug_cpu.py def test_hotplug(self): · line 62

Quoted 1 line
tests/functional/test_x86_64_hotplug_cpu.py +1 -0
+        exec_command_and_wait_for_pattern(self, 'cd ..', prompt)

Is this actually needed ? Are we keeping the CPU from being unplugged by being in that dir ? If so, why isn't it also needed in the while loop below ?

I added it to make the console output less confusing (otherwise it's still shown in the prompt after the CPU has been unplugged)... but I can also remove this line again if you prefer it?

Thomas

#3 lore raw
Quoted 29 lines · Thomas Huth
Quoted 15 lines · Daniel P. Berrangé
Quoted 14 lines · Thomas Huth

When unplugging the CPU, the test tries to check for a successful unplug by changing to the /sys/devices/system/cpu/cpu1 directory to see whether that fails. However, the "cd" could be faster than the unplug operation in the kernel, so there is a race condition and the test sometimes fails here.
Fix it by trying to change the directory in a loop until the the CPU has really been unplugged.

---
  tests/functional/test_x86_64_hotplug_cpu.py | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
Quoted 12 lines

tests/functional/test_x86_64_hotplug_cpu.py def test_hotplug(self): · line 61

Quoted 8 lines
tests/functional/test_x86_64_hotplug_cpu.py +1 -0
index b1d5156c72..7b9200ac2e 100755
@@ -59,11 +59,13 @@ def test_hotplug(self):
                                            'cd /sys/devices/system/cpu/cpu1',
                                            'cpu1#')
+        exec_command_and_wait_for_pattern(self, 'cd ..', prompt)

Is this actually needed ? Are we keeping the CPU from being unplugged by being in that dir ? If so, why isn't it also needed in the while loop below ?

Quoted 3 lines

I added it to make the console output less confusing (otherwise it's still shown in the prompt after the CPU has been unplugged)... but I can also remove this line again if you prefer it?

No, i'm not that fussed.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#4 lore raw
In reply to Thomas Huth
Quoted 9 lines · Thomas Huth

When unplugging the CPU, the test tries to check for a successful unplug by changing to the /sys/devices/system/cpu/cpu1 directory to see whether that fails. However, the "cd" could be faster than the unplug operation in the kernel, so there is a race condition and the test sometimes fails here.
Fix it by trying to change the directory in a loop until the the CPU has really been unplugged.

Quoted 5 lines
---
 tests/functional/test_x86_64_hotplug_cpu.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Thanks for fixing this! I'll keep an eye on the CI job status after merging your next pull request.

Stefan