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.8 KiB

3 weeks ago
use intel_gpu_uapi::*;
use gpu::i915;
3 weeks ago
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();
3 weeks ago
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_get_version() {
let device = i915::find_device();
3 weeks ago
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());
3 weeks ago
}
fn has_engine_class(engines: &Vec<i915::Engine>, engine_class: uapi::i915::EngineClass) -> bool {
3 weeks ago
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");
3 weeks ago
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));
3 weeks ago
// Compute engine is not always present
// assert!(has_engine_class(&engines, uapi::i915::EngineClass::Compute));
3 weeks ago
}
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");
3 weeks ago
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);
}