~satchmo/libvmm

ref: d9d896747246f4dd668d18acd90e7172a5a943b2 libvmm/tests/kvm/device.cpp -rw-r--r-- 1.4 KiB
d9d89674Jason Phan readme: Try out plaintext 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#define CATCH_CONFIG_MAIN

#include <catch2/catch.hpp>

#include "vmm/kvm/kvm.hpp"

#if defined(__i386__) || defined(__x86_64__)
// NOTE: For some unknown reason, making 2
//       `vm.device(KVM_DEV_TYPE_VFIO, KVM_CREATE_DEVICE_TEST)` calls (and only
//       binding the second one to a variable) causes `has_attr()` and co to
//       fail with "Invalid argument" instead of "Inappropriate ioctl." This is
//       true even if the calls were made in separate test cases... Because of
//       this, we can't exactly test just device creation.
TEST_CASE("Fake device attributes") {
    auto kvm = vmm::kvm::system{};
    auto vm = kvm.vm();

    // Fails b/c there's no VGIC on x86_64.
    REQUIRE_THROWS(vm.device(KVM_DEV_TYPE_ARM_VGIC_V3, KVM_CREATE_DEVICE_TEST));

    // NOTE: Creating a real device would make our CI dependent on
    //       host-specific settings (e.g., having /dev/vfio). So, this is just
    //       a test device which we expect to fail.
    auto device = vm.device(KVM_DEV_TYPE_VFIO, KVM_CREATE_DEVICE_TEST);

    auto attr = kvm_device_attr {
        0,
        KVM_DEV_VFIO_GROUP,
        KVM_DEV_VFIO_GROUP_ADD,
        0x0,
    };

    REQUIRE_THROWS_WITH(device.has_attr(attr), "Inappropriate ioctl for device");
    REQUIRE_THROWS_WITH(device.get_attr(attr), "Inappropriate ioctl for device");
    REQUIRE_THROWS_WITH(device.set_attr(attr), "Inappropriate ioctl for device");
}
#endif