Testing Scenic and Escher


Information about testability:

Scenic test packages

You can specify packages in these ways:

  • Everything:

    --with //bundles/tests
  • Individually, if you want to build less packages:

    --with //src/ui:tests
    --with //src/ui/lib/escher:escher_tests

Scenic and CQ

Tests are automatically run before submission by trybots for every change in Fuchsia. See the fuchsia-x64-release and fuchsia-x64-asan bots on https://ci.chromium.org/p/fuchsia/builders.

Add a new test suite to existing CQ tests

Most of the Scenic and Escher tests are written in Googletest. If you need to add test suites or test cases, you need to create test source files and add them as a source of the test executables in corresponding BUILD.gn files.

Adding a test package to CQ

To add a test package to CQ, you need to:

  • Create test components;
  • Reference the test package;
  • Specify test environments.

Create test components

To add a new test package to CQ, you need to create a test component including source files, metadata and BUILD.gn file. See Test component. You can include multiple test executables in one single test package, and all of them will be executed if you run fx test <test_package> on host.

Examples of test packages:

Reference the test package

To ensure the test is run on CQ, it requires an unbroken chain of dependencies that roll up to your fx set command's available packages (expandable using the --with flag), typically going through the all target of //bundles/packages/tests:all.

You need to make sure that there is a dependency chain from //bundles/packages/tests:all to your test package. For more information, see Testing FAQ documentation.

Specify test environments

To ensure that the test is run on CQ, you also need to specify a test environment for each test executable in the package inside the test's BUILD.gn file.

Generally the environment is set to environments = basic_envs. This specifies the test should be run on both QEMU (for arm64), FEMU and NUC (for x64), and using both debug and release builds. For running on other environments, refer to Test environments.

Reference the test package transitively. For example, the packages above are referenced by //bundles/packages/tests:all through //bundles/packages/tests:scenic.

Unit tests and integration tests

To run tests locally during development:

Running on device/emulator

Some of these tests require the test Scenic to connect to the real display controller.

Run fx shell killall scenic.cm to kill an active instance of Scenic.

  • Run all Scenic tests:

    From host workstation, ensure fx serve is running, then:

      fx test \
        escher_tests \
        allocation_unittests \
        display_unittests \
        flatland_unittests \
        flatland_buffers_unittests \
        flatland_display_compositor_pixeltests \
        flatland_display_compositor_pixeltests_with_fake_display \
        flatland_engine_unittests \
        flatland_renderer_unittests \
        input_unittests \
        scenic_unittests \

    Or from Fuchsia target device:

    runtests --names escher_unittests,input_unittests,a11y_manager_apptests
  • Run a specific test binary:

    From host workstation, ensure fx serve is running, then use the following command to run the escher_unittests test component:

    fx test escher_unittests
  • Run a single test within a component:

    From host workstation, ensure fx serve is running, then:

    fx test escher_unittests -- --gtest_filter=NoOpMacTest.DummyTestCase

    See more documentation about the glob pattern for the filter arg.

  • Run a specific component

    From your host workstation:

    fx test fuchsia-pkg://fuchsia.com/escher_unittests#meta/escher_unittests.cm

Host tests

  • fx test --host runs all host tests, but you probably only want to run Escher tests.
  • Escher: To run escher_unittests locally on Linux: follow instructions in Escher documentation.

Manual UI tests

After making big Scenic changes, you may want to do manual UI testing by running some example applications to see if there is any regression.

UI Examples

There are some examples available:

  • flatland-view-provider
    • Basic example of serving ViewProvider and creating a UI using Flatland commands.
    • Source: //src/ui/examples/flatland-view-provider
    • Build dependency: //src/ui/examples/flatland-view-provider
    • Package URI: fuchsia-pkg://fuchsia.com/flatland-examples#meta/flatland-view-provider.cm

To run these applications, you need to include the following dependency in your fx set configuration:

fx set workstation_eng.x64 --with "//src/ui/examples"

Running UI examples

Running in shell

You can launch the stories (modules) in any shell you are in:

  • In Ermine shell, you can run modules by typing in the package name (e.g. flatland-view-provider) in the [ASK] bar to run modules.

  • Or, use command ffx session add <component_name> command to launch a component in the shell.

    From your host workstation, run:

    fx session add "fuchsia-pkg://fuchsia.com/flatland_examples#meta/flatland-view-provider.cm"

    to present the View provided in flatland-view-provider component.