crosvm/kvm_sys/tests/sanity.rs
David Tolnay aecf9a4dee edition: Remove extern crate lines
In Rust 2018 edition, `extern crate` is no longer required for importing
from other crates. Instead of writing:

    extern crate dep;
    use dep::Thing;

we write:

    use dep::Thing;

In this approach, macros are imported individually from the declaring
crate rather than through #[macro_use]. Before:

    #[macro_use]
    extern crate sys_util;

After:

    use sys_util::{debug, error};

The only place that `extern crate` continues to be required is in
importing the compiler's proc_macro API into a procedural macro crate.
This will hopefully be fixed in a future Rust release.

    extern crate proc_macro;

TEST=cargo check
TEST=cargo check --all-features
TEST=cargo check --target aarch64-unknown-linux-gnu
TEST=local kokoro

Change-Id: I0b43768c0d81f2a250b1959fb97ba35cbac56293
Reviewed-on: https://chromium-review.googlesource.com/1565302
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-04-15 02:06:08 -07:00

37 lines
1,016 B
Rust

// Copyright 2017 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use libc::{c_char, ioctl, open, O_RDWR};
use kvm_sys::*;
const KVM_PATH: &'static 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);
}