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_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, 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); }