KVM Unit Testing

Overview of kvm-unit-tests

KVM unit testing started off alongside of original project KVM. It’s purpose was to validate all the supported features of KVM. With evolving development of KVM, very quickly it became necessary to standardize the process of validation which motivated the kvm-unit-tests project. It’s basically a collection of small standalone programs which are used as tiny guest operating systems (OS) to test KVM. Since KVM is part of Linux kernel, any userspace virtual machine manager (VMM) such as, qemu or kvmtool can be used for launching these guest OSes which then validate specific feature as implemented by the Linux KVM. Running of these unit testcases will also help in validation of the userspace hypervisor tool. The kvm-unit-tests framework supports multiple architectures e.g. i386, x86_64, armv7 (arm), armv8 (arm64), ppc64, ppc64le, and s390x. To learn more about the framework and testdevs please follow the official page for kvm-unit-tests.

Build & Install

Download the software stack

Skip this section if the required sources have been downloaded and the host TAP interface has been setup.

To obtain the required sources for the platform, follow the steps listed on the Setup Workspace page (including the setting up of the host TAP interface). Ensure that the platform software is downloaded before proceeding with the steps listed below. Also, note the host machine requirements listed on that page which is essential to build and execute the platform software stack.

Build the platform software

This section describes the procedure to build the sofware stack required to perform KVM unit testing. Following software packages from the Neoverse reference platform software stack are needed to do the testing:

  • Software stack for distro boot as given in Distro Boot guide,

  • kvm-unit-tests built for kvmtool target,

  • Kvmtool VMM.

Skip this section if a Buildroot or Busybox build is already performed for the platform software stack as the kvmtool and kvm-unit-tests are already built as part of the buildroot and busybox build.

  • Build UEFI firmware for the host and for the guest OS (ArmVirtKvmTool) by running the appropriate script from software stack:

    ./build-scripts/build-test-uefi.sh -p <platform name> <command>
    
  • A single script builds both kvmtool and kvm-unit-tests in the reference platform software stack. Run the below command to build the binaries:

    ./build-scripts/build-kvmtool.sh -p <platform name> <command>
    

    Supported command line options for above two commands are listed below:

    • <platform name>

    • <command>

      • Supported commands are

        • clean

        • build

        • package

    For example, to build the platform software stack and the kvmtool and kvm-unit-tests binaries for Rd-N2-Cfg1 platform run the following commands:

    ./build-scripts/build-test-uefi.sh -p rdn2cfg1 all
    
    ./build-scripts/build-kvmtool.sh -p rdn2cfg1 clean
    ./build-scripts/build-kvmtool.sh -p rdn2cfg1 build
    ./build-scripts/build-kvmtool.sh -p rdn2cfg1 package
    

Setup Satadisk Images

The kvm-unit-tests can be validated on a Linux distributions running as the host OS. Create disk images by following the guidelines from Distro Boot page.

Note

For simplicity, the setup instructions where specific, are given for Ubuntu v22.04 distro host OS.

Booting the platform for validation

  • Boot the host satadisk image on the FVP with network enabled as mentioned in Distro Boot. For example, to boot Ubuntu as the host OS give the follwing command to begin the distro boot from the ubuntu.satadisk image:

    ./distro.sh -p rdn2cfg1 -d /absolute/path/to/ubuntu.satadisk -n true
    
  • Once the host OS is booted up ensure that the KVM and virtualization support is enabled. After booting enable the networking support as well. Follow the UEFI supported virtualization guide for details on preparing the setup with Linux distribution running as host OS with networking enabled. For example, one might need to run the following commands:

    sudo dhclient -v
    sudo apt update
    sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils net-tools libfdt-dev -y
    

Running Unit Testcases

After booting the host OS with a Linux distribution such as Ubuntu, create a workspace to begin with kvm-unit-tests example.

mkdir -p ~/unit-testing/
cd ~/unit-testing/
  • Executing the unit testcase will require the kvm-unit-tests output directory and the kvmtool binary that are built as part of the reference software build as mentioned in the section Build the platform software. Copy these to host OS through network.

    rsync -Wa --progress user@server:TOP_DIR/output/<Platform name>/components/kvm-ut .
    cd kvm-ut/
    rsync -Wa --progress user@server:TOP_DIR/output/<Platform name>/components/rdn2/lkvm .
    
  • Get the absolute path to the recently copied lkvm binary and run the below command to export the KVMTOOL as the target vmm to run kvm-unit-tests.

    sudo su
    export KVMTOOL=<Absolute path to kvmtool>/lkvm
    
  • Finally, begin testing by executing the automated test script from kvm-ut directory that iterates over all available test implementation for the platform.

    ./run_tests.sh
    

Copyright (c) 2022-2023, Arm Limited. All rights reserved.