You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.6 KiB

use intel_gpu_uapi::*;
use gpu::i915;
use std::os::fd::{AsRawFd, OwnedFd, RawFd};
use std::fs::File;
use std::path::Path;
#[test]
fn test_i915_gpu_find_device() {
let device = i915::find_device();
assert!(device.is_some());
let drm_version = device.unwrap().driver;
assert_eq!(drm_version.name.to_str().unwrap(), "i915");
assert_eq!(drm_version.desc.to_str().unwrap(), "Intel Graphics");
}
#[test]
fn test_i915_gpu_from_path() {
let device = i915::find_device().expect("Failed to find i915 device");
let path = device.node.path.clone().expect("Failed to get path");
let device_2 = i915::Device::from_path(path).expect("Failed to create device from path");
assert_eq!(device.driver.name, device_2.driver.name);
assert_eq!(device.driver.desc, device_2.driver.desc);
assert_eq!(device.node.path, device_2.node.path);
}
#[test]
fn test_i915_gpu_from_fd() {
let device = i915::find_device().expect("Failed to find i915 device");
let fd = device.node.fd;
let device_2 = i915::Device::from_fd(OwnedFd::from(fd)).expect("Failed to create device from fd");
assert_eq!(device.driver.name, device_2.driver.name);
assert_eq!(device.driver.desc, device_2.driver.desc);
}
#[test]
fn test_i915_gpu_get_version() {
let device = i915::find_device();
assert!(device.is_some());
let drm_version = device.unwrap().driver;
assert_eq!(drm_version.name.to_str().unwrap(), "i915");
assert_eq!(drm_version.desc.to_str().unwrap(), "Intel Graphics");
let fd_null = File::open("/dev/null").expect("Failed to open /dev/null");
assert!(i915::Device::from_fd(OwnedFd::from(fd_null)).is_none());
}
fn has_engine_class(engines: &Vec<i915::Engine>, engine_class: uapi::i915::EngineClass) -> bool {
engines.iter().filter(|engine| engine.info.engine.engine_class == engine_class).count() > 0
}
#[test]
fn test_i915_gpu_get_engines() {
let device = i915::find_device().expect("Failed to find i915 device");
let drm_version = &device.driver;
assert_eq!(drm_version.name.to_str().unwrap(), "i915");
assert_eq!(drm_version.desc.to_str().unwrap(), "Intel Graphics");
let engines = device.get_engines().expect("Failed to get engines");
assert!(engines.len() > 0);
assert!(has_engine_class(&engines, uapi::i915::EngineClass::Render));
assert!(has_engine_class(&engines, uapi::i915::EngineClass::Copy));
assert!(has_engine_class(&engines, uapi::i915::EngineClass::Video));
assert!(has_engine_class(&engines, uapi::i915::EngineClass::VideoEnhance));
// Compute engine is not always present
// assert!(has_engine_class(&engines, uapi::i915::EngineClass::Compute));
}
fn get_vendor_for_fd(fd: RawFd) -> String{
unsafe {
let mut stat: libc::stat = std::mem::zeroed();
libc::fstat(fd, &mut stat);
let (major, minor) = (libc::major(stat.st_rdev),
libc::minor(stat.st_rdev));
let sysfs_path = format!("/sys/dev/char/{}:{}/device/device", major, minor);
let sysfs_path = Path::new(&sysfs_path);
let dev_id = std::fs::read_to_string(sysfs_path).expect("Unable to read device id");
return dev_id.trim().to_string();
}
}
#[test]
fn test_i915_gpu_get_param() {
let device = i915::find_device().expect("Failed to find i915 device");
let drm_version = &device.driver;
assert_eq!(drm_version.name.to_str().unwrap(), "i915");
assert_eq!(drm_version.desc.to_str().unwrap(), "Intel Graphics");
let chipset_id = device.get_param(native::I915_PARAM_CHIPSET_ID).expect("Failed to get param");
let chip_id = format!("{:#04x}", chipset_id);
let dev_id = get_vendor_for_fd(device.node.fd.as_raw_fd());
assert_eq!(dev_id, chip_id);
}