Surprisingly a change not made years ago, the Linux Kernel Unit Testing “KUnit” framework with the Linux 6.14 kernel is set to use hardware acceleration by default for faster testing where available.
KUnit is the Liunux kernel’s common unit testing framework for carrying out various tests. Surprisingly up until now the KUnit testing script hasn’t attempted to hardware acceleration for virtualization by default. But for Linux 6.14 that’s among the changes now present.
Tamir Duberstein who authored the patch enabling KUnit hardware acceleration by default explained:
“Use KVM or HVF if supported by the QEMU binary and available on the system.
This produces a nice improvement on my Apple M3 Pro running macOS 14.7:
Before:
./tools/testing/kunit/kunit.py exec –arch arm64
[HH:MM:SS] Elapsed time: 10.145sAfter:
./tools/testing/kunit/kunit.py exec –arch arm64
[HH:MM:SS] Elapsed time: 1.773s”
They are just simple unit tests so even without hardware acceleration not too time consuming, but for those frequently triggering KUnit or similar, the time savings from 10 seconds to just over one second can certainly add up for CI-type testing and other repetitive testing.
The patch is attempting to use KVM, HVF (macOS Hypervisor Framework), or otherwise the Tiny Code Generation (TCG) depending upon the platform / how QEMU was built. Should no hardware acceleration support be available, no worries, and KUnit will gracefully still run its tests.
This hardware acceleration when available is part of the KUnit updates for Linux 6.14 along with introducing a new autorun option. The autorun option controls tests to run on boot or module load. The Kconfig KUNIT_AUTORUN_ENABLED option can be used for specifying the default kunit.autorun value for the unit tests to automatically run.