Fri 11 October 2024

Speed Up Embedded Software Testing with QEMU

Testing embedded software is challenging, especially when the target hardware is not readily available and may not be for months.

Software engineers typically need immediate and frequent access to the physical target hardware during development. This often leads to delays and resource contention, which results in inadequate testing and high development costs. This is where hardware emulation tools like QEMU (Quick Emulator) come into play to help accelerate embedded development.

Here, we explore how QEMU will help embedded software engineers emulate hardware setups and overcome typical bottlenecks of hardware dependency.

What is QEMU?

QEMU is open source software that allows you to emulate various hardware architectures. QEMU offers full-system emulation, allowing engineers to create a virtual replica of their embedded device’s hardware. This capability is crucial for validating application behaviour under representative conditions without requiring access to the target hardware.

QEMU is highly adaptable to many development scenarios, from emulating state-of-the-art CPU accelerations to full-scale rig simulation for software-in-the-loop (SIL/SWIL) testing. With QEMU, you can test features, find bugs, and gauge performance, all within a controlled and repeatable environment.

Simulating hardware setups with QEMU

QEMU allows each software team member to have an emulated system-under-test (SUT) for when hardware doesn’t yet exist. This lets software teams start early and hit the ground running on critical, specific tasks once hardware becomes available. That’s not to say QEMU isn’t of value following the early stages of a software project. QEMU continues to be a valuable tool beyond hardware availability for testing anywhere, instant scaling, and ease of scripting.

Additionally, with software engineers working on an emulated system, expensive and rare hardware is freed up for complex testing. Since QEMU is an emulated system, time/signal-dependent simulations can also be accelerated.

QEMU & Continuous Integration

While requiring upfront investment, automated testing — specifically continuous integration (CI) — frees up expensive engineer time. CI allows for regression testing and in-depth system analysis through variable changes, which would otherwise be difficult due to the human input required. QEMU enhances these practices by enabling interactions to be easily scripted.

When QEMU is combined with the openQA testing tool, it is possible to expand automated QEMU testing to cover the user interface (UI) with automated screen presses, for example. Implementing QEMU in CI allows teams to spot errors quickly before code is merged, freeing up hardware for complex hardware-in-the-loop (HIL) tests that are difficult to automate. This ultimately aids in avoiding costly errors. As a bonus, this approach is also language-agnostic.

The use of QEMU in CI allows parallelised test runs for multiple software versions by utilising emulated hardware on CI runners, a task that would otherwise require teams of testers. This shortens the development cycle time. In addition, due to features such as tracing and an internal GDB server (allowing debugging as if running on hardware), QEMU is significantly more straightforward to debug.

In addition, QEMU will emulate devices such as CAN buses, memory-mapped IO (MMIO), and serial-attached devices, including GPS, Trusted Platform Modules (TPMs), and USB. This capability allows for complex emulated hardware setups, including multiple displays and physical networks.

Challenges of working with QEMU

While QEMU is an essential development tool, it cannot fully replace hardware. This is because QEMU is not cycle-accurate or executed in exactly the same way as the hardware would.

While still efficient due to its Tiny Code Generator (TCG), there is still overhead for emulating or translating. QEMU’s aim is to be fast, which means trade-offs between accuracy and speed.

There may be issues with coverage of all the hardware instructions which may not be supported in QEMU. Also the driver models may not support all exceptions as these are unlikely to be useful in an emulated environment.

QEMU is an expansive project covering user and system-level emulation across 31 architectures, with AArch64 supporting 47 CPUs and 419 devices. As a result, developing complex setups can be challenging.

The bottom line: Why QEMU matters

QEMU is a powerful solution for testing embedded software, helping prioritise hardware for critical, complex testing and development.

Integrating QEMU for embedded software into your workflow will significantly accelerate early-stage development, ease system debugging, and facilitate automated testing throughout the software project. QEMU provides full system emulation, allowing thorough testing and debugging in a virtual machine for embedded systems. This flexibility ensures your system is tested in conditions close to real hardware, reducing the risks and challenges of late-stage bugs.

Ultimately, QEMU will accelerate your development process with emulation that gets close to the actual hardware. A well-configured QEMU will bring you much closer to the results and experience your software team needs.

Explore some of our recent QEMU projects:

How are you using QEMU?

Send us your thoughts or comments via the form below.

Other Content

Get in touch to find out how Codethink can help you

sales@codethink.co.uk +44 161 660 9930

Contact us