mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-10 20:19:07 +00:00
30055ecabd
Depending on which linux kernel headers are used, different outputs for bindgen are given. In particular, some structs in x86's kvm.h are not in arm's kvm.h and the other way around. This presented as compile time failures when compiling the ioctl number functions which take these struct types as parameters. This change solves this my lumping ioctls into an x86 module, arm module, and common module. Additionally, bindgen is run with the x86 kvm.h and the arm kvm.h header and only the appropriate one is included at build time. This change also fixes a few ioctls with the incorrect direction label. TEST=cargo test [--target=armv7a-cros-linux-gnueabi] BUG=chromium:711556 Change-Id: I7fc0e10587978006b89d16167df1107582b34670 Reviewed-on: https://chromium-review.googlesource.com/482411 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
39 lines
1 KiB
Rust
39 lines
1 KiB
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.
|
|
|
|
extern crate kvm_sys;
|
|
extern crate libc;
|
|
|
|
use libc::{ioctl, open, c_char, 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);
|
|
}
|