Commit de2afca6 authored by Chong Gu's avatar Chong Gu Committed by Commit Bot

[Fuchsia] Target module cleanup.

Change --output-dir flag to --out-dir
Make --out-dir a mandatory flag, but allow it to be set automatically in gpu integration tests.

Bug: 1080854
Change-Id: I2ee9e96edc3d0b0a5514ee8d2cee179400142e49
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2386430Reviewed-by: default avatarRobert Ma <robertma@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Reviewed-by: default avatarBrian Sheedy <bsheedy@chromium.org>
Commit-Queue: Chong Gu <chonggu@google.com>
Auto-Submit: Chong Gu <chonggu@google.com>
Cr-Commit-Position: refs/heads/master@{#806932}
parent 30fe7c4e
......@@ -152,7 +152,7 @@ template("fuchsia_package_runner") {
}
executable_args += [
"--output-dir",
"--out-dir",
"@WrappedPath(.)",
"--target-cpu",
target_cpu,
......
......@@ -20,9 +20,9 @@ def GetTargetType():
class AemuTarget(qemu_target.QemuTarget):
EMULATOR_NAME = 'aemu'
def __init__(self, output_dir, target_cpu, system_log_file, cpu_cores,
def __init__(self, out_dir, target_cpu, system_log_file, cpu_cores,
require_kvm, ram_size_mb, enable_graphics, hardware_gpu):
super(AemuTarget, self).__init__(output_dir, target_cpu, system_log_file,
super(AemuTarget, self).__init__(out_dir, target_cpu, system_log_file,
cpu_cores, require_kvm, ram_size_mb)
# TODO(crbug.com/1000907): Enable AEMU for arm64.
......
......@@ -15,26 +15,29 @@ def _AddTargetSpecificationArgs(arg_parser):
"""Returns a parser that handles the target type used for the test run."""
device_args = arg_parser.add_argument_group(
'target', 'Arguments specifying the Fuchsia target type.')
'target',
'Arguments specifying the Fuchsia target type. To see a list of '
'arguments available for a specific target type, specify the desired '
'target to use and add the --help flag.')
device_args.add_argument('--target-cpu',
default=GetHostArchFromPlatform(),
help='GN target_cpu setting for the build. Defaults '
'to the same architecture as host cpu.')
device_args.add_argument('--device',
default=None,
choices=['aemu', 'qemu', 'device', 'ext'],
choices=['aemu', 'qemu', 'device', 'custom'],
help='Choose to run on aemu|qemu|device. '
'By default, Fuchsia will run on AEMU on x64 '
'hosts and QEMU on arm64 hosts. Alternatively, '
'setting to ext will require specifying the '
'setting to custom will require specifying the '
'subclass of Target class used via the '
'--ext-device-path flag.')
'--custom-device-target flag.')
device_args.add_argument('-d',
action='store_const',
dest='device',
const='device',
help='Run on device instead of emulator.')
device_args.add_argument('--ext-device-path',
device_args.add_argument('--custom-device-target',
default=None,
help='Specify path to file that contains the '
'subclass of Target that will be used. Only '
......@@ -45,11 +48,11 @@ def _AddTargetSpecificationArgs(arg_parser):
def _GetTargetClass(args):
"""Gets the target class to be used for the test run."""
if args.device == 'ext':
if not args.ext_device_path:
raise Exception('--ext-device-path flag must be set when device flag '
'set to ext.')
target_path = args.ext_device_path
if args.device == 'custom':
if not args.custom_device_target:
raise Exception('--custom-device-target flag must be set when device '
'flag set to custom.')
target_path = args.custom_device_target
else:
if not args.device:
args.device = 'aemu' if args.target_cpu == 'x64' else 'qemu'
......
......@@ -60,10 +60,17 @@ class DeviceTarget(target.Target):
If |_host| is set:
Deploy to a device at the host IP address as-is."""
def __init__(self, output_dir, target_cpu, host=None, node_name=None,
port=None, ssh_config=None, fuchsia_out_dir=None,
os_check='update', system_log_file=None):
"""output_dir: The directory which will contain the files that are
def __init__(self,
out_dir,
target_cpu,
host=None,
node_name=None,
port=None,
ssh_config=None,
fuchsia_out_dir=None,
os_check='update',
system_log_file=None):
"""out_dir: The directory which will contain the files that are
generated to support the deployment.
target_cpu: The CPU architecture of the deployment target. Can be
"x64" or "arm64".
......@@ -78,7 +85,7 @@ class DeviceTarget(target.Target):
mismatch.
If 'ignore', the target's SDK version is ignored."""
super(DeviceTarget, self).__init__(output_dir, target_cpu)
super(DeviceTarget, self).__init__(out_dir, target_cpu)
self._port = port if port else 22
self._system_log_file = system_log_file
......@@ -110,8 +117,8 @@ class DeviceTarget(target.Target):
else:
# Default to using an automatically generated SSH config and keys.
boot_data.ProvisionSSH(output_dir)
self._ssh_config_path = boot_data.GetSSHConfigPath(output_dir)
boot_data.ProvisionSSH(out_dir)
self._ssh_config_path = boot_data.GetSSHConfigPath(out_dir)
@staticmethod
def RegisterArgs(arg_parser):
......@@ -138,7 +145,7 @@ class DeviceTarget(target.Target):
'Equivalent to setting --ssh_config and '
'--os-check=ignore')
device_args.add_argument(
'--os_check',
'--os-check',
choices=['check', 'update', 'ignore'],
default='update',
help="Sets the OS version enforcement policy. If 'check', then the "
......
......@@ -16,13 +16,13 @@ import tempfile
class EmuTarget(target.Target):
def __init__(self, output_dir, target_cpu, system_log_file):
"""output_dir: The directory which will contain the files that are
def __init__(self, out_dir, target_cpu, system_log_file):
"""out_dir: The directory which will contain the files that are
generated to support the emulator deployment.
target_cpu: The emulated target CPU architecture.
Can be 'x64' or 'arm64'."""
super(EmuTarget, self).__init__(output_dir, target_cpu)
super(EmuTarget, self).__init__(out_dir, target_cpu)
self._emu_process = None
self._system_log_file = system_log_file
self._amber_repo = None
......@@ -49,9 +49,6 @@ class EmuTarget(target.Target):
def __enter__(self):
return self
def _GetEmulatorName(self):
pass
def _BuildCommand(self):
"""Build the command that will be run to start Fuchsia in the emulator."""
pass
......@@ -72,7 +69,7 @@ class EmuTarget(target.Target):
# Python script panicking and aborting.
# The precise root cause is still nebulous, but this fix works.
# See crbug.com/741194.
logging.debug('Launching %s.' % (self._GetEmulatorName()))
logging.debug('Launching %s.' % (self.EMULATOR_NAME))
logging.debug(' '.join(emu_command))
# Zircon sends debug logs to serial port (see kernel.serial=legacy flag
......@@ -113,21 +110,20 @@ class EmuTarget(target.Target):
def Shutdown(self):
if not self._emu_process:
logging.error('%s did not start' % (self._GetEmulatorName()))
logging.error('%s did not start' % (self.EMULATOR_NAME))
return
returncode = self._emu_process.poll()
if returncode == None:
logging.info('Shutting down %s' % (self._GetEmulatorName()))
logging.info('Shutting down %s' % (self.EMULATOR_NAME))
self._emu_process.kill()
elif returncode == 0:
logging.info('%s quit unexpectedly without errors' %
self._GetEmulatorName())
logging.info('%s quit unexpectedly without errors' % self.EMULATOR_NAME)
elif returncode < 0:
logging.error('%s was terminated by signal %d' %
(self._GetEmulatorName(), -returncode))
(self.EMULATOR_NAME, -returncode))
else:
logging.error('%s quit unexpectedly with exit code %d' %
(self._GetEmulatorName(), returncode))
(self.EMULATOR_NAME, returncode))
# TODO(crbug.com/1100402): Delete when no longer needed for debug info.
# Log system statistics at the end of the emulator run.
......@@ -141,11 +137,11 @@ class EmuTarget(target.Target):
def _GetEndpoint(self):
if not self._IsEmuStillRunning():
raise Exception('%s quit unexpectedly.' % (self._GetEmulatorName()))
raise Exception('%s quit unexpectedly.' % (self.EMULATOR_NAME))
return ('localhost', self._host_ssh_port)
def _GetSshConfigPath(self):
return boot_data.GetSSHConfigPath(self._output_dir)
return boot_data.GetSSHConfigPath(self._out_dir)
# TODO(crbug.com/1100402): Delete when no longer needed for debug info.
......
......@@ -14,10 +14,10 @@ from common import SDK_ROOT, EnsurePathExists, \
def GetTargetType():
return GenericX64Target
return GenericX64PavedDeviceTarget
class GenericX64Target(device_target.DeviceTarget):
class GenericX64PavedDeviceTarget(device_target.DeviceTarget):
"""In addition to the functionality provided by DeviceTarget, this class
automatically handles paving of x64 devices that use generic Fuchsia build.
......@@ -59,7 +59,7 @@ class GenericX64Target(device_target.DeviceTarget):
self._GetTargetSdkArch(),
boot_data.TARGET_TYPE_GENERIC)),
EnsurePathExists(
boot_data.GetBootImage(self._output_dir, self._GetTargetSdkArch(),
boot_data.GetBootImage(self._out_dir, self._GetTargetSdkArch(),
boot_data.TARGET_TYPE_GENERIC))
]
......@@ -67,7 +67,7 @@ class GenericX64Target(device_target.DeviceTarget):
bootserver_command += ['-n', self._node_name]
bootserver_command += ['--']
bootserver_command += boot_data.GetKernelArgs(self._output_dir)
bootserver_command += boot_data.GetKernelArgs(self._out_dir)
logging.debug(' '.join(bootserver_command))
_, stdout = SubprocessCallWithTimeout(bootserver_command,
......
......@@ -40,10 +40,9 @@ def GetTargetType():
class QemuTarget(emu_target.EmuTarget):
EMULATOR_NAME = 'qemu'
def __init__(self, output_dir, target_cpu, system_log_file, cpu_cores,
def __init__(self, out_dir, target_cpu, system_log_file, cpu_cores,
require_kvm, ram_size_mb):
super(QemuTarget, self).__init__(output_dir, target_cpu,
system_log_file)
super(QemuTarget, self).__init__(out_dir, target_cpu, system_log_file)
self._cpu_cores=cpu_cores
self._require_kvm=require_kvm
self._ram_size_mb=ram_size_mb
......@@ -75,29 +74,37 @@ class QemuTarget(emu_target.EmuTarget):
boot_data.AssertBootImagesExist(self._GetTargetSdkArch(), 'qemu')
emu_command = [
'-kernel', EnsurePathExists(
'-kernel',
EnsurePathExists(
boot_data.GetTargetFile('qemu-kernel.kernel',
self._GetTargetSdkArch(),
boot_data.TARGET_TYPE_QEMU)),
'-initrd', EnsurePathExists(
boot_data.GetBootImage(self._output_dir, self._GetTargetSdkArch(),
'-initrd',
EnsurePathExists(
boot_data.GetBootImage(self._out_dir, self._GetTargetSdkArch(),
boot_data.TARGET_TYPE_QEMU)),
'-m', str(self._ram_size_mb),
'-smp', str(self._cpu_cores),
'-m',
str(self._ram_size_mb),
'-smp',
str(self._cpu_cores),
# Attach the blobstore and data volumes. Use snapshot mode to discard
# any changes.
'-snapshot',
'-drive', 'file=%s,format=qcow2,if=none,id=blobstore,snapshot=on' %
_EnsureBlobstoreQcowAndReturnPath(self._output_dir,
self._GetTargetSdkArch()),
'-device', 'virtio-blk-pci,drive=blobstore',
'-drive',
'file=%s,format=qcow2,if=none,id=blobstore,snapshot=on' %
_EnsureBlobstoreQcowAndReturnPath(self._out_dir,
self._GetTargetSdkArch()),
'-device',
'virtio-blk-pci,drive=blobstore',
# Use stdio for the guest OS only; don't attach the QEMU interactive
# monitor.
'-serial', 'stdio',
'-monitor', 'none',
]
'-serial',
'stdio',
'-monitor',
'none',
]
# Configure the machine to emulate, based on the target architecture.
if self._target_cpu == 'arm64':
......@@ -141,7 +148,7 @@ class QemuTarget(emu_target.EmuTarget):
emu_command.extend(kvm_command)
kernel_args = boot_data.GetKernelArgs(self._output_dir)
kernel_args = boot_data.GetKernelArgs(self._out_dir)
# TERM=dumb tells the guest OS to not emit ANSI commands that trigger
# noisy ANSI spew from the user's terminal emulator.
......@@ -178,7 +185,7 @@ def _ComputeFileHash(filename):
return hasher.hexdigest()
def _EnsureBlobstoreQcowAndReturnPath(output_dir, target_arch):
def _EnsureBlobstoreQcowAndReturnPath(out_dir, target_arch):
"""Returns a file containing the Fuchsia blobstore in a QCOW format,
with extra buffer space added for growth."""
......@@ -187,11 +194,11 @@ def _EnsureBlobstoreQcowAndReturnPath(output_dir, target_arch):
fvm_tool = common.GetHostToolPathFromPlatform('fvm')
blobstore_path = boot_data.GetTargetFile('storage-full.blk', target_arch,
'qemu')
qcow_path = os.path.join(output_dir, 'gen', 'blobstore.qcow')
qcow_path = os.path.join(out_dir, 'gen', 'blobstore.qcow')
# Check a hash of the blobstore to determine if we can re-use an existing
# extended version of it.
blobstore_hash_path = os.path.join(output_dir, 'gen', 'blobstore.hash')
blobstore_hash_path = os.path.join(out_dir, 'gen', 'blobstore.hash')
current_blobstore_hash = _ComputeFileHash(blobstore_path)
if os.path.exists(blobstore_hash_path) and os.path.exists(qcow_path):
......
......@@ -60,8 +60,8 @@ class FuchsiaTargetException(Exception):
class Target(object):
"""Base class representing a Fuchsia deployment target."""
def __init__(self, output_dir, target_cpu):
self._output_dir = output_dir
def __init__(self, out_dir, target_cpu):
self._out_dir = out_dir
self._started = False
self._dry_run = False
self._target_cpu = target_cpu
......@@ -72,9 +72,8 @@ class Target(object):
common_args = arg_parser.add_argument_group(
'target', 'Arguments that apply to all targets.')
common_args.add_argument(
'--output-dir',
'--out-dir',
type=os.path.realpath,
default=os.getcwd(),
help=('Path to the directory in which build files are located. '
'Defaults to current directory.'))
common_args.add_argument('--system-log-file',
......
......@@ -57,7 +57,7 @@ def main():
type=int,
help='Sets the limit of test batch to run in a single '
'process.')
# --test-launcher-filter-file is specified relative to --output-dir,
# --test-launcher-filter-file is specified relative to --out-dir,
# so specifying type=os.path.* will break it.
parser.add_argument('--test-launcher-filter-file',
default=None,
......@@ -81,9 +81,9 @@ def main():
help='Arguments for the test process.')
args = parser.parse_args()
# Flag output_dir is required for tests launched with this script.
if not args.output_dir:
raise ValueError("output-dir must be specified.")
# Flag out_dir is required for tests launched with this script.
if not args.out_dir:
raise ValueError("out-dir must be specified.")
ConfigureLogging(args)
......@@ -157,7 +157,7 @@ def main():
args.package_name)
run_package_args = RunPackageArgs.FromCommonArgs(args)
returncode = RunPackage(args.output_dir, target, args.package,
returncode = RunPackage(args.out_dir, target, args.package,
args.package_name, child_args, run_package_args)
if test_server:
......
......@@ -31,8 +31,9 @@ def main():
# If output_dir is not set, assume the script is being launched
# from the output directory.
if not args.output_dir:
args.output_dir = os.getcwd()
if not args.out_dir:
args.out_dir = os.getcwd()
additional_target_args['out_dir'] = args.out_dir
# Create a temporary log file that Telemetry will look to use to build
# an artifact when tests fail.
......@@ -43,7 +44,7 @@ def main():
additional_target_args['system_log_file'] = args.system_log_file
package_names = ['web_engine', 'web_engine_shell']
web_engine_dir = os.path.join(args.output_dir, 'gen', 'fuchsia', 'engine')
web_engine_dir = os.path.join(args.out_dir, 'gen', 'fuchsia', 'engine')
gpu_script = [
os.path.join(path_util.GetChromiumSrcDir(), 'content', 'test', 'gpu',
'run_gpu_integration_test.py')
......@@ -55,7 +56,7 @@ def main():
with GetDeploymentTargetForArgs(additional_target_args) as target:
target.Start()
_, fuchsia_ssh_port = target._GetEndpoint()
gpu_script.extend(['--fuchsia-ssh-config-dir', args.output_dir])
gpu_script.extend(['--fuchsia-ssh-config-dir', args.out_dir])
gpu_script.extend(['--fuchsia-ssh-port', str(fuchsia_ssh_port)])
gpu_script.extend(['--fuchsia-system-log-file', args.system_log_file])
if args.verbose:
......
......@@ -130,7 +130,7 @@ class _TargetHost(object):
self._amber_repo = None
self._target = None
target_args = {
'output_dir': build_path,
'out_dir': build_path,
'target_cpu': 'x64',
'system_log_file': None,
'cpu_cores': CPU_CORES,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment