tree: d2e9c7f50ba56e841fe630e662ac732cc38f072e [path history] [tgz]
  1. examples/
  2. fuchsia/
  3. scripts/
  4. sdk_generation/
  5. test_utils/
  6. tools/
  7. .bazelrc
  8. .gitignore
  9. BUILD.bazel
  10. MODULE.bazel
  11. README.md
  12. WORKSPACE.bazel
  13. WORKSPACE.bzlmod
build/bazel_sdk/tests/README.md

Fuchsia Bazel SDK Tests

This directory contains tests meant to test the Fuchsia Bazel SDK. These currently require to be in a Fuchsia checkout.

The test suite can be run against three types of inputs:

  • A local IDK export directory.

    This is currently how the Core IDKs, generated by the Fuchsia build, are validated before uploading them to cloud storage.

  • A local Bazel SDK directory.

    This is currently how the Core Bazel SDKs, generated by the Fuchsia build, are validated before uploading them to cloud storage.

    This can also be used to run the test suite against the final Fuchsia in-tree SDK, as defined in //build/bazel/bazel_sdk/README.md.

  • The content of the @fuchsia_sdk repository in the Fuchsia in-tree platform build, which itself depends on the content of the @fuchsia_in_tree_idk repository.

Simple invocation with fx build

The simplest way to run the test suite is to use the following fx build command from a Fuchsia checkout:

  • fx build bazel_sdk_tests:

    Setup the Fuchsia in-tree @fuchsia_sdk repository and its dependencies, then run the test suite against it. This is useful during development of the Bazel rules themselves, or when modifying the content of the IDK/SDK.

    Note that no tests are ever run against the @sdk_internal repository of the in-tree Bazel workspace.

  • fx build //build/bazel/bazel_sdk:final_fuchsia_sdk.validation

    Build the final Fuchsia in-tree SDK, which mirrors the content of @fuchsia_sdk in a directly usable form, then run the test suiteagainst it. In terms of test and feature coverage, this should be equivalent to building bazel_sdk_tests.

  • fx build //sdk:final_fuchsia_idk.validation:

    Build the Fuchsia Core IDK, then run the test suite against it.

    NOTE: Building the Core IDK is very long, this is usually only performed on dedicated CI builders (e.g. sdk-core-linux).

  • fx build //sdk:final_fuchsia_sdk.validation:

    Build the Fuchsia Core Bazel SDK, then run the test suite against it.

    NOTE: Building the Core Bazel SDK is very long, this is usually only performed on dedicated CI builders (e.g. sdk-bazel-linux).

    NOTE: This target is called implicitly when building //sdk:final_fuchsia_sdk.

All these targets ensure that their pre-requisites are available, that builds are properly hermetic and also incrementally correct. However, they will run the full test suite every time (i.e. will not allow you to run an individual test).

Because Bazel caches test results, this can still be moderately fast during development.

Custom invocation with scripts/bazel_test.py

Another way is to prepare your Fuchsia build, then invoking scripts/bazel_test.py manually. You can use --test_target=<label> to select an individual test target (instead of all of them), or even pass extra arguments using -- <extra_args>.

The script ensures that the test workspace uses all vendored prebuilts and Bazel rules from the Fuchsia checkout, and never download anything from the network.

Running against a local IDK export dir:

# Prepare the Core IDK (beware: this takes > 20minutes).
fx build //sdk:final_fuchsia_idk.exported
LOCAL_IDK="$(fx get-build-dir)/sdk/exported/fuchsia_idk"

# Run the full test suite
scripts/bazel_test.py \
    --fuchsia_idk_directory="${LOCAL_IDK}" \
    --target_cpu=x64

# Run a subset of test targets, and change test output.
scripts/bazel_test.py \
    --fuchsia_idk_directory="${LOCAL_IDK}" \
    --target_cpu=x64 \
    --test_target=:build_only_tests -- --test_output=streamed

Alternatively, run it against the final Fuchsia in-tree IDK, which is only useful for Fuchsia build developers:

# Prepare the final Fuchsia in-tree IDK
fx build //build/bazel:final_fuchsia_in_tree_idk
LOCAL_IDK="$(fx get-build-dir)/gen/build/bazel/fuchsia_in_tree_idk"

