Skip to content

Commit 08dec46

Browse files
author
root
committed
perf_top.py:test_top$ Added fix to eliminate pexpect and pexpect:spawn
issue The pexpect issue is fixed by using alternative as pexpect while running is not recognised. Signed-off-by: Tejas Manhas <[email protected]>
1 parent 4251053 commit 08dec46

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

perf/perf_top.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import sys
1818
import time
1919
import platform
20-
import pexpect
20+
import threading
2121
import tempfile
2222
import os
2323
from avocado import Test
@@ -76,15 +76,31 @@ def test_top(self):
7676
self.option = self.option + " /boot/vmlinux-" + \
7777
platform.uname()[2]
7878

79-
child = pexpect.spawn("perf top %s" % self.option, encoding='utf-8')
80-
time.sleep(10)
81-
child.logfile = sys.stdout
82-
err = child.expect_exact(
83-
['Error: ', 'perf: Segmentation fault', pexpect.TIMEOUT])
84-
child.send('q')
85-
exit_status = child.wait()
86-
if exit_status != 0 or err == 0:
87-
self.fail("Unknown option %s" % self.option)
79+
cmd = f"perf top {self.option}"
80+
self.log.info(f"Running command: {cmd}")
81+
82+
proc = process.SubProcess(cmd)
83+
proc.start()
84+
time.sleep(10) # let perf top run for a short while
85+
86+
# Try to stop gracefully (like pressing 'q')
87+
if proc.poll() is None:
88+
process.run(f"pkill -SIGINT -f '{cmd}'", ignore_status=True)
89+
time.sleep(1)
90+
91+
proc.wait()
92+
93+
# Check for dmesg errors
94+
dmesg.collect_errors_dmesg([
95+
'WARNING: CPU:', 'Oops', 'Segfault',
96+
'soft lockup', 'Unable to handle'
97+
])
98+
99+
# Check exit code and stderr for issues
100+
if proc.result.exit_status != 0:
101+
self.fail(f"perf top failed with option {self.option}: "
102+
f"{proc.result.stderr.decode('utf-8', 'ignore')}")
103+
88104
dmesg.collect_errors_dmesg(['WARNING: CPU:', 'Oops', 'Segfault',
89105
'soft lockup', 'Unable to handle'])
90106

0 commit comments

Comments
 (0)