@ -9,18 +9,24 @@ use std::thread;
#[ test ]
#[ test ]
fn test_i915_uapi_get_version ( ) {
fn test_i915_uapi_get_version ( ) {
let node = i915 ::find_node ( ) . expect ( "Failed to find i915 fd" ) ;
let nodes = i915 ::find_all_nodes ( ) ;
let drm_version = uapi ::get_drm_version ( node . fd . as_raw_fd ( ) ) . expect ( "Failed to get drm version" ) ;
assert! ( nodes . len ( ) > 0 ) ;
assert_eq! ( drm_version . name . to_str ( ) . unwrap ( ) , "i915" ) ;
for node in nodes {
assert_eq! ( drm_version . desc . to_str ( ) . unwrap ( ) , "Intel Graphics" ) ;
let drm_version = uapi ::get_drm_version ( node . fd . as_raw_fd ( ) ) . expect ( "Failed to get drm version" ) ;
assert_eq! ( drm_version . name . to_str ( ) . unwrap ( ) , "i915" ) ;
assert_eq! ( drm_version . desc . to_str ( ) . unwrap ( ) , "Intel Graphics" ) ;
}
}
}
#[ test ]
#[ test ]
fn test_i915_uapi_get_engines ( ) {
fn test_i915_uapi_get_engines ( ) {
let node = i915 ::find_node ( ) . expect ( "Failed to find i915 fd" ) ;
let nodes = i915 ::find_all_nodes ( ) ;
let _engines = i915 ::get_engines ( node . fd . as_raw_fd ( ) ) . expect ( "Failed to get engines" ) ;
assert! ( nodes . len ( ) > 0 ) ;
let fail_fd = File ::open ( "/dev/null" ) . expect ( "Failed to open /dev/null" ) ;
for node in nodes {
assert! ( i915 ::get_engines ( fail_fd . as_raw_fd ( ) ) . is_none ( ) ) ;
let _engines = i915 ::get_engines ( node . fd . as_raw_fd ( ) ) . expect ( "Failed to get engines" ) ;
let fail_fd = File ::open ( "/dev/null" ) . expect ( "Failed to open /dev/null" ) ;
assert! ( i915 ::get_engines ( fail_fd . as_raw_fd ( ) ) . is_none ( ) ) ;
}
}
}
#[ test ]
#[ test ]
@ -32,15 +38,19 @@ fn test_i915_uapi_get_param_fail() {
#[ test ]
#[ test ]
fn test_i915_uapi_native_engine_info ( ) {
fn test_i915_uapi_native_engine_info ( ) {
let node = i915 ::find_node ( ) . expect ( "Failed to find i915 fd" ) ;
let nodes = i915 ::find_all_nodes ( ) ;
let engines = i915 ::get_engines ( node . fd . as_raw_fd ( ) ) . expect ( "Failed to get engines" ) ;
assert! ( nodes . len ( ) > 0 ) ;
for engine in engines {
for node in nodes {
let native_engine = engine . to_native ( ) ;
let engines = i915 ::get_engines ( node . fd . as_raw_fd ( ) ) . expect ( "Failed to get engines" ) ;
let from_native = i915 ::EngineInfo ::from_native ( native_engine ) ;
for engine in engines {
assert_eq! ( & engine , & from_native ) ;
let native_engine = engine . to_native ( ) ;
let from_native = i915 ::EngineInfo ::from_native ( native_engine ) ;
assert_eq! ( & engine , & from_native ) ;
}
}
}
}
}
// TODO
#[ test ]
#[ test ]
fn test_i915_uapi_find_fd ( ) {
fn test_i915_uapi_find_fd ( ) {
let fd = i915 ::find_fd ( ) . expect ( "Failed to find i915 fd" ) ;
let fd = i915 ::find_fd ( ) . expect ( "Failed to find i915 fd" ) ;
@ -51,55 +61,125 @@ fn test_i915_uapi_find_fd() {
#[ test ]
#[ test ]
fn test_i915_uapi_get_context_param ( ) {
fn test_i915_uapi_get_context_param ( ) {
let node = i915 ::find_node ( ) . expect ( "Failed to find i915 fd" ) ;
let nodes = i915 ::find_all_nodes ( ) ;
// Mesa uses context id of 0 for init so it's surely okay, right?
assert! ( nodes . len ( ) > 0 ) ;
let param = i915 ::get_context_param ( node . fd . as_raw_fd ( ) ,
for node in nodes {
0 ,
// Mesa uses context id of 0 for init so it's surely okay, right?
native ::I915_CONTEXT_PARAM_GTT_SIZE as u32 )
let param = i915 ::get_context_param ( node . fd . as_raw_fd ( ) ,
. expect ( "Failed to get context param" ) ;
0 ,
assert! ( param > 0 ) ;
native ::I915_CONTEXT_PARAM_GTT_SIZE as u32 )
. expect ( "Failed to get context param" ) ;
assert! ( param > 0 ) ;
}
}
}
#[ test ]
#[ test ]
fn test_i915_uapi_gem_lifecycle ( ) {
fn test_i915_uapi_gem_lifecycle ( ) {
let node = i915 ::find_node ( ) . expect ( "Failed to find i915 fd" ) ;
let nodes = i915 ::find_all_nodes ( ) ;
let gem = i915 ::make_gem ( node . fd . as_raw_fd ( ) , 4096 ) . expect ( "Failed to make gem" ) ;
assert! ( nodes . len ( ) > 0 ) ;
assert! ( gem . handle > 0 ) ;
for node in nodes {
assert! ( i915 ::gem_is_valid ( node . fd . as_raw_fd ( ) , & gem ) . unwrap ( ) ) ;
let gem = i915 ::make_gem ( node . fd . as_raw_fd ( ) , 4096 ) . expect ( "Failed to make gem" ) ;
let tmp = i915 ::DrmGemHandle { handle : gem . handle } ;
assert! ( gem . handle > 0 ) ;
i915 ::close_gem ( node . fd . as_raw_fd ( ) , tmp ) . expect ( "Failed to close gem" ) ;
assert! ( i915 ::gem_is_valid ( node . fd . as_raw_fd ( ) , & gem ) . unwrap ( ) ) ;
assert! ( ! i915 ::gem_is_valid ( node . fd . as_raw_fd ( ) , & gem ) . unwrap ( ) ) ;
let tmp = i915 ::DrmGemHandle { handle : gem . handle } ;
let invalid_fd = File ::open ( "/dev/null" ) . expect ( "Failed to open /dev/null" ) ;
i915 ::close_gem ( node . fd . as_raw_fd ( ) , tmp ) . expect ( "Failed to close gem" ) ;
assert! ( i915 ::make_gem ( invalid_fd . as_raw_fd ( ) , 4096 ) . is_none ( ) ) ;
assert! ( ! i915 ::gem_is_valid ( node . fd . as_raw_fd ( ) , & gem ) . unwrap ( ) ) ;
let invalid_fd = File ::open ( "/dev/null" ) . expect ( "Failed to open /dev/null" ) ;
assert! ( i915 ::make_gem ( invalid_fd . as_raw_fd ( ) , 4096 ) . is_none ( ) ) ;
}
}
}
#[ test ]
#[ test ]
fn test_i915_uapi_gem_tiling ( ) {
fn test_i915_uapi_gem_tiling ( ) {
let node = i915 ::find_node ( ) . expect ( "Failed to find i915 fd" ) ;
let nodes = i915 ::find_all_nodes ( ) ;
let gem = i915 ::make_gem ( node . fd . as_raw_fd ( ) , 4096 ) . expect ( "Failed to make gem" ) ;
assert! ( nodes . len ( ) > 0 ) ;
// TODO figure out which devices this holds for
for node in nodes {
assert! ( i915 ::gem_has_tiling ( node . fd . as_raw_fd ( ) , & gem ) . is_ok_and ( | e | e = = true ) ) ;
let gem = i915 ::make_gem ( node . fd . as_raw_fd ( ) , 4096 ) . expect ( "Failed to make gem" ) ;
i915 ::close_gem ( node . fd . as_raw_fd ( ) , gem ) . expect ( "Failed to close gem" ) ;
// TODO figure out which devices this holds for
let tiling = i915 ::gem_get_tiling ( node . fd . as_raw_fd ( ) , & gem ) ;
if tiling . is_err ( ) {
// Unsupported on DG
continue ;
}
assert! ( i915 ::gem_has_tiling ( node . fd . as_raw_fd ( ) , & gem ) . is_ok_and ( | e | e = = true ) ) ;
i915 ::close_gem ( node . fd . as_raw_fd ( ) , gem ) . expect ( "Failed to close gem" ) ;
}
}
}
#[ test ]
#[ test ]
fn test_i915_uapi_gem_caching ( ) {
fn test_i915_uapi_gem_caching ( ) {
let node = i915 ::find_node ( ) . expect ( "Failed to find i915 fd" ) ;
let nodes = i915 ::find_all_nodes ( ) ;
let gem = i915 ::make_gem ( node . fd . as_raw_fd ( ) , 4096 ) . expect ( "Failed to make gem" ) ;
assert! ( nodes . len ( ) > 0 ) ;
let caching = i915 ::gem_get_caching ( node . fd . as_raw_fd ( ) , & gem ) . expect ( "Failed to get caching" ) ;
for node in nodes {
assert! ( caching > 0 ) ;
let gem = i915 ::make_gem ( node . fd . as_raw_fd ( ) , 4096 ) . expect ( "Failed to make gem" ) ;
i915 ::close_gem ( node . fd . as_raw_fd ( ) , gem ) . expect ( "Failed to close gem" ) ;
let caching = i915 ::gem_get_caching ( node . fd . as_raw_fd ( ) , & gem ) ;
if caching . is_err ( ) {
// Unsupported on DG
continue ;
}
let caching = caching . unwrap ( ) ;
assert! ( caching > 0 ) ;
i915 ::close_gem ( node . fd . as_raw_fd ( ) , gem ) . expect ( "Failed to close gem" ) ;
}
}
}
#[ test ]
#[ test ]
fn test_i915_uapi_gem_thread ( ) {
fn test_i915_uapi_gem_thread ( ) {
let node = i915 ::find_node ( ) . expect ( "Failed to find i915 fd" ) ;
let nodes = i915 ::find_all_nodes ( ) ;
let gem = i915 ::make_gem ( node . fd . as_raw_fd ( ) , 4096 ) . expect ( "Failed to make gem" ) ;
assert! ( nodes . len ( ) > 0 ) ;
thread ::scope ( | s | {
for node in nodes {
let handle = s . spawn ( | | {
let gem = i915 ::make_gem ( node . fd . as_raw_fd ( ) , 4096 ) . expect ( "Failed to make gem" ) ;
thread ::scope ( | s | {
let handle = s . spawn ( | | {
assert! ( i915 ::gem_is_valid ( node . fd . as_raw_fd ( ) , & gem ) . unwrap ( ) ) ;
} ) ;
assert! ( i915 ::gem_is_valid ( node . fd . as_raw_fd ( ) , & gem ) . unwrap ( ) ) ;
assert! ( i915 ::gem_is_valid ( node . fd . as_raw_fd ( ) , & gem ) . unwrap ( ) ) ;
handle . join ( ) . expect ( "Failed to join thread" ) ;
} ) ;
} ) ;
assert! ( i915 ::gem_is_valid ( node . fd . as_raw_fd ( ) , & gem ) . unwrap ( ) ) ;
}
handle . join ( ) . expect ( "Failed to join thread" ) ;
}
} ) ;
#[ test ]
fn test_i915_uapi_gem_fork_parent ( ) {
let nodes = i915 ::find_all_nodes ( ) ;
assert! ( nodes . len ( ) > 0 ) ;
for node in nodes {
let gem = i915 ::make_gem ( node . fd . as_raw_fd ( ) , 4096 ) . expect ( "Failed to make gem" ) ;
let pid = unsafe { libc ::fork ( ) } ;
if pid = = 0 {
if i915 ::gem_is_valid ( node . fd . as_raw_fd ( ) , & gem ) . unwrap ( ) {
std ::process ::exit ( 0 ) ;
} else {
std ::process ::exit ( - 1 ) ;
}
} else {
assert! ( i915 ::gem_is_valid ( node . fd . as_raw_fd ( ) , & gem ) . unwrap ( ) ) ;
let mut status = 0 ;
unsafe { libc ::waitpid ( pid , & mut status , 0 ) } ;
assert_eq! ( status , 0 ) ;
}
}
}
}
// TODO: Fix this test
// Shared mem needs to be used to communicate the gem handle between parent and child
// Test both a shared fd and separate fd
// #[test]
// fn test_i915_uapi_gem_fork_child() {
// let pid = unsafe { libc::fork() };
// if pid == 0 {
// let node = i915::find_node().expect("Failed to find i915 fd");
// let gem = i915::make_gem(node.fd.as_raw_fd(), 4096).expect("Failed to make gem");
// if i915::gem_is_valid(node.fd.as_raw_fd(), &gem).unwrap() {
// println!("handle 1: {}", gem.handle);
// std::process::exit(gem.handle as i32);
// } else {
// std::process::exit(-1);
// }
// } else {
// let node = i915::find_node().expect("Failed to find i915 fd");
// let mut status = 0;
// unsafe { libc::waitpid(pid, &mut status, 0) };
// assert!(i915::gem_is_valid(node.fd.as_raw_fd(), &DrmGemHandle {handle: 1}).unwrap());
// }
// }