Add |target_cpu| option to Fuchsia exe_/test_runner scripts.

- BuildBootfs() now accepts a |target_cpu| parameter, and uses it to
  choose the correct bootdata and kernel binaries.
- RunFuchsia() uses the |target_cpu| in the BootfsData to configure QEMU
  for the correct machine, CPU-type, etc.
- GN rules are updated to propagate the |target_cpu| into the runner-
  script creation, and the scripts themselves are updated to pass it on
  to BuildBootfs().

ARM64 binaries are run with QEMU machine=virt, cpu=cortex-a53.

Bug: 772031
Change-Id: Icb529dda7394b3731aa888e0b092e04215fe6016
Reviewed-on: https://chromium-review.googlesource.com/710058
Commit-Queue: Wez <wez@chromium.org>
Reviewed-by: Scott Graham <scottmg@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#507808}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 143667269a9aa451cdd90e0a80d492f583a1c949
This commit is contained in:
Wez 2017-10-10 22:55:17 +00:00 коммит произвёл Commit Bot
Родитель 59d74a12a4
Коммит b2421585fc
4 изменённых файлов: 51 добавлений и 14 удалений

Просмотреть файл

@ -63,6 +63,8 @@ template("generate_runner_script") {
runner_script,
"--output-directory",
rebase_path(root_build_dir, root_build_dir),
"--target-cpu",
target_cpu,
]
deps += [

Просмотреть файл

@ -26,6 +26,8 @@ def main():
parser.add_argument('--runtime-deps-path',
type=os.path.realpath,
help='Runtime data dependency file from GN.')
parser.add_argument('--target-cpu',
help='GN target_cpu setting for the build.')
parser.add_argument('--exe-name',
type=os.path.realpath,
help='Name of the the binary executable.')
@ -37,7 +39,7 @@ def main():
args.output_directory,
ReadRuntimeDeps(args.runtime_deps_path, args.output_directory),
args.exe_name, child_args, args.dry_run, summary_output=None,
power_off=False)
power_off=False, target_cpu=args.target_cpu)
if not bootfs:
return 2

Просмотреть файл

