|
| 1 | +# Bao Test Framework |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The primary goal of the Bao Test Framework is to provide the infrastructure for the testing process of Bao Project components. It encompasses three core components: (i) a C library designed for real-time test handling, (ii) a Python tool for comprehensive test management, and (iii) a build system based on Nix. |
| 6 | +The C library and Python tool are provided in the `bao-tests` repository while the Nix packages required are available in the `bao-nix` repository. Lastly, a folder `recipes` contains all the recipes and tests. |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +## How to use |
| 11 | + |
| 12 | +**1. Create a folder inside `recipes` with the following structure** |
| 13 | + |
| 14 | +``` |
| 15 | + tests |
| 16 | + ├── bao-tests |
| 17 | + ├── bao-nix |
| 18 | + ├── recipes |
| 19 | + │ ├── RECIPE-EXAMPLE |
| 20 | + │ │ ├── configs |
| 21 | + │ │ ├── src |
| 22 | +``` |
| 23 | + |
| 24 | +The name `RECIPE-EXAMPLE` will be used as an argument when using `make`. |
| 25 | +The folder `configs` is used to store all the bao configs (link to docs) related to the recipe in question. |
| 26 | +Lastly, the folder `src` is used for test sources. |
| 27 | + |
| 28 | +**2. Create a `.nix` file in the `RECIPE-EXAMPLE` folder.** |
| 29 | + |
| 30 | +The following code is an example of a Nix recipe to build the system with a single baremetal guest. |
| 31 | + |
| 32 | +```nix |
| 33 | +{ |
| 34 | + pkgs ? import (fetchTarball { |
| 35 | + url = "https://github.com/NixOS/nixpkgs/archive/refs/tags/22.11.tar.gz"; |
| 36 | + sha256 = "sha256:11w3wn2yjhaa5pv20gbfbirvjq6i3m7pqrq2msf0g7cv44vijwgw"; |
| 37 | + }) {}, |
| 38 | + platform ? " ", |
| 39 | + bao_cfg_repo ? " ", |
| 40 | + bao_cfg ? " ", |
| 41 | + list_tests ? " ", |
| 42 | + list_suites ? " ", |
| 43 | + log_level ? " ", |
| 44 | + GIC_VERSION ? " ", |
| 45 | + IRQC ? " ", |
| 46 | + IPIC ? " ", |
| 47 | +}: |
| 48 | +
|
| 49 | +with pkgs; |
| 50 | +
|
| 51 | +let |
| 52 | + packages = rec { |
| 53 | +
|
| 54 | + setup-cfg = callPackage ../../bao-nix/pkgs/setup-cfg/setup-cfg.nix{ |
| 55 | + inherit platform; |
| 56 | + inherit GIC_VERSION; |
| 57 | + inherit IRQC; |
| 58 | + inherit IPIC; |
| 59 | + bao-tests = ../../bao-tests; |
| 60 | + tests_srcs = ./src; |
| 61 | + baremetal_patch = ./baremetal.patch; |
| 62 | + }; |
| 63 | +
|
| 64 | + #Build toolchain |
| 65 | + toolchain = callPackage ../../bao-nix/pkgs/toolchains/${setup-cfg.toolchain_name}.nix{}; |
| 66 | +
|
| 67 | + #Build guests |
| 68 | + guests = [ |
| 69 | + (callPackage (../../bao-nix/pkgs/guest/tf/baremetal.nix) |
| 70 | + { |
| 71 | + inherit setup-cfg; |
| 72 | + inherit toolchain; |
| 73 | + guest_name = "baremetal"; |
| 74 | + list_tests = ""; |
| 75 | + list_suites = "CPU_BOOT_CHECK"; |
| 76 | + inherit log_level; |
| 77 | + } |
| 78 | + ) |
| 79 | + ]; |
| 80 | +
|
| 81 | + bao_cfg_repo = ./configs; |
| 82 | + |
| 83 | + #Build Hypervisor |
| 84 | + bao = callPackage ../../bao-nix/pkgs/bao/bao.nix |
| 85 | + { |
| 86 | + inherit setup-cfg; |
| 87 | + inherit toolchain; |
| 88 | + inherit bao_cfg_repo; |
| 89 | + inherit bao_cfg; |
| 90 | + inherit guests; |
| 91 | + #bao_srcs_path = /home/mafs/bao-hypervisor; |
| 92 | + }; |
| 93 | +
|
| 94 | + # Build Firmware |
| 95 | + firmware = callPackage ../../bao-nix/pkgs/firmware/${platform}.nix { |
| 96 | + inherit toolchain; |
| 97 | + inherit platform; |
| 98 | + inherit setup-cfg; |
| 99 | + }; |
| 100 | + inherit pkgs; |
| 101 | + }; |
| 102 | +in |
| 103 | + packages |
| 104 | +
|
| 105 | +``` |
| 106 | + |
| 107 | +The main fields in the recipe that should be modified for other uses are: |
| 108 | + |
| 109 | +* **guests** - This array should include all the the guest used in the bao configuration. |
| 110 | +* **list_tests** - For each guest that will execute tests, this field should be filled with test names. |
| 111 | +* **list_suits** - Similar to the previous field, but should be filled with suites (groups of tests) instead. |
| 112 | + |
| 113 | +**3. Implement the tests** |
| 114 | + |
| 115 | +Create a `.c` file in the `src` folder and implement the tests following the example below: |
| 116 | + |
| 117 | +```c |
| 118 | +#include "testf.h" |
| 119 | + |
| 120 | +BAO_TEST(SUITE_NAME, TEST_NAME) |
| 121 | +{ |
| 122 | + printf("Hello World!!!\n"); |
| 123 | +} |
| 124 | +``` |
| 125 | +
|
| 126 | +Every source file that implements tests should include the `testf.h` header. |
| 127 | +A test is defined using the macro `BAO_TEST` with `SUITE_NAME` and `TEST_NAME` as arguments to identify the test in the previous step. |
| 128 | +
|
| 129 | +**4. Run the framework** |
| 130 | +
|
| 131 | +From the **bao-hypervisor** main directory, to run the test framework you should use the following command: |
| 132 | +
|
| 133 | +``` |
| 134 | +make tests PLATFORM=platform RECIPE=RECIPE_EXAMPLE |
| 135 | +``` |
0 commit comments