# Copyright 2021 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Implements commands for running and interacting with Fuchsia on FVDL."""
import boot_data import common import emu_target import logging import os import re import subprocess import tempfile
# Use a temp file for vdl output.
self._vdl_output_file = tempfile.NamedTemporaryFile()
# Use a temp file for the device proto and write the ram size.
self._device_proto_file = tempfile.NamedTemporaryFile() with open(self._device_proto_file.name, 'w') as file:
file.write(_DEVICE_PROTO_TEMPLATE.format(ramsize=self._ram_size_mb))
def _IsEmuStillRunning(self): ifnot self._pid: try: with open(self._vdl_output_file.name) as vdl_file: for line in vdl_file: if'pid'in line:
match = re.match(r'.*pid:\s*(\d*).*', line) if match:
self._pid = match.group(1) except IOError:
logging.error('vdl_output file no longer found. ' 'Cannot get emulator pid.') returnFalse if subprocess.check_output(['ps', '-p', self._pid, 'o', 'comm=']): returnTrue
logging.error('Emulator pid no longer found. Emulator must be down.') returnFalse
def _GetEndpoint(self): if self._with_network: return self._GetNetworkAddress() return ('localhost', self._host_ssh_port)
def _GetNetworkAddress(self): if self._host: return (self._host, _DEFAULT_SSH_PORT) try: with open(self._vdl_output_file.name) as vdl_file: for line in vdl_file: if'network_address'in line:
address = re.match(r'.*network_address:\s*"\[(.*)\]".*', line) if address:
self._host = address.group(1) return (self._host, _DEFAULT_SSH_PORT)
logging.error('Network address not found.') raise EmulatorNetworkNotFoundError() except IOError as e:
logging.error('vdl_output file not found. Cannot get network address.') raise
def Shutdown(self): ifnot self._emu_process:
logging.error('%s did not start' % (self.EMULATOR_NAME)) return
femu_command = [
self._FVDL_PATH, '--sdk', 'kill', '--launched-proto',
self._vdl_output_file.name
]
femu_process = subprocess.Popen(femu_command)
returncode = femu_process.wait() if returncode == 0:
logging.info('FVDL shutdown successfully') else:
logging.info('FVDL kill returned error status {}'.format(returncode))
emu_target.LogProcessStatistics('proc_stat_end_log')
emu_target.LogSystemStatistics('system_statistics_end_log')
self._vdl_output_file.close()
self._device_proto_file.close()
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.