@ -131,7 +131,7 @@ def _StripBinary(dry_run, bin_path):
return strip_path
def _StripBinaries(dry_run, file_mapping):
def _StripBinaries(dry_run, file_mapping, target_cpu):
"""Updates the supplied manifest |file_mapping|, by stripping any executables
and updating their entries to point to the stripped location. Returns a
mapping from target executables to their un-stripped paths, for use during
@ -142,6 +142,8 @@ def _StripBinaries(dry_run, file_mapping):
file_tag = f.read(4)
if file_tag == '\x7fELF':
symbols_mapping[target] = source
# TODO(wez): Strip ARM64 binaries as well. See crbug.com/773444.
if target_cpu == 'x64':
file_mapping[target] = _StripBinary(dry_run, source)
return symbols_mapping
@ -163,19 +165,35 @@ def ReadRuntimeDeps(deps_path, output_directory):
return result
def _TargetCpuToArch(target_cpu):
"""Returns the Fuchsia SDK architecture name for the |target_cpu|."""
if target_cpu == 'arm64':
return 'aarch64'
elif target_cpu == 'x64':
return 'x86_64'
raise Exception('Unknown target_cpu:' + target_cpu)
def _TargetCpuToSdkBinPath(target_cpu):
"""Returns the path to the kernel & bootfs .bin files for |target_cpu|."""
return os.path.join(SDK_ROOT, 'target', _TargetCpuToArch(target_cpu))
class BootfsData(object):
"""Results from BuildBootfs().
bootfs: Local path to .bootfs image file.
symbols_mapping: A dict mapping executables to their unstripped originals.
target_cpu: GN's target_cpu setting for the image.
"""
def __init__(self, bootfs_name, symbols_mapping):
def __init__(self, bootfs_name, symbols_mapping, target_cpu):
self.bootfs = bootfs_name
self.symbols_mapping = symbols_mapping
self.target_cpu = target_cpu
def BuildBootfs(output_directory, runtime_deps, bin_name, child_args, dry_run,
summary_output, power_off):
summary_output, power_off, target_cpu):
# |runtime_deps| already contains (target, source) pairs for the runtime deps,
# so we can initialize |file_mapping| from it directly.
file_mapping = dict(runtime_deps)
@ -229,7 +247,7 @@ def BuildBootfs(output_directory, runtime_deps, bin_name, child_args, dry_run,
lambda x: _MakeTargetImageName(DIR_SOURCE_ROOT, output_directory, x))
# Strip any binaries in the file list, and generate a manifest mapping.
symbols_mapping = _StripBinaries(dry_run, file_mapping)
symbols_mapping = _StripBinaries(dry_run, file_mapping, target_cpu)
# Write the target, source mappings to a file suitable for bootfs.
manifest_file = open(bin_name + '.bootfs_manifest', 'w')
@ -245,11 +263,11 @@ def BuildBootfs(output_directory, runtime_deps, bin_name, child_args, dry_run,
[mkbootfs_path, '-o', bootfs_name,
# TODO(wez): Parameterize this on the |target_cpu| from GN.
'--target=boot', os.path.join(
SDK_ROOT, 'target', 'x86_64', 'bootdata.bin'),
_TargetCpuToSdkBinPath(target_cpu), 'bootdata.bin'),
'--target=system', manifest_file.name]) != 0:
return None
return BootfsData(bootfs_name, symbols_mapping)
return BootfsData(bootfs_name, symbols_mapping, target_cpu)
def _SymbolizeEntries(entries):
@ -364,7 +382,8 @@ def _GetResultsFromImg(dry_run, test_launcher_summary_output):
def RunFuchsia(bootfs_data, use_device, dry_run, test_launcher_summary_output):
# TODO(wez): Parameterize this on the |target_cpu| from GN.
kernel_path = os.path.join(SDK_ROOT, 'target', 'x86_64', 'zircon.bin')
kernel_path = os.path.join(_TargetCpuToSdkBinPath(bootfs_data.target_cpu),
'zircon.bin')
if use_device:
# TODO(fuchsia): This doesn't capture stdout as there's no way to do so
@ -374,16 +393,15 @@ def RunFuchsia(bootfs_data, use_device, dry_run, test_launcher_summary_output):
bootfs_data.bootfs]
return _RunAndCheck(dry_run, bootserver_command)
qemu_path = os.path.join(SDK_ROOT, 'qemu', 'bin', 'qemu-system-x86_64')
qemu_path = os.path.join(
SDK_ROOT, 'qemu', 'bin',
'qemu-system-' + _TargetCpuToArch(bootfs_data.target_cpu))
qemu_command = [qemu_path,
'-m', '2048',
'-nographic',
'-machine', 'q35',
'-kernel', kernel_path,
'-initrd', bootfs_data.bootfs,
'-smp', '4',
'-enable-kvm',
'-cpu', 'host,migratable=no',
# Configure virtual network. It is used in the tests to connect to
# testserver running on the host.
@ -401,6 +419,19 @@ def RunFuchsia(bootfs_data, use_device, dry_run, test_launcher_summary_output):
'-append', 'TERM=dumb kernel.halt_on_panic=true',
]
# Configure the machine & CPU to emulate, based on the target architecture.
if bootfs_data.target_cpu == 'arm64':
qemu_command.extend([
'-machine','virt',
'-cpu', 'cortex-a53',
])
else:
qemu_command.extend([
'-enable-kvm',
'-machine', 'q35',
'-cpu', 'host,migratable=no',
])
if test_launcher_summary_output:
# Make and mount a 100M minfs formatted image that is used to copy the
# results json to, for extraction from the target.

Просмотреть файл

@ -114,6 +114,8 @@ def main():
default=False,
help='Runs the tests and the launcher in the same '
'process. Useful for debugging.')
parser.add_argument('--target-cpu',
help='GN target_cpu setting for the build.')
parser.add_argument('--test-launcher-batch-limit',
type=int,
help='Sets the limit of test batch to run in a single '
@ -190,7 +192,7 @@ def main():
bootfs = BuildBootfs(
args.output_directory, runtime_deps, args.exe_name, child_args,
args.dry_run, summary_output=args.test_launcher_summary_output,
power_off=not args.device)
power_off=not args.device, target_cpu=args.target_cpu)
if not bootfs:
return 2