[testing] Include full Fuchsia SDK in testing env.

Upload `@fuchsia_sdk//:all_files` to the testing environment for
non-host test groups.

This helps ensure that we don't run into unexpected issues in
infrastructure since we generally cannot assume that SDK tooling will
function correctly when only a subset of the SDK exists in runtime.

Also, this is what we do in-tree in infrastructure anyways.

See https://fxrev.dev/1009182.

Change-Id: Ib9353e8ef3ec2461e3a76e066017d51173cc5b22
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia-infra-bazel-rules/+/1010372
Reviewed-by: Chase Latta <chaselatta@google.com>
Reviewed-by: Jiaming Li <lijiaming@google.com>
Commit-Queue: Darren Chan <chandarren@google.com>
diff --git a/infra/private/testing/fuchsia_host_test_group.bzl b/infra/private/testing/fuchsia_host_test_group.bzl
index b5dfe52..4be0aac 100644
--- a/infra/private/testing/fuchsia_host_test_group.bzl
+++ b/infra/private/testing/fuchsia_host_test_group.bzl
@@ -13,6 +13,7 @@
         name,
         environment_setup = [],
         deps = [],
+        non_test_deps = [],
         asan_enabled = False,
         hermetic = True,
         tags = [],
@@ -46,6 +47,8 @@
         environment_setup: A list of target actions to run before tests.
           Requires `hermetic = False`.
         deps: A list of tests to run in this test group.
+        non_test_deps: Non-test runtime file dependencies to include in the
+          testing environment.
         asan_enabled: Whether to build the `deps` with asan.
         hermetic: Controls whether this test group is automatically resharded.
         tags: Typical meaning in Bazel.
@@ -57,6 +60,7 @@
         product_bundle = None,
         environment_setup = environment_setup,
         deps = deps,
+        non_test_deps = non_test_deps,
         hermetic = hermetic,
         asan_enabled = asan_enabled,
         tags = tags + BUILDDEF.tags,
diff --git a/infra/private/testing/fuchsia_test_group.bzl b/infra/private/testing/fuchsia_test_group.bzl
index 406af92..af7c8ab 100644
--- a/infra/private/testing/fuchsia_test_group.bzl
+++ b/infra/private/testing/fuchsia_test_group.bzl
@@ -20,6 +20,7 @@
         product_bundle,
         environment_setup = [],
         deps = [],
+        non_test_deps = [],
         asan_enabled = False,
         hermetic = True,
         tags = [],
@@ -62,6 +63,8 @@
         environment_setup: A list of target actions to run before tests.
           Requires `hermetic = False`.
         deps: A list of tests to run in this test group.
+        non_test_deps: Non-test runtime file dependencies to include in the
+          testing environment.
         asan_enabled: Whether to build the `deps` with asan.
         hermetic: Controls whether this test group is automatically resharded.
         tags: Typical meaning in Bazel.
@@ -91,6 +94,7 @@
         local_product_bundle = local_product_bundle,
         environment_setup = environment_setup,
         deps = deps,
+        non_test_deps = non_test_deps + ["@fuchsia_sdk//:all_files"],
         hermetic = hermetic,
         asan_enabled = asan_enabled,
         tags = tags + BUILDDEF.tags,
@@ -164,9 +168,9 @@
         ),
         runfiles = [
             ctx.attr._run_tests_tool,
-            _runfiles_for_test_target(sdk, test_target),
             local_pb,
             ctx.attr.environment_setup,
+            ctx.attr.non_test_deps,
             ctx.attr.deps,
         ],
         environment_setup = [
@@ -230,32 +234,6 @@
                     expected_cpu,
                 ))
 
-def _runfiles_for_test_target(sdk, test_target):
-    runfiles = []
-
-    # Common runfiles for testing on fuchsia.
-    if test_target.is_fuchsia:
-        runfiles += [
-            sdk.ffx,
-            sdk.sdk_manifest,
-
-            # Needed for ffx log.
-            sdk.symbolizer,
-            sdk.symbolizer_manifest,
-            sdk.symbol_index_config,
-        ]
-
-    # Needed to launch an emulator.
-    if test_target.is_emulator:
-        runfiles += [
-            sdk.aemu_runfiles,
-            sdk.fvm,
-            sdk.fvm_manifest,
-            sdk.zbi,
-            sdk.zbi_manifest,
-        ]
-    return runfiles
-
 def _local_test_orchestration_executable(ctx, test_manifest):
     """Generates an executable capable of running the global test manifest."""
 
@@ -312,6 +290,9 @@
         "asan_enabled": attr.bool(
             doc = "Determines if the tests in this group should run under ASAN.",
         ),
+        "non_test_deps": attr.label_list(
+            doc = "Non-test runtime file dependencies to include in the testing environment.",
+        ),
         "experiments_INTERNAL_USE_ONLY": attr.string_list(
             doc = "Configure experiments to enable for this test group. Unsupported, for internal use only.",
         ),
diff --git a/infra/private/utils.bzl b/infra/private/utils.bzl
index b33a629..c3af8a0 100644
--- a/infra/private/utils.bzl
+++ b/infra/private/utils.bzl
@@ -63,6 +63,7 @@
     for elem in flatten(elements):
         if type(elem) == "Target":
             runfiles.append(elem[DefaultInfo].default_runfiles)
+            runfiles.append(ctx.runfiles(elem[DefaultInfo].files.to_list()))
             files_to_run = elem[DefaultInfo].files_to_run
             if files_to_run.executable and files_to_run.runfiles_manifest:
                 runfiles.append(ctx.runfiles([