# Run the full test suite
scripts/bazel_test.py \
    --fuchsia_idk_directory="${LOCAL_IDK}" \
    --target_cpu=x64

Running against a local Bazel SDK directory (not @fuchsia_sdk):

# Generate the final Fuchsia in-tree SDK
fx build generate_fuchsia_sdk_repository
LOCAL_SDK="$(fx get-build-dir)/gen/build/bazel/fuchsia_sdk"

# Run the full test suite
scripts/bazel_test.py --fuchsia_sdk_directory="${LOCAL_SDK}"

Alternatively, run it against the Core Bazel SDK

# Generate the Core Bazel SDK (beware: this takes > 20minutes)
fx build //sdk:final_fuchsia_sdk
LOCAL_SDK="$(fx get-build-dir)/obj/sdk/final_fuchsia_sdk"

# Run the full test suite
scripts/bazel_test.py --fuchsia_sdk_directory="${LOCAL_SDK}"

Running against the in-tree @fuchsia_sdk repository:

Note that this is only needed by Fuchsia developers modify the Bazel rules or the content of the in-tree IDK/SDK. Testing against the final Fuchsia in-tree SDK, as described in the previous section, should be equivalent:

# Prepare the @fuchsia_sdk repository. Only needed once per `jiri update`
fx build bazel_workspace
fx bazel --query --config=quiet @fuchsia_sdk//:BUILD.bazel

# Run the full test suite
scripts/bazel_test.py --fuchsia-in-tree-sdk

# Run a subset of test targets, and change test output.
scripts/bazel_test.py \
    --fuchsia-in-tree-sdk \
    --test_target=:build_only_tests -- --test_output=streamed

Direct bazel invocation

Finally, it is possible to directly invoke bazel test in this directory after some necessary preparation.

TODO: Fix Bazel 8.0 invocation.

Running against a local IDK:

This requires setting the LOCAL_FUCHSIA_IDK_DIRECTORY environment variable when calling Bazel. For example, when using the final in-tree IDK:

fx build //build/bazel:final_fuchsia_in_tree_idk
IDK="$(fx get-build-dir)/gen/build/bazel/fuchsia_in_tree_idk"
LOCAL_FUCHSIA_IDK_DIRECTORY="${IDK}" bazel test --config=fuchsia_x64 :tests

Or for the Core IDK:

fx build //sdk:final_fuchsia_idk.exported
IDK="$(fx get-build-dir)/sdk/exported/final_fuchsia_idk
LOCAL_FUCHSIA_IDK_DIRECTORY="${IDK}" bazel test --config=fuchsia_x64 :tests

Running against the final Fuchsia in-tree SDK:

This is the simplest and recommended way. It requires setting the LOCAL_FUCHSIA_PLATFORM_BUILD environment variable to your Fuchsia build directory as in:

# Preparation steps (only do this once)
cd /work/fuchsia
fx set core.x64

# Do this after each `jiri update` or modifying the SDK
fx build generate_fuchsia_sdk_repository

# Run the test suite
cd build/bazel_sdk/tests
LOCAL_FUCHSIA_PLATFORM_BUILD=$(fx get-build-dir) bazel test --config=fuchsia_x64 :tests

Running against the @fuchsia_sdk repository:

This is only mentioned here for completeness, as this is only useful for Fuchsia build developers when debugging changes to the in-tree Bazel workspace itself, even though using scripts/bazel_test.py would be simpler to do the same.

This requires overriding two repositories, for reasons explained in //build/bazel/bazel_sdk/README.md:

# Preparation steps is slightly different
cd /work/fuchsia
fx set core.x64
fx build bazel_workspace
fx bazel --query --config=quiet @fuchsia_sdk//:BUILD.bazel

OUTPUT_BASE="$(fx get-build-dir)/gen/build/bazel/output_base"
FUCHSIA_SDK_REPO="${OUTPUT_BASE}/external/fuchsia_sdk"
FUCHSIA_IN_TREE_IDK_REPO="${OUTPUT_BASE}/external/fuchsia_in_tree_idk"

# Run the test suite
bazel test \
    --config=fuchsia_x64 \
    --override_repository=fuchsia_sdk="${FUCHSIA_SDK_REPO}" \
    --override_repository=fuchsia_in_tree_idk="${FUCHSIA_IN_TREE_IDK_REPO}" \
    :tests