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.

115 lines
4.6 KiB

use intel_gpu::*;
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_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);
}
3 weeks ago
#[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 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);
}
#[test]
fn test_i915_gpu_gem_lifecycle() {
let device = i915::find_device().expect("Failed to find i915 device");
let gem = i915::GemHandle::new(&device.node, 4096).expect("Failed to create gem handle");
let tmp = gem.handle.clone();
assert!(gem.is_valid().unwrap());
drop(gem);
assert!(i915::GemHandle::from_handle(&device.node, tmp).is_err());
}
#[test]
fn test_i915_gpu_gem_from_handle() {
let device = i915::find_device().expect("Failed to find i915 device");
let gem = i915::GemHandle::new(&device.node, 4096).expect("Failed to create gem handle");
let tmp = gem.handle.clone();
let gem_2 = i915::GemHandle::from_handle(&device.node, tmp).expect("Failed to create gem handle from handle");
assert_eq!(gem.handle, gem_2.handle);
assert!(gem.is_valid().unwrap());
drop(gem);
assert!(!gem_2.is_valid().unwrap());
}
#[test]
fn test_i915_gpu_gem_has_tiling() {
let device = i915::find_device().expect("Failed to find i915 device");
let gem = i915::GemHandle::new(&device.node, 4096).expect("Failed to create gem handle");
assert!(gem.has_tiling().unwrap());
3 weeks ago
}