@ -9,19 +9,25 @@ 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 ( ) ;
assert! ( nodes . len ( ) > 0 ) ;
for node in nodes {
let drm_version = uapi ::get_drm_version ( node . fd . as_raw_fd ( ) ) . expect ( "Failed to get drm version" ) ;
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 . name . to_str ( ) . unwrap ( ) , "i915" ) ;
assert_eq! ( drm_version . desc . to_str ( ) . unwrap ( ) , "Intel Graphics" ) ;
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 ( ) ;
assert! ( nodes . len ( ) > 0 ) ;
for node in nodes {
let _engines = i915 ::get_engines ( node . fd . as_raw_fd ( ) ) . expect ( "Failed to get engines" ) ;
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" ) ;
let fail_fd = File ::open ( "/dev/null" ) . expect ( "Failed to open /dev/null" ) ;
assert! ( i915 ::get_engines ( fail_fd . as_raw_fd ( ) ) . is_none ( ) ) ;
assert! ( i915 ::get_engines ( fail_fd . as_raw_fd ( ) ) . is_none ( ) ) ;
}
}
}
#[ test ]
#[ test ]
fn test_i915_uapi_get_param_fail ( ) {
fn test_i915_uapi_get_param_fail ( ) {
@ -32,7 +38,9 @@ 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 ( ) ;
assert! ( nodes . len ( ) > 0 ) ;
for node in nodes {
let engines = i915 ::get_engines ( node . fd . as_raw_fd ( ) ) . expect ( "Failed to get engines" ) ;
let engines = i915 ::get_engines ( node . fd . as_raw_fd ( ) ) . expect ( "Failed to get engines" ) ;
for engine in engines {
for engine in engines {
let native_engine = engine . to_native ( ) ;
let native_engine = engine . to_native ( ) ;
@ -40,7 +48,9 @@ fn test_i915_uapi_native_engine_info() {
assert_eq! ( & engine , & from_native ) ;
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,7 +61,9 @@ 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 ( ) ;
assert! ( nodes . len ( ) > 0 ) ;
for node in nodes {
// Mesa uses context id of 0 for init so it's surely okay, right?
// Mesa uses context id of 0 for init so it's surely okay, right?
let param = i915 ::get_context_param ( node . fd . as_raw_fd ( ) ,
let param = i915 ::get_context_param ( node . fd . as_raw_fd ( ) ,
0 ,
0 ,
@ -59,10 +71,13 @@ fn test_i915_uapi_get_context_param() {
. expect ( "Failed to get context param" ) ;
. expect ( "Failed to get context param" ) ;
assert! ( param > 0 ) ;
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 ( ) ;
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 gem = i915 ::make_gem ( node . fd . as_raw_fd ( ) , 4096 ) . expect ( "Failed to make gem" ) ;
assert! ( gem . handle > 0 ) ;
assert! ( gem . handle > 0 ) ;
assert! ( i915 ::gem_is_valid ( node . fd . as_raw_fd ( ) , & gem ) . unwrap ( ) ) ;
assert! ( i915 ::gem_is_valid ( node . fd . as_raw_fd ( ) , & gem ) . unwrap ( ) ) ;
@ -72,28 +87,47 @@ fn test_i915_uapi_gem_lifecycle() {
let invalid_fd = File ::open ( "/dev/null" ) . expect ( "Failed to open /dev/null" ) ;
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 ( ) ) ;
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 ( ) ;
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 gem = i915 ::make_gem ( node . fd . as_raw_fd ( ) , 4096 ) . expect ( "Failed to make gem" ) ;
// TODO figure out which devices this holds for
// 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 ) ) ;
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" ) ;
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 ( ) ;
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 gem = i915 ::make_gem ( node . fd . as_raw_fd ( ) , 4096 ) . expect ( "Failed to make gem" ) ;
let caching = i915 ::gem_get_caching ( node . fd . as_raw_fd ( ) , & gem ) . expect ( "Failed to get caching" ) ;
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 ) ;
assert! ( caching > 0 ) ;
i915 ::close_gem ( node . fd . as_raw_fd ( ) , gem ) . expect ( "Failed to close gem" ) ;
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 ( ) ;
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 gem = i915 ::make_gem ( node . fd . as_raw_fd ( ) , 4096 ) . expect ( "Failed to make gem" ) ;
thread ::scope ( | s | {
thread ::scope ( | s | {
let handle = s . spawn ( | | {
let handle = s . spawn ( | | {
@ -103,3 +137,49 @@ fn test_i915_uapi_gem_thread() {
handle . join ( ) . expect ( "Failed to join thread" ) ;
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());
// }
// }