Jayanth Dodderi Chidanand | 13ee0e0 | 2025-06-26 12:14:38 +0100 | [diff] [blame] | 1 | Hafnium Tests |
| 2 | ============= |
| 3 | |
| 4 | This guide explains how to build and run Hafnium tests on the Arm |FVP|, including |
| 5 | all necessary other firmware images, by using `Shrinkwrap`_. |
| 6 | These tests include Hafnium itself, as well as supporting components like TF-A, |
| 7 | secure partitions, and test payloads such as TFTF. |
| 8 | |
| 9 | Overview of Shrinkwrap for Hafnium Testing |
| 10 | ------------------------------------------ |
| 11 | |
| 12 | Shrinkwrap is a tool that makes it easier to build and run firmware on Arm FVP. |
| 13 | It provides a user-friendly command-line interface and, by default, uses a |
| 14 | container-based backend to manage the build environment. |
| 15 | It uses YAML-based configuration files to describe platform topology, firmware |
| 16 | components, and runtime parameters. These configurations can be easily customized |
| 17 | and extended through a built-in layering system. |
| 18 | |
| 19 | For further detailed information on the Shrinkwrap tool, including its design and usage, |
| 20 | refer to the `Quick Start Guide`_. |
| 21 | |
| 22 | Shrinkwrap Integration in hftest.py |
| 23 | ----------------------------------- |
| 24 | |
| 25 | Shrinkwrap is included in the Hafnium repository as a Git submodule at |
| 26 | ``third_party/shrinkwrap``. |
| 27 | |
| 28 | For test execution, all Shrinkwrap setup is handled internally by the |
| 29 | Hafnium test framework. The `hftest.py` script uses a helper class |
| 30 | (``ShrinkwrapManager``) to configure paths, generate overlays, and run |
| 31 | Shrinkwrap commands for each test. |
| 32 | |
| 33 | Manual configuration of environment variables or setup scripts is not |
| 34 | required. The `hftest.py` framework handles Shrinkwrap setup automatically in all |
| 35 | environments, including local development, Docker, and CI. |
| 36 | |
| 37 | To run Hafnium tests configured through the ``kokoro/`` test scripts, use the |
| 38 | following predefined Makefile targets: |
| 39 | |
| 40 | .. code:: shell |
| 41 | |
| 42 | make test_spmc # Runs the SPMC test suite |
| 43 | make test_el3_spmc # Runs the EL3 SPMC test suite |
| 44 | |
| 45 | These workflows are supported across local development, CI pipelines, and the |
| 46 | Hafnium Docker container provided under ``build/docker/``. |
| 47 | |
| 48 | These targets invoke test scripts under `kokoro/` directory, which then invokes |
| 49 | `hftest.py` with the appropriate configuration. Shrinkwrap is used under the |
| 50 | hood to build the FVP package and launch tests using both static and dynamic overlays. |
| 51 | |
| 52 | For example: |
| 53 | - ``kokoro/test_spmc.sh`` runs tests for Secure Partition Manager Component (SPMC) at S-EL1. |
| 54 | - ``kokoro/test_el3_spmc.sh`` runs tests for EL3-based SPMC setups (e.g., Hafnium at EL3). |
| 55 | |
| 56 | |
| 57 | Manual Shrinkwrap Environment Setup |
| 58 | ----------------------------------- |
| 59 | |
| 60 | If you intend to use Shrinkwrap manually, outside of `hftest.py` framework, you |
| 61 | can configure the environment using the following script: |
| 62 | |
| 63 | .. code:: shell |
| 64 | |
| 65 | source ./tools/shrinkwrap/shrinkwrap_setup_env.sh |
| 66 | |
| 67 | This script prepares the environment by: |
| 68 | |
| 69 | - Adding the Shrinkwrap CLI binary to your ``PATH`` |
| 70 | - Setting ``SHRINKWRAP_CONFIG`` to point to Hafnium’s overlay configs |
| 71 | - Setting ``SHRINKWRAP_BUILD`` and ``SHRINKWRAP_PACKAGE`` as the output directories for build artifacts |
| 72 | |
| 73 | .. note:: |
| 74 | |
| 75 | By default, if ${SHRINKWRAP_BUILD} and ${SHRINKWRAP_PACKAGE} are not set, |
| 76 | Shrinkwrap uses ``${HOME}/.shrinkwrap`` as its default output directory. |
| 77 | However, the provided setup script ``shrinkwrap_setup_env.sh`` overrides that |
| 78 | and places the build/package outputs under ``out/`` folder in the Hafnium |
| 79 | repository. You can modify these paths if needed. |
| 80 | |
| 81 | Shrinkwrap at the Core of the hftest Framework |
| 82 | ---------------------------------------------- |
| 83 | |
| 84 | The ``hftest`` Python framework now leverages `Shrinkwrap`_ to handle model |
| 85 | configuration and runtime arguments for FVP-based Hafnium tests. |
| 86 | This integration replaces manual argument generation with modular and declarative |
| 87 | YAML configurations, enhancing both clarity and maintainability. |
| 88 | |
| 89 | All Shrinkwrap-related functionality is handled internally by the |
| 90 | ``ShrinkwrapManager`` utility, which abstracts away the complexity of manual |
| 91 | setup and execution. |
| 92 | |
| 93 | The ``ShrinkwrapManager`` utility is responsible for: |
| 94 | |
| 95 | * Setting up the Shrinkwrap environment (e.g., config paths, build directories) |
| 96 | * Generating the dynamic overlay. |
| 97 | * Running the Shrinkwrap build phase once, using static overlays. |
| 98 | * Running the Shrinkwrap run phase individually for each test, with the appropriate dynamic overlay. |
| 99 | |
| 100 | Overlay Structure |
| 101 | ~~~~~~~~~~~~~~~~~ |
| 102 | |
| 103 | Overlays are an important concept in Shrinkwrap. They are configuration fragments |
| 104 | (typically YAML files) that are layered on top of a base configuration—either |
| 105 | during the build or run phase to compose, reuse, or override configuration logic |
| 106 | without duplicating YAML files. Overlays are always applied as the topmost layer |
| 107 | in the configuration stack, and can also be passed dynamically at runtime using |
| 108 | the ``--overlay`` command-line flag to selectively modify or extend existing setups |
| 109 | without altering the original configuration. |
| 110 | |
| 111 | In the context of Hafnium's ``hftest.py`` integration with Shrinkwrap, overlays |
| 112 | are applied in the following way: |
| 113 | |
| 114 | - **Static Overlays**: |
| 115 | |
| 116 | - Define reusable FVP-related configurations such as hypervisor preloading, |
| 117 | SPMC artifact addresses, debug flags, etc. |
| 118 | - Each test driver (e.g., `FvpDriverHypervisor`, `FvpDriverSPMC`, `FvpDriverEL3SPMC`) |
| 119 | contributes one or more static overlays. |
| 120 | - These are applied during the Shrinkwrap build phase and reside under: |
| 121 | ``tools/shrinkwrap/configs/kokoro/`` |
| 122 | |
| 123 | - Example overlays: |
| 124 | |
| 125 | - ``fvp_hf_hypervisor_preloaded.yaml`` |
| 126 | - ``fvp_hf_spmc_preloaded.yaml`` |
| 127 | - ``fvp_hf_debug.yaml`` (conditionally applied) |
| 128 | |
| 129 | - **Dynamic Overlay**: |
| 130 | |
| 131 | - Automatically generated by ``hftest.py`` at runtime. |
| 132 | - Applied during the **Shrinkwrap run phase** using: ``fvp_hf_dynamic_overlay.yaml`` |
| 133 | |
| 134 | - **Overlay Layering in Practice**: |
| 135 | |
| 136 | - Common FVP platform settings are defined in the base YAML: |
| 137 | ``FVP_Base_RevC-2xAEMvA-hafnium.yaml`` |
| 138 | - Static overlays provided by the test driver are layered **on top** of this |
| 139 | base during the ``shrinkwrap build`` phase. |
| 140 | - The dynamic overlay is layered **last**, during the ``shrinkwrap run`` phase, |
| 141 | and contains runtime values such as UART log paths, memory load addresses, |
| 142 | or test-specific artifacts. |
| 143 | |
| 144 | This overlay-based design promotes clean separation between reusable |
| 145 | infrastructure setup and per-test dynamic inputs. It improves configurability, |
| 146 | test maintenance, and makes it easy to add new test targets without repeating |
| 147 | model configuration. |
| 148 | |
| 149 | Testing Hafnium with TFTF |
| 150 | ------------------------- |
| 151 | |
| 152 | Outside of the Hafnium test framework (`hftest.py`), developers can use a standalone |
| 153 | Shrinkwrap configuration ``hafnium-tftf.yaml`` to build and run the full |
| 154 | Hafnium software stack. This configuration is designed to support day-to-day |
| 155 | integration testing of Hafnium alongside `TF-A`_ and `TF-A-Tests`_. |
| 156 | |
| 157 | The primary test payload from TF-A-Tests is the TFTF (Trusted Firmware Test |
| 158 | Framework) binary. The test setup also deploys the Cactus and Ivy secure partitions |
| 159 | to validate FF-A-based SPM functionality. |
| 160 | |
| 161 | In this setup: |
| 162 | |
| 163 | - TF-A runs at EL3 |
| 164 | - Hafnium runs at Secure EL2 |
| 165 | - Cactus and Ivy SPs (Secure Partitions) run at S-EL1 |
| 166 | - TFTF runs in the Normal World |
| 167 | |
| 168 | This configuration is ideal for validating SPMC behavior, FF-A interface support, |
| 169 | and overall system integration. |
| 170 | |
| 171 | Hafnium provides dedicated Makefile targets to build and run the ``hafnium-tftf.yaml`` |
| 172 | configuration using Shrinkwrap: |
| 173 | |
| 174 | .. code:: shell |
| 175 | |
| 176 | make test_tftf # Builds and runs the full configuration |
| 177 | make test_tftf_build # Only performs the Shrinkwrap build phase |
| 178 | make test_tftf_run # Runs the configuration on FVP after building |
| 179 | make test_tftf_clean # Cleans previously built Shrinkwrap artifacts |
| 180 | |
| 181 | When ``HAFNIUM_HERMETIC_BUILD=true`` is set, the above targets are executed inside |
| 182 | the Hafnium developer Docker container (``build/docker/``), with all dependencies |
| 183 | and the runtime environment preconfigured. |
| 184 | |
| 185 | These targets invoke corresponding rules from the ``kokoro.mk`` which run |
| 186 | ``shrinkwrap build`` and ``shrinkwrap run`` using the ``hafnium-tftf.yaml`` |
| 187 | configuration and its associated overlays. |
| 188 | |
| 189 | The build and run commands are also documented in detail within the corresponding |
| 190 | YAML configuration file. When you run the build command, Shrinkwrap stores external |
| 191 | repositories under the ``${SHRINKWRAP_BUILD}/sources/<CONFIG_NAME>`` directory. |
| 192 | |
| 193 | By using the ``hafnium-tftf.yaml`` custom configuration file, developers can |
| 194 | easily build and run SPM-related test suites through Shrinkwrap. |
| 195 | |
| 196 | *Copyright (c) 2025, Arm Limited. All rights reserved.* |
| 197 | |
| 198 | .. _Shrinkwrap: https://shrinkwrap.docs.arm.com |
| 199 | .. _Quick Start Guide: https://shrinkwrap.docs.arm.com/en/latest/userguide/quickstart.html#quick-start-guide |
| 200 | .. _TF-A: https://trustedfirmware-a.readthedocs.io/en/latest/ |
| 201 | .. _TF-A-Tests: https://trustedfirmware-a-tests.readthedocs.io/en/latest/index.html |