mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Test] Make timeout.py signal an error when the timeout is hit.
Print an error message and exit with a non-zero code when we hit the timeout. This makes it clear when a test fails due to a timeout. On Darwin, run `sample` on the target process first, so that the failure includes some information about what the test was doing when the timeout occurred.
This commit is contained in:
@@ -1,18 +1,29 @@
|
||||
#!/uar/bin/env python3
|
||||
|
||||
import platform
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
|
||||
sampleCommand = None
|
||||
timeoutSampleTime = 0
|
||||
|
||||
if platform.system() == 'Darwin':
|
||||
sampleCommand = '/usr/bin/sample'
|
||||
timeoutSampleTime = 10
|
||||
|
||||
|
||||
def watchdog(command, timeout=None):
|
||||
def watchdog(command, timeout):
|
||||
process = subprocess.Popen(command)
|
||||
timer = threading.Timer(timeout, process.kill)
|
||||
try:
|
||||
timer.start()
|
||||
process.communicate()
|
||||
finally:
|
||||
timer.cancel()
|
||||
process.wait(timeout=timeout)
|
||||
except subprocess.TimeoutExpired:
|
||||
if sampleCommand:
|
||||
pidstr = str(process.pid)
|
||||
subprocess.run([sampleCommand, pidstr, str(timeoutSampleTime)])
|
||||
process.kill()
|
||||
sys.exit(
|
||||
'error: command timed out after {} seconds: {}'
|
||||
.format(timeout, ' '.join(sys.argv[2:])))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user