From f35799cb410f89003c5ae84ab6e711eb4b9e3321 Mon Sep 17 00:00:00 2001 From: Scott Graham Date: Thu, 11 Jan 2018 15:46:36 -0800 Subject: [PATCH] fuchsia: Ensure qemu instance is ready before continuing after 'start' Ensures that enough networking is set up before returning so that the VM will be ready to accept commands to run tests. Otherwise requests to do so immediately after the VM is started can flakily fail. Bug: crashpad:196 Change-Id: Idc231e7fc418ad054bb9ec115c1598c804055a96 Reviewed-on: https://chromium-review.googlesource.com/862709 Commit-Queue: Scott Graham Reviewed-by: Mark Mentovai --- build/run_fuchsia_qemu.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/build/run_fuchsia_qemu.py b/build/run_fuchsia_qemu.py index e3f4efc3..edc51db3 100755 --- a/build/run_fuchsia_qemu.py +++ b/build/run_fuchsia_qemu.py @@ -27,6 +27,7 @@ import signal import subprocess import sys import tempfile +import time try: from subprocess import DEVNULL @@ -57,7 +58,7 @@ def _CheckForTun(): if returncode != 0: print('To use QEMU with networking on Linux, configure TUN/TAP. See:', file=sys.stderr) - print(' https://fuchsia.googlesource.com/magenta/+/HEAD/docs/qemu.md#enabling-networking-under-qemu-x86_64-only', + print(' https://fuchsia.googlesource.com/zircon/+/HEAD/docs/qemu.md#enabling-networking-under-qemu-x86_64-only', file=sys.stderr) return 2 return 0 @@ -77,6 +78,8 @@ def _Start(pid_file): initrd_path = os.path.join(kernel_data_dir, 'bootdata.bin') mac_tail = ':'.join('%02x' % random.randint(0, 255) for x in range(3)) + instance_name = 'crashpad_qemu_' + \ + ''.join(chr(random.randint(ord('A'), ord('Z'))) for x in range(8)) # These arguments are from the Fuchsia repo in zircon/scripts/run-zircon. popen = subprocess.Popen([ @@ -93,12 +96,22 @@ def _Start(pid_file): '-enable-kvm', '-netdev', 'type=tap,ifname=qemu,script=no,downscript=no,id=net0', '-device', 'e1000,netdev=net0,mac=52:54:00:' + mac_tail, - '-append', 'TERM=dumb', + '-append', 'TERM=dumb zircon.nodename=' + instance_name, ], stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL) with open(pid_file, 'wb') as f: f.write('%d\n' % popen.pid) + for i in range(10): + netaddr_path = os.path.join(fuchsia_dir, 'sdk', arch, 'tools', 'netaddr') + if subprocess.call([netaddr_path, '--nowait', instance_name], + stdout=open(os.devnull), stderr=open(os.devnull)) == 0: + break + time.sleep(.5) + else: + print('instance did not respond after start', file=sys.stderr) + return 1 + def main(args): if len(args) != 1 or args[0] not in ('start', 'stop'):