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