• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #![cfg(not(target_arch = "arm"))]
6 
7 use libc::{c_char, ioctl, open, O_RDWR};
8 
9 use kvm_sys::*;
10 
11 const KVM_PATH: &str = "/dev/kvm\0";
12 
13 #[test]
get_version()14 fn get_version() {
15     let sys_fd = unsafe { open(KVM_PATH.as_ptr() as *const c_char, O_RDWR) };
16     assert!(sys_fd >= 0);
17 
18     let ret = unsafe { ioctl(sys_fd, KVM_GET_API_VERSION(), 0) };
19     assert_eq!(ret as u32, KVM_API_VERSION);
20 }
21 
22 #[test]
create_vm_fd()23 fn create_vm_fd() {
24     let sys_fd = unsafe { open(KVM_PATH.as_ptr() as *const c_char, O_RDWR) };
25     assert!(sys_fd >= 0);
26 
27     let vm_fd = unsafe { ioctl(sys_fd, KVM_CREATE_VM(), 0) };
28     assert!(vm_fd >= 0);
29 }
30 
31 #[test]
check_vm_extension()32 fn check_vm_extension() {
33     let sys_fd = unsafe { open(KVM_PATH.as_ptr() as *const c_char, O_RDWR) };
34     assert!(sys_fd >= 0);
35 
36     let has_user_memory = unsafe { ioctl(sys_fd, KVM_CHECK_EXTENSION(), KVM_CAP_USER_MEMORY) };
37     assert_eq!(has_user_memory, 1);
38 }
39