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.

70 lines
2.9 KiB

3 weeks ago
use intel_gpu_uapi::*;
use std::fmt::format;
use std::os::fd::{AsRawFd, OwnedFd, RawFd};
use std::fs::File;
use std::path::Path;
#[test]
fn test_i915_find_device() {
let device = gpu::drm_i915::find_i915_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_drm_version() {
let device = gpu::drm_i915::find_i915_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!(gpu::drm_i915::Device::from_fd(OwnedFd::from(fd_null)).is_none());
}
fn has_engine_class(engines: &Vec<gpu::drm_i915::Engine>, engine_class: uapi::DrmI915EngineClass) -> bool {
engines.iter().filter(|engine| engine.info.engine.engine_class == engine_class).count() > 0
}
#[test]
fn test_i915_get_engines() {
let device = gpu::drm_i915::find_i915_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::DrmI915EngineClass::Render));
assert!(has_engine_class(&engines, uapi::DrmI915EngineClass::Copy));
assert!(has_engine_class(&engines, uapi::DrmI915EngineClass::Video));
assert!(has_engine_class(&engines, uapi::DrmI915EngineClass::VideoEnhance));
// Compute engine is not always present
// assert!(has_engine_class(&engines, uapi::DrmI915EngineClass::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_get_param() {
let device = gpu::drm_i915::find_i915_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);
}