GPU: add synthetic unit tests for query.rs and signature.rs

(cherry picked from commit 0be58e62d24181a9eb60244a7e4d878a3627d401)
This commit is contained in:
给伊莉雅补魔 authored and local committed 2026-11-25 01:03:00 -06:00
1 parent 54909476b7
commit 7da03c4a8e
2 files changed
+289

No files matched your search

+87
View File
@@ -70,3 +70,90 @@ static FUNCTIONS: Table<24> = {
f[7] = object::parent_device as *const (); // 0x38
Table(f)
};
#[cfg(test)]
mod tests {
use super::*;
use crate::object::{E_NOINTERFACE, E_POINTER, S_FALSE, S_OK, slot};
#[test]
fn null_descriptions_are_rejected() {
let mut heap = std::ptr::null();
assert_eq!(
create(std::ptr::null(), std::ptr::null(), &HEAP_IIDS[0], &mut heap),
E_INVALIDARG
);
assert!(heap.is_null());
// The description is checked first: a probe with no room for the
// heap fails on it rather than answering S_FALSE.
assert_eq!(
create(
std::ptr::null(),
std::ptr::null(),
&HEAP_IIDS[0],
std::ptr::null_mut()
),
E_INVALIDARG
);
}
#[test]
fn creation_without_an_out_pointer_only_probes() {
let desc = Desc {
kind: 1, // timestamps
count: 64,
nodes: 0,
};
// A known interface with no out pointer asks whether creation would
// succeed; the heap is dropped instead of handed out.
assert_eq!(
create(std::ptr::null(), &desc, &HEAP_IIDS[0], std::ptr::null_mut()),
S_FALSE
);
// A null interface id is tolerated: no interface, no heap.
let mut heap = std::ptr::null();
assert_eq!(
create(std::ptr::null(), &desc, std::ptr::null(), &mut heap),
E_NOINTERFACE
);
assert!(heap.is_null());
}
#[test]
fn heaps_answer_their_interfaces_and_count_references() {
let desc = Desc {
kind: 0, // occlusion
count: 8,
nodes: 0,
};
let null = std::ptr::null();
let mut heap = null;
assert_eq!(create(null, &desc, &HEAP_IIDS[0], &mut heap), S_OK);
assert!(!heap.is_null());
let query = slot::<extern "system" fn(This, *const Iid, *mut This) -> HRESULT>(heap, 0x0);
// Every interface the heap answers to hands out the same object.
for iid in &HEAP_IIDS {
let mut out = null;
assert_eq!(query(heap, iid, &mut out), S_OK);
assert_eq!(out as usize, heap as usize);
}
// An unknown interface writes null behind and reports it missing.
let unknown = [0u8; 16];
let mut out = heap;
assert_eq!(query(heap, &unknown, &mut out), E_NOINTERFACE);
assert!(out.is_null());
// A null interface id is tolerated rather than matched.
let mut out = heap;
assert_eq!(query(heap, std::ptr::null(), &mut out), E_NOINTERFACE);
assert!(out.is_null());
// No room for the answer is a pointer error.
assert_eq!(query(heap, &unknown, std::ptr::null_mut()), E_POINTER);
// References: one from creation, four from the queries, one added;
// each release hands back what is left, the last frees the heap.
assert_eq!(slot::<extern "system" fn(This) -> u32>(heap, 0x8)(heap), 6);
let release = slot::<extern "system" fn(This) -> u32>(heap, 0x10);
for left in [5, 4, 3, 2, 1, 0] {
assert_eq!(release(heap), left);
}
}
}