Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9ce44ca
feat(test-framework): Add a README.md in the tests directory
miguelafsilva5 May 31, 2024
000a8be
feat(submodules): Add the test-framework (bao-test) repository
miguelafsilva5 Jun 3, 2024
af653ae
feat(submodules): Add the nix packages (bao-nix) repository
miguelafsilva5 Jun 3, 2024
3ed4587
feat(recipe): Add the main nix recipe file for a single baremetal
miguelafsilva5 Jun 3, 2024
62d9ce3
feat(recipe): Add the patch required to add tests to the baremetal
miguelafsilva5 Jun 3, 2024
53fd9a0
feat(recipe): Add bao configs for qemu riscv64 and aarch64
miguelafsilva5 Jun 3, 2024
e3ec76f
feat(recipe): Add basic boot test
miguelafsilva5 Jun 3, 2024
b2c4c3e
feat(test-framework): Add a tests rule to bao Makefile
miguelafsilva5 Jun 4, 2024
5d0b9bd
feat(test-framework): Add a makefile for the test framework
miguelafsilva5 May 31, 2024
5d136eb
fix: Suppress errors when including the ci.mk
miguelafsilva5 Jun 4, 2024
ac44b51
feat(submodules): Add the test-framework (bao-test) repository
miguelafsilva5 Jun 3, 2024
049b663
feat(recipe): Add the main nix recipe file for a single baremetal
miguelafsilva5 Jun 3, 2024
6819b0d
feat(recipe): Add the patch required to add tests to the baremetal
miguelafsilva5 Jun 3, 2024
e37898f
feat(recipe): Add bao configs for qemu riscv64 and aarch64
miguelafsilva5 Jun 3, 2024
5c28ae4
feat(recipe): Add basic boot test
miguelafsilva5 Jun 3, 2024
22ac6d6
feat(test-framework): Add a tests rule to bao Makefile
miguelafsilva5 Jun 4, 2024
a471931
fix: Suppress errors when including the ci.mk
miguelafsilva5 Jun 4, 2024
ae3afc5
feat(submodules): Add the nix recipes (bao-nix) repository
miguelafsilva5 Jul 17, 2024
1739cff
feat(irq_tests): add support to run IRQ tests (uart and timer)
Diogo21Costa Sep 4, 2024
8c7b4b8
feat(irq_tests): add support to run IRQ tests (uart and timer)
Diogo21Costa Sep 4, 2024
98265e6
add(uart_irq): update test to use command macro to send char
Diogo21Costa Sep 24, 2024
6271408
feat(tests): include timeout in IRQ tests
Diogo21Costa Sep 24, 2024
8800baa
fix(irq_test): update single baremetal tests
Diogo21Costa Apr 3, 2025
d37be4d
feat(test): add support to single freertos tests
Diogo21Costa Apr 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[submodule "ci"]
path = ci
url = [email protected]:bao-project/bao-ci.git
[submodule "tests/bao-tests"]
path = tests/bao-tests
url = [email protected]:bao-project/bao-tests.git
[submodule "tests/bao-nix"]
path = tests/bao-nix
url = [email protected]:bao-project/bao-nix.git
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ scripts_dir:=$(cur_dir)/scripts
ci_dir:=$(cur_dir)/ci
src_dirs:=

include $(ci_dir)/ci.mk
-include $(ci_dir)/ci.mk

targets:=$(MAKECMDGOALS)
ifeq ($(targets),)
targets:=all
endif
non_build_targets+=ci clean
non_build_targets+=ci clean tests
build_targets:=$(strip $(foreach target, $(targets), \
$(if $(findstring $(target),$(non_build_targets)),,$(target))))

Expand Down Expand Up @@ -342,3 +342,9 @@ $(call ci, format, $(all_c_files))

.PHONY: ci
ci: license-check format-check

tests_dir := $(cur_dir)/tests
-include $(tests_dir)/tests.mk

.PHONY: tests
tests: framework
135 changes: 135 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Bao Test Framework

## Overview

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.
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.



## How to use

**1. Create a folder inside `recipes` with the following structure**

```
tests
├── bao-tests
├── bao-nix
├── recipes
│ ├── RECIPE-EXAMPLE
│ │ ├── configs
│ │ ├── src
```

The name `RECIPE-EXAMPLE` will be used as an argument when using `make`.
The folder `configs` is used to store all the bao configs (link to docs) related to the recipe in question.
Lastly, the folder `src` is used for test sources.

