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 <scottmg@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Scott Graham 2018-01-11 15:46:36 -08:00 committed by Commit Bot
parent 2a51cb5fd5
commit f35799cb41

View File

@ -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'):