Hafnium has 4 main kinds of tests:
src/*_test.cc
.src/arch/fake
).test/arch
.standalone_main.c
.test/vmapi
.standalone_main.c
for the primary VM and hftest_service.c
for secondary VMs.test/linux
.linux_main.c
.Host tests run directly on the host machine where they are built, whereas the other 3 types can run under an emulator such as QEMU, or on real hardware.
Presubmit builds everything, runs all tests and checks the source for formatting and lint errors. This can be run locally with:
./kokoro/ubuntu/build.sh
Or to just run the tests after having built everything manually run:
./kokoro/ubuntu/test.sh
These tests boot Hafnium on QEMU and the VMs make calls to Hafnium to test its behaviour. They can also be run on the Arm FVP and in some cases on real hardware.
Having a framework for tests makes them easier to read and write. hftest is a framework to meet the needs of VM based tests for Hafnium. It consists of:
Assertions should be familiar from other testing libraries. They make use of C11's _Generic
expressions for type genericity.
Test declarations name the test and the suite that the test is part of. Declarations are converted into descriptors stored in the .hftest
section of the VM image which allows the image to inspect the structure of the tests it contains. The linker sorts the descriptors by their symbol name which is how descriptors from the same suite are grouped together for easier parsing.
The base VM image offers a command line interface, via the bootargs, to query the tests in the image and to run specific tests. The driver script uses this interface to execute tests, each with a fresh QEMU boot to give a fresh environment.