Skip to content

Commit

Permalink
scripts/vm-util: Make timeout optional
Browse files Browse the repository at this point in the history
  • Loading branch information
avdgrinten committed Dec 5, 2024
1 parent 965226b commit 1ea57b1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
2 changes: 2 additions & 0 deletions bootstrap.d/tasks.y4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ tasks:
- 'qemu'
- '--arch'
- '@OPTION:arch@'
- '--timeout=1200'
- '--io-timeout=30'
- '--expect'
- "launching '/usr/libexec/weston-desktop-shell'"
workdir: '@BUILD_ROOT@'
Expand Down
33 changes: 24 additions & 9 deletions scripts/vm-util.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def __init__(self):
self.launch_time = None
self.last_io_time = None

self.timeout = 20 * 60
self.io_timeout = 30
self.timeout = None
self.io_timeout = None

async def run(self, qemu, qemu_args, *, expect_all, expect_none):
print("Running {}".format(shlex.join([qemu] + qemu_args)))
Expand Down Expand Up @@ -165,13 +165,19 @@ async def do_wait(self):
assert pending

now = time.time()
until_timeout = min(
self.timeout - (now - self.launch_time),
self.io_timeout - (now - self.last_io_time),
)
if until_timeout < 0:
self.proc.terminate()
pending_timeouts = []
if self.timeout is not None:
pending_timeouts.append(self.timeout - (now - self.launch_time))
if self.io_timeout is not None:
pending_timeouts.append(self.io_timeout - (now - self.last_io_time))

if not pending_timeouts:
until_timeout = None
else:
until_timeout = min(pending_timeouts)
if until_timeout < 0:
self.proc.terminate()
until_timeout = None

done, pending = await asyncio.wait(pending, timeout=until_timeout)
if done:
Expand All @@ -197,7 +203,10 @@ async def process_stdout(self, *, expect_all, expect_none):
if not sep:
break
buf = tail
line = head.decode("utf-8").strip()
try:
line = head.decode("utf-8").strip()
except UnicodeDecodeError:
continue

if expect_all is not None:
expect_all = [expr for expr in expect_all if not expr.search(line)]
Expand Down Expand Up @@ -533,6 +542,10 @@ def do_qemu(args):
expect_none = [re.compile(expr) for expr in args.expect_not]

runner = QemuRunner()
if args.timeout is not None:
runner.timeout = args.timeout
if args.io_timeout is not None:
runner.io_timeout = args.io_timeout
asyncio.run(runner.run(qemu, qemu_args, expect_all=expect_all, expect_none=expect_none))


Expand Down Expand Up @@ -565,6 +578,8 @@ def do_qemu(args):
qemu_parser.add_argument("--cmd", type=str)
qemu_parser.add_argument("--qmp", action="store_true")
qemu_parser.add_argument("--use-system-qemu", action="store_true")
qemu_parser.add_argument("--timeout", type=int)
qemu_parser.add_argument("--io-timeout", type=int)
qemu_parser.add_argument("--expect", action="append")
qemu_parser.add_argument("--expect-not", action="append")

Expand Down

0 comments on commit 1ea57b1

Please sign in to comment.