From 21ae9657a9188e27e33fa256f9599a3156707649 Mon Sep 17 00:00:00 2001 From: Zijie He Date: Tue, 22 Aug 2023 19:59:25 +0000 Subject: [PATCH] [Fuchsia] Import test scripts from chromium and use it to download image The with_envs.py works with the test script by providing the required environment variables. This change in theory does nothing since the `product download` is in 12.20230413.0.1, but `run` is removed before that, https://fxrev.dev/831319. So the DEPS cannot really download the images. The issue will be addressed in a coming change. Bug: #38752 Change-Id: Ib5f3d1d619921651208fa442201ba607a99e54d5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/319867 Reviewed-by: Ryan Macnak Reviewed-by: Alexander Thomas Commit-Queue: Zijie He --- .gn | 9 ++++ DEPS | 35 +++++++++++++-- build/fuchsia/with_envs.py | 43 +++++++++++++++++++ pkg/test_runner/lib/src/fuchsia.dart | 9 +++- .../lib/src/runtime_configuration.dart | 4 +- 5 files changed, 93 insertions(+), 7 deletions(-) create mode 100755 build/fuchsia/with_envs.py diff --git a/.gn b/.gn index a9e618fadae..b38467dd346 100644 --- a/.gn +++ b/.gn @@ -15,3 +15,12 @@ secondary_source = "//build/secondary/" # Override the default script executable to always be python3. script_executable = "python3" + +default_args = { + # fuchsia::io::InotifyWatchMask has been deprecated in 12 and removed in 13 + # right before the current version (12.20230418.0.1) we are using. + # https://fxrev.dev/836377. + # So explicitly marking fuchsia_target_api_level to 11 to workaround it + # temporarily. + fuchsia_target_api_level = 11 +} diff --git a/DEPS b/DEPS index 7d1e872ecfc..8f939f0b4e0 100644 --- a/DEPS +++ b/DEPS @@ -80,7 +80,8 @@ vars = { "gn_version": "git_revision:e3978de3e8dafb50a2b11efa784e08699a43faf8", # Update from https://chrome-infra-packages.appspot.com/p/fuchsia/sdk/gn - "fuchsia_sdk_version": "version:12.20230314.2.1", + "fuchsia_sdk_version": "version:12.20230407.0.1", + "download_fuchsia_deps": False, # Ninja, runs the build based on files generated by GN. "ninja_tag": "version:2@1.11.1.chromium.7", @@ -595,6 +596,7 @@ deps = { "dep_type": "cipd", }, + # TODO(38752): Confirm if mac sdk is necessary in dart. Var("dart_root") + "/third_party/fuchsia/sdk/mac": { "packages": [ { @@ -602,9 +604,12 @@ deps = { "version": Var("fuchsia_sdk_version"), } ], - "condition": 'host_os == "mac" and host_cpu == "x64"', + "condition": + 'download_fuchsia_deps and host_os == "mac" and host_cpu == "x64"', "dep_type": "cipd", }, + + # TODO(38752): Migrate to core sdk, gn sdk is deprecating. Var("dart_root") + "/third_party/fuchsia/sdk/linux": { "packages": [ { @@ -612,7 +617,20 @@ deps = { "version": Var("fuchsia_sdk_version"), } ], - "condition": 'host_os == "linux" and host_cpu == "x64"', + "condition": + 'download_fuchsia_deps and host_os == "linux" and host_cpu == "x64"', + "dep_type": "cipd", + }, + + Var("dart_root") + "/third_party/fuchsia/test_scripts": { + "packages": [ + { + "package": "chromium/fuchsia/test-scripts/fuchsia", + "version": "version:2@0d97902a72c9bc224f64630177cf95cd632604a2", + } + ], + "condition": + 'download_fuchsia_deps and host_os == "linux" and host_cpu == "x64"', "dep_type": "cipd", }, @@ -762,4 +780,15 @@ hooks = [ Var('emsdk_ver')], 'condition': 'download_emscripten' }, + { + 'name': 'Download Fuchsia system images', + 'pattern': '.', + 'action': [ + 'python3', + 'sdk/build/fuchsia/with_envs.py', + 'sdk/third_party/fuchsia/test_scripts/update_product_bundles.py', + 'terminal.qemu-x64', + ], + 'condition': 'download_fuchsia_deps' + }, ] diff --git a/build/fuchsia/with_envs.py b/build/fuchsia/with_envs.py new file mode 100755 index 00000000000..b98caa6718e --- /dev/null +++ b/build/fuchsia/with_envs.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +# Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +# for details. All rights reserved. Use of this source code is governed by a +# BSD-style license that can be found in the LICENSE file. + +import os +import platform +import subprocess +import sys + + +def Main(): + """ + Execute the test-scripts with required environment variables. It acts like + /usr/bin/env, but provides some extra functionality to dynamically set up + the environment variables. + """ + os.environ['SRC_ROOT'] = os.path.abspath( + os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) + os.environ['FUCHSIA_IMAGES_ROOT'] = os.path.join(os.environ['SRC_ROOT'], + 'third_party', 'fuchsia', + 'images') + sdk_dir = '' + if platform.system() == 'Linux': + sdk_dir = 'linux' + elif platform.system() == 'Darwin': + sdk_dir = 'mac' + else: + assert False, 'Unsupported OS' + os.environ['FUCHSIA_SDK_ROOT'] = os.path.join(os.environ['SRC_ROOT'], + 'third_party', 'fuchsia', + 'sdk', sdk_dir) + # TODO(zijiehe): Remove this experimental config after upgrading sdk to a + # version later than https://fxrev.dev/841540. + subprocess.call([ + os.path.join(os.environ['FUCHSIA_SDK_ROOT'], 'tools', 'x64', 'ffx'), + 'config', 'set', 'product.experimental', 'true' + ]) + subprocess.call(sys.argv[1:]) + + +if __name__ == '__main__': + sys.exit(Main()) diff --git a/pkg/test_runner/lib/src/fuchsia.dart b/pkg/test_runner/lib/src/fuchsia.dart index 5acaee13d68..90f4c7d2670 100644 --- a/pkg/test_runner/lib/src/fuchsia.dart +++ b/pkg/test_runner/lib/src/fuchsia.dart @@ -49,9 +49,11 @@ class FuchsiaEmulator { "terminal.qemu-$arch", "--name", emulatorName, - "--headless", + "--headless" ]); _run(ffx, [ + "-t", + emulatorName, "target", "repository", "register", @@ -64,11 +66,14 @@ class FuchsiaEmulator { static void stop() {} - static List getTestArgs(String mode, List arguments) { + static List getTestArgs( + String mode, String arch, List arguments) { arguments = arguments .map((arg) => arg.replaceAll(Repository.uri.toFilePath(), '/pkg/data/')) .toList(); return [ + "-device-name", + "dart-fuchsia-$mode-$arch", "run", "fuchsia-pkg://fuchsia.com/dart_ffi_test_$mode#meta/fuchsia_ffi_test_component.cmx", ...arguments diff --git a/pkg/test_runner/lib/src/runtime_configuration.dart b/pkg/test_runner/lib/src/runtime_configuration.dart index 0c3d86630dd..17f959ca9d2 100644 --- a/pkg/test_runner/lib/src/runtime_configuration.dart +++ b/pkg/test_runner/lib/src/runtime_configuration.dart @@ -480,8 +480,8 @@ class DartkFuchsiaEmulatorRuntimeConfiguration if (isCrashExpected) { arguments.insert(0, '--suppress-core-dump'); } - var runtimeArgs = - FuchsiaEmulator.getTestArgs(_configuration.mode.name, arguments); + var runtimeArgs = FuchsiaEmulator.getTestArgs( + _configuration.mode.name, _configuration.architecture.name, arguments); runtimeArgs.insert(runtimeArgs.length - 1, '--disable-dart-dev'); return [ VMCommand(FuchsiaEmulator.fsshTool, runtimeArgs, environmentOverrides)