#![cfg(not(target_os = "windows"))]
use std::ffi::CStr;
use kvm_sys::*;
use libc::c_char;
use libc::ioctl;
use libc::open64;
use libc::O_RDWR;
const KVM_PATH: &CStr = c"/dev/kvm";
#[test]
fn get_version() {
let sys_fd = unsafe { open64(KVM_PATH.as_ptr() as *const c_char, O_RDWR) };
assert!(sys_fd >= 0);
let ret = unsafe { ioctl(sys_fd, KVM_GET_API_VERSION, 0) };
assert_eq!(ret as u32, KVM_API_VERSION);
}
#[test]
fn create_vm_fd() {
let sys_fd = unsafe { open64(KVM_PATH.as_ptr() as *const c_char, O_RDWR) };
assert!(sys_fd >= 0);
let vm_fd = unsafe { ioctl(sys_fd, KVM_CREATE_VM, 0) };
assert!(vm_fd >= 0);
}
#[test]
fn check_vm_extension() {
let sys_fd = unsafe { open64(KVM_PATH.as_ptr() as *const c_char, O_RDWR) };
assert!(sys_fd >= 0);
let has_user_memory = unsafe { ioctl(sys_fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY) };
assert_eq!(has_user_memory, 1);
}