|
17 | 17 | import sys |
18 | 18 | import time |
19 | 19 | import platform |
20 | | -import pexpect |
| 20 | +import threading |
21 | 21 | import tempfile |
22 | 22 | import os |
23 | 23 | from avocado import Test |
@@ -76,15 +76,31 @@ def test_top(self): |
76 | 76 | self.option = self.option + " /boot/vmlinux-" + \ |
77 | 77 | platform.uname()[2] |
78 | 78 |
|
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 | + |
88 | 104 | dmesg.collect_errors_dmesg(['WARNING: CPU:', 'Oops', 'Segfault', |
89 | 105 | 'soft lockup', 'Unable to handle']) |
90 | 106 |
|
|
0 commit comments