Today I published my QEMU testing framework, which was developed during my Master’s thesis. You can find the code on GitHub.

Repository screenshot

The framework allows you to test the implementation of emulated CPU instructions for the AVR32 architecture in QEMU. The framework supports the automatic build and execution of multiple (or all) tests at once, including the evaluation of the test results. The only manual work that is required is the writing of the test and the definition of the expected results.

I already included a few tests. I will polish my remaining tests later and add them to the repository.

I explain how the framework can be used in article 5 of my series, How to add a new architecture to QEMU.

How does the framework work?

The framework consists of three Python scripts.

avr32test.py is the “test management” script. It is called by the user and starts the execution of a specified test. The available options are shown in the README.md file of the project on GitHub.

avr32generate_tests.py is used to build an executable AVR32 ELF-file for a specific test. This script can be used manually, but it is intended to be used by the management script. The script requires an AVR32 assembler (avr32-as) to be present in the same directory. The AVR32 assembler is not part of the project repository, but you can download it from the Atmel website. It is part of the Arm 32-bit GNU Toolchain (Linux).

The third script extracts the .text section from an ELF-file. As there was no support for ELF files in the first version of the emulator, it was necessary to export the program text section. avr32generate_tests then uses the resulting raw binary as an input for QMEU.

After QEMU finishes the execution of the test file, the management script compares the CPU register values from QEMU with the expected results from the test file. Again, you can find the available options in the README file. I also published an article on how to implement new tests.