blob: b7b8c931a28d1b72d0bda701e58837a8e1599320 [file] [log] [blame] [view]
Andrew Scull23042042018-08-22 17:44:56 +01001# Testing
2
Andrew Walbraneffa9472019-08-05 13:29:29 +01003## Overview
4
5Hafnium has 4 main kinds of tests:
6
71. Host tests
8 * Unit tests of core functionality, e.g. page table manipulation.
9 * Source in `src/*_test.cc`.
10 * Using the [Google Test](https://github.com/google/googletest) framework,
11 built against 'fake' architecture (`src/arch/fake`).
121. Arch tests
13 * Architecture-specific unit tests, e.g. MMU setup.
14 * Source under `test/arch`.
15 * Using our own _hftest_ framework, with `standalone_main.c`.
16 * Build own hypervisor image, run in EL2.
171. VM API tests
18 * Exercise hypervisor API from both primary and secondary VMs.
19 * Source under `test/vmapi`.
20 * Tests are run from the primary VM under a normal build of the Hafnium
21 hypervisor, possibly communicating with a helper service in one or more
22 secondary VMs.
23 * Using our own _hftest_ framework, with `standalone_main.c` for the
24 primary VM and `hftest_service.c` for secondary VMs.
25 * Build own primary and secondary VMs, run in EL1 under actual Hafnium
26 image.
271. Linux tests
28 * Exercise the Hafnium Linux kernel module.
29 * Source under `test/linux`.
30 * Tests are run from userspace (PID 1) under Linux in the primary VM under
31 Hafnium, possibly with other secondary VMs.
32 * Using our own _hftest_ framework, with `linux_main.c`.
33
34Host tests run directly on the host machine where they are built, whereas the
35other 3 types can run under an emulator such as QEMU, or on real hardware.
Andrew Scull23042042018-08-22 17:44:56 +010036
37## Presubmit
38
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010039Presubmit builds everything, runs all tests and checks the source for formatting
40and lint errors. This can be run locally with:
Andrew Scull23042042018-08-22 17:44:56 +010041
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010042```shell
Andrew Scull23042042018-08-22 17:44:56 +010043./kokoro/ubuntu/build.sh
44```
45
46Or to just run the tests after having built everything manually run:
47
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010048```shell
Andrew Scull23042042018-08-22 17:44:56 +010049./kokoro/ubuntu/test.sh
50```
51
52## QEMU tests
53
54These tests boot Hafnium on QEMU and the VMs make calls to Hafnium to test its
Andrew Walbranfe7d32d2019-08-05 14:25:56 +010055behaviour. They can also be run on the Arm [FVP](FVP.md) and in some cases on
56real hardware.
Andrew Scull23042042018-08-22 17:44:56 +010057
Andrew Walbraneffa9472019-08-05 13:29:29 +010058### hftest
Andrew Scull23042042018-08-22 17:44:56 +010059
Andrew Walbraneffa9472019-08-05 13:29:29 +010060Having a framework for tests makes them easier to read and write. _hftest_ is a
Andrew Scull23042042018-08-22 17:44:56 +010061framework to meet the needs of VM based tests for Hafnium. It consists of:
62
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010063* assertions
64* test declarations
65* base VM image
66* driver script
Andrew Scull23042042018-08-22 17:44:56 +010067
68Assertions should be familiar from other testing libraries. They make use of
69C11's `_Generic` expressions for type genericity.
70
71Test declarations name the test and the suite that the test is part of.
72Declarations are converted into descriptors stored in the `.hftest` section of
73the VM image which allows the image to inspect the structure of the tests it
74contains. The linker sorts the descriptors by their symbol name which is how
75descriptors from the same suite are grouped together for easier parsing.
76
77The base VM image offers a command line interface, via the bootargs, to query
78the tests in the image and to run specific tests. The driver script uses this
79interface to execute tests, each with a fresh QEMU boot to give a fresh
80environment.