**2. Create a `.nix` file in the `RECIPE-EXAMPLE` folder.**

The following code is an example of a Nix recipe to build the system with a single baremetal guest.

```nix
{
pkgs ? import (fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/refs/tags/22.11.tar.gz";
sha256 = "sha256:11w3wn2yjhaa5pv20gbfbirvjq6i3m7pqrq2msf0g7cv44vijwgw";
}) {},
platform ? " ",
bao_cfg_repo ? " ",
bao_cfg ? " ",
list_tests ? " ",
list_suites ? " ",
log_level ? " ",
GIC_VERSION ? " ",
IRQC ? " ",
IPIC ? " ",
}:

with pkgs;

let
packages = rec {

setup-cfg = callPackage ../../bao-nix/pkgs/setup-cfg/setup-cfg.nix{
inherit platform;
inherit GIC_VERSION;
inherit IRQC;
inherit IPIC;
bao-tests = ../../bao-tests;
tests_srcs = ./src;
baremetal_patch = ./baremetal.patch;
};

#Build toolchain
toolchain = callPackage ../../bao-nix/pkgs/toolchains/${setup-cfg.toolchain_name}.nix{};

#Build guests
guests = [
(callPackage (../../bao-nix/pkgs/guest/tf/baremetal.nix)
{
inherit setup-cfg;
inherit toolchain;
guest_name = "baremetal";
list_tests = "";
list_suites = "CPU_BOOT_CHECK";
inherit log_level;
}
)
];

bao_cfg_repo = ./configs;

#Build Hypervisor
bao = callPackage ../../bao-nix/pkgs/bao/bao.nix
{
inherit setup-cfg;
inherit toolchain;
inherit bao_cfg_repo;
inherit bao_cfg;
inherit guests;
#bao_srcs_path = /home/mafs/bao-hypervisor;
};

# Build Firmware
firmware = callPackage ../../bao-nix/pkgs/firmware/${platform}.nix {
inherit toolchain;
inherit platform;
inherit setup-cfg;
};
inherit pkgs;
};
in
packages

```

The main fields in the recipe that should be modified for other uses are:

* **guests** - This array should include all the the guest used in the bao configuration.
* **list_tests** - For each guest that will execute tests, this field should be filled with test names.
* **list_suits** - Similar to the previous field, but should be filled with suites (groups of tests) instead.

**3. Implement the tests**

Create a `.c` file in the `src` folder and implement the tests following the example below:

```c
#include "testf.h"

BAO_TEST(SUITE_NAME, TEST_NAME)
{
printf("Hello World!!!\n");
}
```

Every source file that implements tests should include the `testf.h` header.
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.

**4. Run the framework**

From the **bao-hypervisor** main directory, to run the test framework you should use the following command:

```
make tests PLATFORM=platform RECIPE=RECIPE_EXAMPLE
```
1 change: 1 addition & 0 deletions tests/bao-nix
Submodule bao-nix added at f9ab3c
1 change: 1 addition & 0 deletions tests/bao-tests
Submodule bao-tests added at 5dd718
32 changes: 32 additions & 0 deletions tests/recipes/single-baremetal/baremetal.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
diff --git a/setup.mk b/setup.mk
index 3a230aa..2edf9ee 100644
--- a/setup.mk
+++ b/setup.mk
@@ -29,6 +29,14 @@ src_dirs+=$(src_dir) $(core_dir) $(platform_dir)
SRC_DIRS+=$(src_dirs)
INC_DIRS+=$(addsuffix /inc, $(src_dirs))

