This guide provides instructions on how to contribute a test to CTS.
An ABI test is a test that verifies the ABI or runtime behavior of an API in the SDK. These tests are distributed as Fuchsia packages containing test components and run entirely on the target device.
The structure of the //sdk/cts
directory mirrors the structure of SDK artifacts. Your test should go in the same directory as the interface under test is found in an SDK. For example:
Tests for... | Should go in... |
---|---|
Host tools | //sdk/cts/tests/tools |
FIDL interfaces | //sdk/cts/tests/fidl |
Libraries | //sdk/cts/tests/pkg |
See existing tests under //sdk/cts/tests
for examples.
Note: The CTS build templates verify that dependencies are released in an SDK. If your test needs an exception, file a bug in DeveloperExperience>CTS
. The allow list can be found here.
In your test directory's BUILD.gn
file, create a test executable using CTS build templates.
{C/C++}
import("//sdk/cts/build/cts.gni") cts_executable("my_test_binary") { deps = [ "//zircon/system/ulib/zxtest" ] sources = [ "my_test.cc" ] testonly = true }
{Rust}
import("//sdk/cts/build/cts.gni") cts_rustc_test("my_test_binary") { edition = "2018" source_root = "src/my_test.rs" sources = [ "src/my_test.rs" ] }
Note: This section assumes familiarity with the concept of Test Components.
// my_test_component.cml { include: [ // Select the appropriate test runner shard here: // rust, elf, etc. "//src/sys/test_runners/rust/default.shard.cml", ], program: { binary: "bin/my_test_binary", }, facets: { // mark your test type "cts". "fuchsia.test": { type: "cts" }, }, ... }
Wrap your executable as a Fuchsia component. CTS provides a special GN template for creating a component:
cts_fuchsia_component("my_test_component") { testonly = true manifest = "meta/my_test_component.cml", deps = [ ":my_test_binary" ] }
CTS also provides a special GN template for creating a test package:
cts_fuchsia_test_package("my_test") { package_name = "my_test" test_components = [ ":my_test_component" ] }
These instructions require you to open several terminal tabs.
fx vdl start --headless
--headless
disables graphical output.fx serve
This step is useful for debugging your test.
ffx log
-v
enables verbose output.See the section about “Debugging tips” below.
This step involves building the CTS in the same way that our CI does when it is released, then running those CTS tests in your local checkout. It is necessary because upon release, we automatically rewrite each CTS test package‘s name to deduplicate it from the same package’s name at HEAD (the build does not allow duplicate names) and we must verify that the test still passes after this rewrite.
Follow the instructions in Step 4 to start an emulator and a package server, then launch a new terminal and run the following command:
$FUCHSIA_DIR/sdk/cts/build/scripts/verify_release/verify_release.py
This command will build the CTS archive, release it to your //prebuilt/cts/test/*
directory, and run the tests contained therein. After a brief pause, the test results will be printed to the terminal window.
To learn more about that script, or to run the commands manually, please see //sdk/cts/build/scripts/verify_release/README.md.
Some common causes of test failure at this stage include:
deps
.If you need additional help debugging at this step, please reach out to the CTS team by filing a bug in the CTS bug component.
This step causes the version of your test from Fuchsia‘s HEAD commit to run as part of Fuchsia’s presumbit queue. It does not include your test in the CTS release (See the next section).
Add a “tests” group to your BUILD file:
group("tests") { testonly = true deps = [ ":my_test" ] }
Next add this target as a dependency to the closest ancestor group("tests")
target.
This step includes your test in the CTS release, which guarantees that your test cannot be broken between Fuchsia milestone releases (typically made every six weeks).
Add an sdk_molecule
target and use it to mark all of your test packages for inclusion in CTS. Each cts_*
template declares an sdk_atom
or sdk_molecule
target with the name ${target_name}_sdk
. List each of the test packages as dependencies:
sdk_molecule("test_sdks") { testonly = true deps = [ ":my_test_sdk" ] }
Next add this target as a dependency to the closest ancestor sdk_molecule("test_sdks")
.
Once these steps are complete, submit your change and you should see your test run as part of the next CTS release.
ffx component list -v
to inspect its current state.Please see the FAQ section about retiring tests.
Please see the FAQ section about disabling tests.