From 9e046ed8d2b01dcadf084df52042d6ead04fff85 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Fri, 27 Nov 2026 05:29:53 -0800 Subject: [PATCH] Runtime tests: port the GPU-time duration and host-clock tests the old runtime's deletion took 5d725aeec7 deleted the old runtime with its tests. Two of its GPU-time tests (tests/gpu_time.rs) describe the new runtime's design as they stood and need nothing new, so they come back unchanged in their answers: - durations_count_ticks_of_the_period_across_a_wrap: the old GpuClock::duration, now Ticks::span (Ticks::new takes the period first, then the valid bits). - the_host_time_rises: host_time, now u64 nanoseconds where it was f64. Verified: baseline runs pending (the runtime's tree as it stands at development's tip, with only these tests added). --- crates/metal2vulkan-runtime/src/tests/mod.rs | 1 + .../metal2vulkan-runtime/src/tests/times.rs | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 crates/metal2vulkan-runtime/src/tests/times.rs diff --git a/crates/metal2vulkan-runtime/src/tests/mod.rs b/crates/metal2vulkan-runtime/src/tests/mod.rs index 3e9f7cad3..a43902d5d 100644 --- a/crates/metal2vulkan-runtime/src/tests/mod.rs +++ b/crates/metal2vulkan-runtime/src/tests/mod.rs @@ -152,6 +152,7 @@ mod take_split; mod texture; mod texture_accesses; mod texture_buffers; +mod times; mod translate; mod translator_fields; mod unattached_colors; diff --git a/crates/metal2vulkan-runtime/src/tests/times.rs b/crates/metal2vulkan-runtime/src/tests/times.rs new file mode 100644 index 000000000..1881cdb7f --- /dev/null +++ b/crates/metal2vulkan-runtime/src/tests/times.rs @@ -0,0 +1,25 @@ +//! A command buffer's times (`times.rs`) without a device: the durations of the GPU's ticks across +//! the wrap of their valid bits, and the host clock they are placed on rising. + +use crate::times::Ticks; + +#[test] +fn durations_count_ticks_of_the_period_across_a_wrap() { + let ticks = Ticks::new(52.083_332, 36); + assert_eq!(ticks.span(1_000, 1_000), 0); + assert_eq!(ticks.span(1_000, 1_096), 5_000); + // From 10 ticks before the 36 bits wrap to 5 after: 15 ticks. + let before = (1u64 << 36) - 10; + assert_eq!(ticks.span(before, 5), 781); + // An end before the start is no duration. + assert_eq!(ticks.span(1_096, 1_000), 0); + let full = Ticks::new(1.0, 64); + assert_eq!(full.span(u64::MAX - 1, 3), 5); +} + +#[test] +fn the_host_time_rises() { + let first = crate::host_time(); + let second = crate::host_time(); + assert!(first > 0 && second >= first, "{first} then {second}"); +}