+# Test framework setup
+include $(TESTF_REPO_DIR)/src/bao-test.mk
+SRC_DIRS+=$(TESTF_SRC_DIR) $(TESTF_TESTS_DIR)
+C_SRC+=$(TESTF_SRCS)
+INC_DIRS+=$(TESTF_INC_DIR)
+CFLAGS+=$(TESTF_FLAGS)
+# End of test framework setup
+
ifeq ($(wildcard $(platform_dir)),)
$(error unsupported platform $(PLATFORM))
endif
diff --git a/src/main.c b/src/main.c
index 9a9e972..69cfa6f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -54,6 +54,8 @@ void main(void){
printf("Bao bare-metal test guest\n");
spin_unlock(&print_lock);

+ testf_entry();
+
irq_set_handler(UART_IRQ_ID, uart_rx_handler);
irq_set_handler(TIMER_IRQ_ID, timer_handler);
irq_set_handler(IPI_IRQ_ID, ipi_handler);
58 changes: 58 additions & 0 deletions tests/recipes/single-baremetal/configs/qemu-aarch64-virt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <config.h>

VM_IMAGE(baremetal_image, XSTR(BAO_WRKDIR_IMGS/baremetal.bin))

struct config config = {

CONFIG_HEADER

.vmlist_size = 1,
.vmlist = (struct vm_config[]) {
{
.image = {
.base_addr = 0x50000000,
.load_addr = VM_IMAGE_OFFSET(baremetal_image),
.size = VM_IMAGE_SIZE(baremetal_image)
},

.entry = 0x50000000,

.platform = {
.cpu_num = 4,

.region_num = 1,
.regions = (struct vm_mem_region[]) {
{
.base = 0x50000000,
.size = 0x4000000
}
},

.dev_num = 2,
.devs = (struct vm_dev_region[]) {
{
/* PL011 */
.pa = 0x9000000,
.va = 0x9000000,
.size = 0x10000,
.interrupt_num = 1,
.interrupts = (irqid_t[]) {33}
},
{
/* Arch timer interrupt */
.interrupt_num = 1,
.interrupts =
(irqid_t[]) {27}
}
},

.arch = {
.gic = {
.gicd_addr = (paddr_t) 0x08000000,
.gicr_addr = (paddr_t) 0x080A0000,
}
}
},
}
},
};
52 changes: 52 additions & 0 deletions tests/recipes/single-baremetal/configs/qemu-riscv64-virt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <config.h>

VM_IMAGE(baremetal_image, XSTR(BAO_WRKDIR_IMGS/baremetal.bin))

struct config config = {

CONFIG_HEADER

.vmlist_size = 1,
.vmlist = (struct vm_config[]) {
{
.image = {
.base_addr = 0x80200000,
.load_addr = VM_IMAGE_OFFSET(baremetal_image),
.size = VM_IMAGE_SIZE(baremetal_image)
},

.entry = 0x80200000,

.platform = {
.cpu_num = 4,

.region_num = 1,
.regions = (struct vm_mem_region[]) {
{
.base = 0x80200000,
.size = 0x4000000
}
},

.dev_num = 1,
.devs = (struct vm_dev_region[]) {
{
.pa = 0x10000000,
.va = 0x10000000,
.size = 0x1000,
.interrupt_num = 1,
.interrupts = (irqid_t[]) {10}
},
},

.arch = {
.irqc = {
.plic = {
.base = 0xc000000,
},
},
},
},
},
}
};
71 changes: 71 additions & 0 deletions tests/recipes/single-baremetal/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
pkgs ? import (fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/refs/tags/22.11.tar.gz";
sha256 = "sha256:11w3wn2yjhaa5pv20gbfbirvjq6i3m7pqrq2msf0g7cv44vijwgw";
}) {},
platform ? " ",
bao_cfg_repo ? " ",
bao_cfg ? " ",
list_tests ? " ",
list_suites ? " ",
log_level ? " ",
GIC_VERSION ? " ",
IRQC ? " ",
IPIC ? " ",
}:

with pkgs;

let
packages = rec {

setup-cfg = callPackage ../../bao-nix/pkgs/setup-cfg/setup-cfg.nix{
inherit platform;
inherit GIC_VERSION;
inherit IRQC;
inherit IPIC;
bao-tests = ../../bao-tests;
tests_srcs = ./src;
baremetal_patch = ./baremetal.patch;
};

#Build toolchain
toolchain = callPackage ../../bao-nix/pkgs/toolchains/${setup-cfg.toolchain_name}.nix{};

#Build guests
guests = [
(callPackage (../../bao-nix/pkgs/guest/tf/baremetal.nix)
{
inherit setup-cfg;
inherit toolchain;
guest_name = "baremetal";
list_tests = "";
list_suites = "CPU_BOOT_CHECK IRQ_CHECK";
inherit log_level;
}
)
];

bao_cfg_repo = ./configs;

#Build Hypervisor
bao = callPackage ../../bao-nix/pkgs/bao/bao.nix
{
inherit setup-cfg;
inherit toolchain;
inherit bao_cfg_repo;
inherit bao_cfg;
inherit guests;
#bao_srcs_path = /home/mafs/bao-hypervisor;
};

# Build Firmware
firmware = callPackage ../../bao-nix/pkgs/firmware/${platform}.nix {
inherit toolchain;
inherit platform;
inherit setup-cfg;
};
inherit pkgs;
};
in
packages
Loading