crosvm/kvm_sys/tests/basic.rs
Dennis Kempin 1dab58a2cf Update all copyright headers to match new style
This search/replace updates all copyright notices to drop the
"All rights reserved", Use "ChromiumOS" instead of "Chromium OS"
and drops the trailing dots.

This fulfills the request from legal and unifies our notices.

./tools/health-check has been updated to only accept this style.

BUG=b:246579983
TEST=./tools/health-check

Change-Id: I87a80701dc651f1baf4820e5cc42469d7c5f5bf7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3894243
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-09-13 18:41:29 +00:00

40 lines
1 KiB
Rust

// Copyright 2017 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#![cfg(not(any(target_os = "windows", target_arch = "arm")))]
use kvm_sys::*;
use libc::c_char;
use libc::ioctl;
use libc::open;
use libc::O_RDWR;
const KVM_PATH: &str = "/dev/kvm\0";
#[test]
fn get_version() {
let sys_fd = unsafe { open(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 { open(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 { open(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);
}