🎨 Fold reims-vgpu-core into reims-vgpu-vulkan as its core module

The Vulkan crate is the library's only platform since the Metal platform
went, and every crate that links core links the Vulkan crate too, so core
needs no crate of its own. Its files move unchanged under
reims_vgpu_vulkan::core (crate::core in the Vulkan crate), the module the
video crate's layout already uses; its #[macro_export] macros stay at the
crate's root, so reims_vgpu_core::metal_check! is reims_vgpu_vulkan's now.
core's lint set is the module's inner attributes, as it was the crate's.
Nothing the guest or the host observes changes, and reims_vgpu.h is the
same. Core's log lines name reims_vgpu_vulkan::core:: as their target in
place of reims_vgpu_core::, so reims-ctl's example filter says so.

The testkit feature is the Vulkan crate's, reims-vgpu-vulkan/testkit, and
the crate's integration tests turn it on through a dev-dependency on the
crate itself, as core's dependents turned core's on. core's tests keep
their paths below core:: in the Vulkan crate's unit tests, and cargo xtask
check's x86_64-apple-darwin leg runs those alone: -p reims-vgpu-vulkan
--lib -E 'test(/^core::/)'. The tests that run themselves again in a child
name themselves below core:: too (a child given a name that matches no
test runs nothing and passes), and the memory map's tests take the lines
of the targets below reims_vgpu_vulkan::core::memory.

The macOS test that declares _exit now declares it safe, as the testkit
does: rustc's clashing_extern_declarations compares the declarations
within one crate.
This commit is contained in:
Anees Iqbal committed 2026-11-08 01:55:07 -08:00
1 parent 249d87da0c
commit fd591f5039
261 files changed
+2828 -2818

No files matched your search

+1 -1
View File
@@ -145,7 +145,7 @@ The video crates' checks:
```sh
ulimit -c 0
scripts/internal/gpu-locks.sh --all -- cargo nextest run --workspace --no-fail-fast \
--features reims-vgpu-core/testkit,reims-vgpu/testkit,reims-vgpu/vulkan,reims-vgpu-c/vulkan
--features reims-vgpu-vulkan/testkit,reims-vgpu/testkit,reims-vgpu/vulkan,reims-vgpu-c/vulkan
scripts/internal/gpu-locks.sh --all -- cargo nextest run -p reims-vgpu-video --run-ignored only -E 'test(/^vaapi::/)' # the VA-API host
scripts/internal/gpu-locks.sh --all -- cargo nextest run -p reims-vgpu-video --run-ignored only -E 'test(/^nvidia::/)' # the NVIDIA host
```
Generated
+5 -14
View File
@@ -448,7 +448,6 @@ dependencies = [
"objc2-foundation",
"objc2-metal",
"parking_lot",
"reims-vgpu-core",
"reims-vgpu-graphics",
"reims-vgpu-video",
"reims-vgpu-vulkan",
@@ -467,21 +466,11 @@ dependencies = [
"objc2-foundation",
"parking_lot",
"reims-vgpu",
"reims-vgpu-core",
"reims-vgpu-graphics",
"reims-vgpu-vulkan",
"tikv-jemallocator",
]
[[package]]
name = "reims-vgpu-core"
version = "0.1.0"
dependencies = [
"log",
"lzma-rs",
"parking_lot",
"zerocopy",
]
[[package]]
name = "reims-vgpu-graphics"
version = "0.1.0"
@@ -516,6 +505,7 @@ dependencies = [
"ash",
"libc",
"log",
"lzma-rs",
"mach2",
"metal2vulkan",
"metal2vulkan-runtime",
@@ -523,8 +513,10 @@ dependencies = [
"objc2-foundation",
"objc2-io-surface",
"objc2-metal",
"reims-vgpu-core",
"parking_lot",
"reims-vgpu-vulkan",
"sha2 0.10.9",
"zerocopy",
]
[[package]]
@@ -542,7 +534,6 @@ dependencies = [
"objc2-foundation",
"objc2-metal",
"objc2-quartz-core",
"reims-vgpu-core",
"reims-vgpu-vulkan",
"sdl3-sys",
]
-2
View File
@@ -2,7 +2,6 @@
[workspace]
resolver = "3"
members = [
"crates/reims-vgpu-core",
"crates/reims-vgpu-window",
"crates/reims-vgpu",
"crates/reims-vgpu-c",
@@ -21,7 +20,6 @@ publish = false
license = "GPL-2.0-or-later OR LGPL-3.0-or-later"
[workspace.dependencies]
reims-vgpu-core = { path = "crates/reims-vgpu-core" }
# Without their default features: each member that wants SDL3's macOS window asks for it
# (`macos-sdl`), so `reims-vgpu-c`'s default decides whether the library has it.
reims-vgpu-window = { path = "crates/reims-vgpu-window", default-features = false }
+1 -1
View File
@@ -355,7 +355,7 @@ pub struct SetArgs {
pub gpu: Option<String>,
#[arg(long, num_args = 0..=1, default_missing_value = "true")]
pub logs: Option<bool>,
/// REIMS_VGPU_LOG's filter, such as info or warn,reims_vgpu_core=debug
/// REIMS_VGPU_LOG's filter, such as info or warn,reims_vgpu_vulkan::core=debug
#[arg(long)]
pub log_level: Option<String>,
#[arg(long, num_args = 0..=1, default_missing_value = "true")]
+2 -2
View File
@@ -27,7 +27,7 @@ reims-vgpu.workspace = true
reims-vgpu-graphics.workspace = true
# The death of a NULL handle, and the mark of the library's threads (the unit tests' testkit
# platform stands where VulkanPlatform stands in the product).
reims-vgpu-core.workspace = true
reims-vgpu-vulkan.workspace = true
# A refusal of a memory map's files.
log.workspace = true
# `fstat` and the host's page size, for the files behind a memory map's ranges.
@@ -43,7 +43,7 @@ objc2.workspace = true
[dev-dependencies]
reims-vgpu = { workspace = true, features = ["testkit"] }
reims-vgpu-core = { workspace = true, features = ["testkit"] }
reims-vgpu-vulkan = { workspace = true, features = ["testkit"] }
# The window tests' recorder.
parking_lot.workspace = true
+2 -2
View File
@@ -15,8 +15,8 @@
//! Linux. The host's function-pointer types stay `extern "C-unwind"`, since both are sound only
//! around an ABI that unwinds.
use reims_vgpu_core::raise::death::{DeathId, fatal};
use reims_vgpu_core::rt::enter_ours;
use reims_vgpu_vulkan::core::raise::death::{DeathId, fatal};
use reims_vgpu_vulkan::core::rt::enter_ours;
mod catch;
+2 -2
View File
@@ -3,8 +3,8 @@
use std::os::unix::process::ExitStatusExt as _;
use std::process::Command;
use reims_vgpu_core::raise::death::{DeathKind, DeathSite};
use reims_vgpu_core::rt::is_our_thread;
use reims_vgpu_vulkan::core::raise::death::{DeathKind, DeathSite};
use reims_vgpu_vulkan::core::rt::is_our_thread;
use super::*;
+1 -1
View File
@@ -1,7 +1,7 @@
//! The catch on Linux: a Rust unwind out of the host's code that no panic hook ended first ends
//! the process at the call.
use reims_vgpu_core::testkit::capture::catch_death;
use reims_vgpu_vulkan::core::testkit::capture::catch_death;
use super::*;
+1 -1
View File
@@ -5,7 +5,7 @@ use objc2::exception::{self, Exception};
use objc2::rc::Retained;
use objc2::runtime::{AnyObject, NSObject};
use objc2_foundation::{NSException, NSString};
use reims_vgpu_core::testkit::capture::catch_death;
use reims_vgpu_vulkan::core::testkit::capture::catch_death;
use super::*;
+2 -2
View File
@@ -57,11 +57,11 @@ static ALLOCATOR: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
pub(crate) type Plat = reims_vgpu::VulkanPlatform;
/// The platform every handle is made on: core's testkit platform in this crate's unit tests.
#[cfg(test)]
pub(crate) type Plat = reims_vgpu_core::testkit::FakePlatform;
pub(crate) type Plat = reims_vgpu_vulkan::core::testkit::FakePlatform;
/// Ends the process: `call` was given a NULL handle it cannot answer without one.
pub(crate) fn null_handle(call: &'static str) -> ! {
use reims_vgpu_core::raise::death::{DeathId, DeathKind, fatal};
use reims_vgpu_vulkan::core::raise::death::{DeathId, DeathKind, fatal};
fatal(DeathId::Platform {
kind: DeathKind::NullDeref,
call,
-26
View File
@@ -1,26 +0,0 @@
[package]
name = "reims-vgpu-core"
description = "What the graphics device and its platform share, generic over the platform; links no Apple framework"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
publish.workspace = true
license.workspace = true
[features]
# core::testkit and testkit::capture outside this crate's own unit tests (architecture 13.2).
testkit = ["dep:lzma-rs"]
# Architecture 2.2: no objc2, block2, dispatch2, mach2 or libc here.
[dependencies]
parking_lot.workspace = true
zerocopy.workspace = true
log.workspace = true
# testkit::metal_answers: the recorded answers too long for text, in xz files.
lzma-rs = { workspace = true, optional = true }
[dev-dependencies]
lzma-rs.workspace = true
[lints]
workspace = true
+14 -2
View File
@@ -7,8 +7,16 @@ rust-version.workspace = true
publish.workspace = true
license.workspace = true
[features]
# core::testkit and testkit::capture outside this crate's own unit tests (architecture 13.2).
testkit = ["dep:lzma-rs"]
[dependencies]
reims-vgpu-core.workspace = true
# core (`core`): its locks (`core::sync`), and the guest's physical ranges as bytes (`core::host`).
parking_lot.workspace = true
zerocopy.workspace = true
# core's testkit::metal_answers: the recorded answers too long for text, in xz files.
lzma-rs = { workspace = true, optional = true }
metal2vulkan-runtime.workspace = true
metal2vulkan.workspace = true
# The debug lines that time the runtime's compiles (gpu/timing.rs), through core's logger.
@@ -39,7 +47,11 @@ libc.workspace = true
sha2.workspace = true
[dev-dependencies]
reims-vgpu-core = { workspace = true, features = ["testkit"] }
# core's testkit for the integration tests (`tests/`), which link the library as other
# crates do.
reims-vgpu-vulkan = { path = ".", features = ["testkit"] }
# core's testkit in the unit tests, compiled under cfg(test).
lzma-rs.workspace = true
[lints]
workspace = true
+27 -27
View File
@@ -128,11 +128,11 @@
use std::cell::{Cell, RefCell};
use std::ptr::NonNull;
use crate::core::platform::types::NsErrorText;
use crate::core::raise::death::{DeathId, DeathKind, fatal_with_detail};
use crate::core::raise::{OnFault, Raise, RaiseResult};
use metal2vulkan_runtime as rt;
use metal2vulkan_runtime::Error;
use reims_vgpu_core::platform::types::NsErrorText;
use reims_vgpu_core::raise::death::{DeathId, DeathKind, fatal_with_detail};
use reims_vgpu_core::raise::{OnFault, Raise, RaiseResult};
pub mod census;
pub mod native;
@@ -1921,8 +1921,8 @@ pub fn trace_degradations() -> bool {
}
/// The kinds the trace saw, which the runtime announces once without it.
static TRACED_KINDS: reims_vgpu_core::sync::Mutex<Vec<rt::Degradation>> =
reims_vgpu_core::sync::Mutex::new(Vec::new());
static TRACED_KINDS: crate::core::sync::Mutex<Vec<rt::Degradation>> =
crate::core::sync::Mutex::new(Vec::new());
/// The runtime's message sink (`DeviceOptions::messages`, [`crate::platform`]): a degradation
/// of [`DIES`] is relayed and counted, or in strict mode kept for the call here it was announced
@@ -1940,10 +1940,10 @@ pub fn notice(message: &rt::DebugMessage) {
if UNHEARD.with(Cell::get) {
return;
}
if trace_degradations() && reims_vgpu_core::trace::on() {
if trace_degradations() && crate::core::trace::on() {
let kind = notice.degradation;
// deg: an occurrence of a degradation, its code
reims_vgpu_core::trace::event_text("deg", &[], kind.code());
crate::core::trace::event_text("deg", &[], kind.code());
// A kind announced once without the trace goes on only at its first occurrence.
if !DIES.contains(&kind) && !HEARD.contains(&kind) {
let mut seen = TRACED_KINDS.lock();
@@ -2014,8 +2014,8 @@ fn hear(kind: rt::Degradation) {
/// The degradations not of [`DIES`] the runtime announced in this process, in order, which
/// [`notice`] relays and a test reads.
#[cfg(test)]
pub(crate) static RELAYED: reims_vgpu_core::sync::Mutex<Vec<rt::Degradation>> =
reims_vgpu_core::sync::Mutex::new(Vec::new());
pub(crate) static RELAYED: crate::core::sync::Mutex<Vec<rt::Degradation>> =
crate::core::sync::Mutex::new(Vec::new());
/// The least severity the sink hears of the messages that are no degradation
/// (`MessageSink::with_least_severity`): `Verbose` where the log takes this module's debug lines,
@@ -2147,8 +2147,8 @@ pub fn refused(sel: &'static str, e: &Error) -> ! {
/// The line of the last death [`dies`] made in this process, which a test reads: the test
/// capture takes a death before its line is written.
#[cfg(test)]
pub(crate) static LAST_LINE: reims_vgpu_core::sync::Mutex<Option<String>> =
reims_vgpu_core::sync::Mutex::new(None);
pub(crate) static LAST_LINE: crate::core::sync::Mutex<Option<String>> =
crate::core::sync::Mutex::new(None);
/// The death at `sel` of [`refused`], [`metal_aborts`] and [`unrepresentable`], its line
/// `line`.
@@ -2494,7 +2494,7 @@ pub fn relays_gap(e: &Error) -> bool {
/// writing a line on stderr naming the refusal and `descriptor` ([`refusal_describing`]). The
/// creator then answers nil, a pipeline or library creator with [`error_text`] as its
/// `NSError`, and the relay is noted for core on the creator's thread
/// ([`reims_vgpu_core::platform::device::note_relayed_gap`]), which faults the work that names a
/// ([`crate::core::platform::device::note_relayed_gap`]), which faults the work that names a
/// function so refused where Metal would end the process at the nil one create later. `false` in
/// strict mode and for every other refusal, which the creator decides as before: a death at
/// `sel`.
@@ -2502,7 +2502,7 @@ pub fn relay_gap(sel: &'static str, e: &Error, descriptor: Option<&str>) -> bool
if !relays_gap(e) {
return false;
}
reims_vgpu_core::platform::device::note_relayed_gap();
crate::core::platform::device::note_relayed_gap();
if counted_first(Inexact::RefusedCreate) {
let line = format!(
"reims-vgpu: {sel}: {}; answered nil, relayed ({}), the first of its kind: \
@@ -2576,9 +2576,9 @@ pub fn hang() -> ! {
pub(crate) fn dies_of<T>(
kind: rt::Degradation,
call: impl FnOnce() -> T,
) -> reims_vgpu_core::raise::death::DeathSite {
) -> crate::core::raise::death::DeathSite {
*LAST_LINE.lock() = None;
let Err(site) = reims_vgpu_core::testkit::capture::catch_death(call) else {
let Err(site) = crate::core::testkit::capture::catch_death(call) else {
panic!("it did not die, where {} dies", kind.code());
};
let line = LAST_LINE.lock().take().unwrap_or_default();
@@ -2593,10 +2593,10 @@ pub(crate) fn dies_of<T>(
#[cfg(test)]
mod tests {
use super::*;
use crate::core::platform::device::relaying_gaps;
use crate::core::raise::{Origin, RaiseId};
use crate::core::testkit::capture::catch_death;
use metal2vulkan_runtime::{Invalid, Problem, RuntimeGap};
use reims_vgpu_core::platform::device::relaying_gaps;
use reims_vgpu_core::raise::{Origin, RaiseId};
use reims_vgpu_core::testkit::capture::catch_death;
fn invalid() -> Error {
Error::Invalid(Invalid::new("fill_buffer", Problem::StorageMode))
@@ -3175,7 +3175,7 @@ mod tests {
relaxed(|| inexact("sel:", Inexact::HeapLayout, || "a value".into()));
assert_eq!(counted(), before + 2);
*LAST_LINE.lock() = None;
let site = reims_vgpu_core::testkit::capture::catch_death(|| {
let site = crate::core::testkit::capture::catch_death(|| {
inexact("sel:", Inexact::HeapLayout, || "a value".into());
})
.unwrap_err();
@@ -3236,10 +3236,10 @@ mod tests {
/// `two_plane_xr10_blits_metal_was_not_measured_at_die`)
#[test]
fn a_call_that_unwinds_lets_its_notice_go() {
use reims_vgpu_core::platform::Platform as _;
use reims_vgpu_core::platform::device::GpuDevice as _;
use reims_vgpu_core::platform::values::TextureDesc;
use reims_vgpu_core::raise::OnFault;
use crate::core::platform::Platform as _;
use crate::core::platform::device::GpuDevice as _;
use crate::core::platform::values::TextureDesc;
use crate::core::raise::OnFault;
let d = crate::gpu::device::tests::dev();
let desc = crate::platform::tests::platform().texture_descriptor(&TextureDesc {
pixel_format: 550,
@@ -3287,10 +3287,10 @@ mod tests {
/// The copy of `a_call_that_unwinds_lets_its_notice_go` announces `TwoPlaneTextureCopy`
#[test]
fn a_kind_of_dies_is_relayed_and_counted_by_default() {
use reims_vgpu_core::platform::Platform as _;
use reims_vgpu_core::platform::device::GpuDevice as _;
use reims_vgpu_core::platform::values::TextureDesc;
use reims_vgpu_core::raise::OnFault;
use crate::core::platform::Platform as _;
use crate::core::platform::device::GpuDevice as _;
use crate::core::platform::values::TextureDesc;
use crate::core::raise::OnFault;
let kind = rt::Degradation::TwoPlaneTextureCopy;
let counted = || {
(relayed_counts().into_iter())
@@ -35,9 +35,9 @@ use std::path::{Path, PathBuf};
use std::sync::{Once, OnceLock};
use std::time::Duration;
use crate::core::platform::os::{Clock as _, Deadline};
use crate::core::sync::{Condvar, Mutex};
use metal2vulkan_runtime as rt;
use reims_vgpu_core::platform::os::{Clock as _, Deadline};
use reims_vgpu_core::sync::{Condvar, Mutex};
use super::native::{self, Placement};
+2 -2
View File
@@ -1,8 +1,8 @@
//! What the Rust API (`reims-vgpu`) asks of this platform beyond core's `Platform`: a frame
//! target's pixels ([`read_pixels`]).
use crate::core::num::ToU64;
use metal2vulkan_runtime as rt;
use reims_vgpu_core::num::ToU64;
use crate::answer::{get, plain};
use crate::gpu::resource::VulkanTexture;
@@ -23,8 +23,8 @@ pub fn read_pixels(texture: &VulkanTexture, dst: &mut [u8], bytes_per_row: usize
#[cfg(test)]
mod tests {
use crate::core::platform::Handle as _;
use metal2vulkan::metal::PixelFormat;
use reims_vgpu_core::platform::Handle as _;
use super::*;
use crate::gpu::device::tests::dev;
+2 -2
View File
@@ -72,10 +72,10 @@ use std::sync::{Arc, OnceLock};
use std::thread::Thread;
use std::time::Duration;
use crate::core::platform::os::clock::{Clock as _, Deadline, MonoTime};
use crate::core::sync::{Mutex, MutexGuard};
use ash::vk;
use metal2vulkan_runtime as rt;
use reims_vgpu_core::platform::os::clock::{Clock as _, Deadline, MonoTime};
use reims_vgpu_core::sync::{Mutex, MutexGuard};
/// How long after the guest's last GPU work the GPU is kept awake.
pub(crate) const AWAKE_FOR: Duration = Duration::from_secs(5 * 60);
@@ -3,10 +3,10 @@
//! deaths, the guest's RAM as the host maps it, and the testkit's fake platform, which the tests
//! run in the Vulkan platform's place. Links no Apple framework.
// The crate root denies `unsafe_code` (D43): `forbid` cannot be lowered by the per-module
// The module denies `unsafe_code` (D43): `forbid` cannot be lowered by the per-module
// `#![allow(unsafe_code)]` that 17.3 grants `testkit/guest_ram.rs` (E0453).
#![deny(unsafe_code)]
// The crate's lint set. Tests are exempt: clippy.toml lets them unwrap, index and panic,
// The module's lint set. Tests are exempt: clippy.toml lets them unwrap, index and panic,
// and the conversion and division lints apply outside cfg(test) only, as clippy has no in-tests
// switch for them. `arithmetic_side_effects` is denied only in the modules guest data flows
// through (their own attributes).
@@ -9,7 +9,7 @@
use std::hash::{BuildHasherDefault, Hasher};
use crate::num::ToU64;
use crate::core::num::ToU64;
/// The odd multiplier, a 64-bit constant with its bits spread (the one `rustc-hash` 2 uses).
const K: u64 = 0xf135_7aea_2e62_a9c5;
@@ -5,7 +5,7 @@ pub mod pipeline;
use std::fmt;
use crate::raise::death::DeathId;
use crate::core::raise::death::DeathId;
/// Where a display's pipelines end the process.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -32,14 +32,14 @@ impl DeathKind {
}
/// The kind of death.
pub(crate) const fn class(self) -> crate::raise::death::DeathKind {
crate::raise::death::DeathKind::Assert
pub(crate) const fn class(self) -> crate::core::raise::death::DeathKind {
crate::core::raise::death::DeathKind::Assert
}
/// The site a death of this kind names (tests).
#[cfg(test)]
pub(crate) fn site(self) -> crate::raise::death::DeathSite {
crate::raise::death::DeathId::from(self).site()
pub(crate) fn site(self) -> crate::core::raise::death::DeathSite {
crate::core::raise::death::DeathId::from(self).site()
}
}
@@ -1,13 +1,13 @@
//! A display's render pipelines, by the target's pixel format and whether there is a gamma
//! table. The table is looked up and set under its mutex, never iterated.
use crate::collections::LookupMap;
use crate::display::DeathKind;
use crate::platform::device::GpuDevice;
use crate::platform::resource::Library;
use crate::platform::values::RenderPipelineDesc;
use crate::platform::{Handle, Platform};
use crate::raise::OnFault;
use crate::core::collections::LookupMap;
use crate::core::display::DeathKind;
use crate::core::platform::device::GpuDevice;
use crate::core::platform::resource::Library;
use crate::core::platform::values::RenderPipelineDesc;
use crate::core::platform::{Handle, Platform};
use crate::core::raise::OnFault;
/// The name of the vertex function in the platform's shader library.
pub const VERTEX_FUNCTION: &str = "displayPresentVertex";
@@ -124,9 +124,9 @@ impl<P: Platform> Drop for DisplayPipelineCache<P> {
#[cfg(test)]
mod tests {
use super::*;
use crate::testkit::calllog::Arg;
use crate::testkit::capture::catch_death;
use crate::testkit::{FakePlatform, Step};
use crate::core::testkit::calllog::Arg;
use crate::core::testkit::capture::catch_death;
use crate::core::testkit::{FakePlatform, Step};
fn cache(p: &FakePlatform) -> DisplayPipelineCache<FakePlatform> {
DisplayPipelineCache::new(p.device()).unwrap()
@@ -207,7 +207,7 @@ mod tests {
assert_eq!(
r.err().map(|s| (s.kind, s.file, s.line)),
Some((
crate::raise::DeathKind::UncaughtObjc,
crate::core::raise::DeathKind::UncaughtObjc,
"newLibraryWithSource:options:error:",
0
))
@@ -2,7 +2,7 @@
//! (`queue`).
//!
//! These are the consumer's (QEMU's) values, not platform APIs: the platform is what core calls
//! on Apple's frameworks, the host is who called core. Every item is at `crate::host::…`.
//! on Apple's frameworks, the host is who called core. Every item is at `crate::core::host::…`.
mod queue;
mod types;
@@ -5,7 +5,7 @@
use std::sync::Arc;
use crate::rt::queue::Executor;
use crate::core::rt::queue::Executor;
/// The queue a display's calls into the host run on (the display descriptor's `queue`): each
/// call of a display handler is submitted to it, and the newFrame source targets it. Jobs run one
@@ -26,7 +26,7 @@ mod tests {
fn host_queue_upcasts() {
struct Inline;
impl Executor for Inline {
fn exec_async(&self, job: crate::rt::Job) {
fn exec_async(&self, job: crate::core::rt::Job) {
job()
}
}
@@ -28,7 +28,7 @@ use std::sync::{Arc, OnceLock};
use log::{Level, LevelFilter, Log, Metadata, Record};
use crate::sync::Mutex;
use crate::core::sync::Mutex;
/// The environment variable that turns the stderr logger on, and holds its filter.
pub const ENV_VAR: &str = "REIMS_VGPU_LOG";
@@ -410,7 +410,7 @@ mod tests {
(Some("info,reims_vgpu::work=debug"), true),
] {
let out = child(
"logging::tests::the_process_names_a_target_only_by_the_variables_pair",
"core::logging::tests::the_process_names_a_target_only_by_the_variables_pair",
env,
);
assert!(out.status.success(), "{env:?}: {out:?}");
@@ -561,7 +561,7 @@ mod tests {
return;
}
let out = child(
"logging::tests::the_process_logger_writes_stderr_until_a_hook_takes_over",
"core::logging::tests::the_process_logger_writes_stderr_until_a_hook_takes_over",
Some("info,reims_vgpu::graphics=debug"),
);
assert!(out.status.success(), "{out:?}");
@@ -608,7 +608,7 @@ mod tests {
return;
}
let out = child(
"logging::tests::the_process_logger_is_silent_without_the_variable",
"core::logging::tests::the_process_logger_is_silent_without_the_variable",
None,
);
assert!(out.status.success(), "{out:?}");
@@ -643,7 +643,7 @@ mod tests {
return;
}
let out = child(
"logging::tests::the_process_logger_yields_to_the_hosts",
"core::logging::tests::the_process_logger_yields_to_the_hosts",
Some("trace"),
);
assert!(out.status.success(), "{out:?}");
@@ -32,8 +32,8 @@ pub mod mapping;
use std::fmt;
use crate::raise::DeathId;
use crate::raise::death::{self, DeathSite};
use crate::core::raise::DeathId;
use crate::core::raise::death::{self, DeathSite};
/// The granule a mapping's length is whole multiples of ([`map::MemoryMap::new_range_mapping`]):
/// 16 KiB, 4 KiB in an x86-64 build.
@@ -1,6 +1,6 @@
//! The host's description of guest memory: its ranges, as the host added them.
use crate::host::HostPtr;
use crate::core::host::HostPtr;
/// One range of guest physical memory and where the host mapped it.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
@@ -4,13 +4,13 @@
use std::num::NonZeroU64;
use std::sync::Arc;
use crate::host::{HostPtr, PhysRange};
use crate::memory::descriptor::MemoryMapDescriptor;
use crate::memory::mapping::{Mapping, Teardown};
use crate::memory::{DeathKind, PAGE_SIZE};
use crate::num::{ToU64, ToUsize};
use crate::platform::Platform;
use crate::platform::os::vm::{HostVm, VmProt};
use crate::core::host::{HostPtr, PhysRange};
use crate::core::memory::descriptor::MemoryMapDescriptor;
use crate::core::memory::mapping::{Mapping, Teardown};
use crate::core::memory::{DeathKind, PAGE_SIZE};
use crate::core::num::{ToU64, ToUsize};
use crate::core::platform::Platform;
use crate::core::platform::os::vm::{HostVm, VmProt};
/// One range of the map: `{start, start + length, length, host pointer}`. The field names are
/// ours.
@@ -441,13 +441,13 @@ impl<P: Platform> MemoryMap<P> {
#[cfg(test)]
mod tests {
use super::*;
use crate::memory::descriptor::GuestPhysicalRange;
use crate::platform::os::vm::KernReturn;
use crate::testkit::calllog::{Arg, Call};
use crate::testkit::capture::catch_death;
use crate::testkit::guest_ram::GuestRam;
use crate::testkit::platform::FakePlatform;
use crate::testkit::script::Step;
use crate::core::memory::descriptor::GuestPhysicalRange;
use crate::core::platform::os::vm::KernReturn;
use crate::core::testkit::calllog::{Arg, Call};
use crate::core::testkit::capture::catch_death;
use crate::core::testkit::guest_ram::GuestRam;
use crate::core::testkit::platform::FakePlatform;
use crate::core::testkit::script::Step;
type Map = MemoryMap<FakePlatform>;
@@ -460,11 +460,11 @@ mod tests {
}
/// The memory area's lines `logs` took since its last take, in order.
fn memory_lines(logs: &crate::testkit::logs::Capture) -> Vec<String> {
fn memory_lines(logs: &crate::core::testkit::logs::Capture) -> Vec<String> {
logs.take()
.into_iter()
.filter(|(_, target, _)| {
target.starts_with(concat!(env!("CARGO_CRATE_NAME"), "::memory"))
target.starts_with(concat!(env!("CARGO_CRATE_NAME"), "::core::memory"))
})
.map(|(_, _, message)| message)
.collect()
@@ -582,7 +582,7 @@ mod tests {
gpr(0x4000, 0x8000, fake_host(1)), // would be an intersection after the sort
gpr(u64::MAX, 1, fake_host(2)),
]);
let logs = crate::testkit::logs::capture();
let logs = crate::core::testkit::logs::capture();
assert!(Map::new(p.clone(), &d).is_none());
assert_eq!(
memory_lines(&logs),
@@ -609,7 +609,7 @@ mod tests {
gpr(0x8000, 0x4000, fake_host(1)),
gpr(0x4000, 0x8000, fake_host(0)),
]);
let logs = crate::testkit::logs::capture();
let logs = crate::core::testkit::logs::capture();
assert!(Map::new(p.clone(), &d).is_none());
assert_eq!(memory_lines(&logs), vec![INTERSECTION.to_owned()]);
}
@@ -659,7 +659,7 @@ mod tests {
gpr(0x8000, 0x8000, fake_host(1)),
gpr(0x8000, 0x4000, fake_host(0)),
]);
let logs = crate::testkit::logs::capture();
let logs = crate::core::testkit::logs::capture();
assert!(Map::new(p.clone(), &d).is_none());
assert_eq!(memory_lines(&logs), vec![INTERSECTION.to_owned()]);
}
@@ -751,7 +751,7 @@ mod tests {
fn a_straddle_is_refused_with_a_log() {
let p = plat();
let m = map(&p);
let logs = crate::testkit::logs::capture();
let logs = crate::core::testkit::logs::capture();
assert!(m.virtual_address_for_physical(0x7ff0, 0x20).is_null());
assert_eq!(
memory_lines(&logs),
@@ -767,7 +767,7 @@ mod tests {
fn overflow_is_refused_with_a_log() {
let p = plat();
let m = map(&p);
let logs = crate::testkit::logs::capture();
let logs = crate::core::testkit::logs::capture();
assert!(m.virtual_address_for_physical(0x4000, u64::MAX).is_null());
assert_eq!(
memory_lines(&logs),
@@ -779,7 +779,7 @@ mod tests {
fn outside_every_range_and_empty_ranges_are_null_silently() {
let p = plat();
let m = map(&p);
let logs = crate::testkit::logs::capture();
let logs = crate::core::testkit::logs::capture();
assert!(m.virtual_address_for_physical(0x0, 1).is_null());
assert!(m.virtual_address_for_physical(0xc000, 1).is_null());
assert!(m.virtual_address_for_physical(0x10000, 0).is_null());
@@ -843,7 +843,7 @@ mod tests {
let (_ram, m) = ram_map(&p, &[(0x4000, 0x8000)]);
p.script()
.push("mach_vm_allocate", Step::value(KernReturn(3)));
let logs = crate::testkit::logs::capture();
let logs = crate::core::testkit::logs::capture();
assert!(m.new_range_mapping(&[pr(0x4000, PAGE)], PAGE, 0).is_none());
assert_eq!(sels(&p), vec!["mach_vm_allocate"]);
assert!(memory_lines(&logs).is_empty());
@@ -1160,7 +1160,7 @@ mod tests {
mod map_memory_at_virtual_address {
use super::*;
use crate::platform::os::vm::HostVm;
use crate::core::platform::os::vm::HostVm;
fn region(p: &FakePlatform, len: u64) -> HostPtr {
p.fake_vm().unlogged().allocate_anywhere(len).unwrap()
@@ -1213,7 +1213,7 @@ mod tests {
let p = plat();
let (_ram, m) = ram_map(&p, &[(0x4000, 0x4000)]);
let dst = region(&p, PAGE);
let logs = crate::testkit::logs::capture();
let logs = crate::core::testkit::logs::capture();
assert!(!m.map_memory_at_virtual_address(dst, &[pr(0, 0)], false));
assert!(vm_calls(&p).is_empty());
assert!(memory_lines(&logs).is_empty());
@@ -1224,7 +1224,7 @@ mod tests {
let p = plat();
let (_ram, m) = ram_map(&p, &[(0x4000, 0x4000)]);
let dst = region(&p, PAGE);
let logs = crate::testkit::logs::capture();
let logs = crate::core::testkit::logs::capture();
assert!(!m.map_memory_at_virtual_address(
dst,
&[pr(0x4000, PAGE), pr(0x4000, u64::MAX)],
@@ -1247,7 +1247,7 @@ mod tests {
let p = plat();
let (_ram, m) = ram_map(&p, &[(0x4000, 0x4000)]);
let dst = region(&p, PAGE);
let logs = crate::testkit::logs::capture();
let logs = crate::core::testkit::logs::capture();
assert!(!m.map_memory_at_virtual_address(dst, &[pr(u64::MAX, 1)], false));
assert_eq!(
memory_lines(&logs),
@@ -1264,7 +1264,7 @@ mod tests {
let (_ram, m) = ram_map(&p, &[(0x4000, 0x4000)]);
let dst = region(&p, PAGE);
p.script().push("mach_vm_remap", Step::value(KernReturn(1)));
let logs = crate::testkit::logs::capture();
let logs = crate::core::testkit::logs::capture();
assert!(!m.map_memory_at_virtual_address(dst, &[pr(0x4000, PAGE)], false));
assert_eq!(memory_lines(&logs), vec![NOT_REMAPPED.to_owned()]);
assert_eq!(sels(&p), vec!["mach_vm_remap"]);
@@ -1276,7 +1276,7 @@ mod tests {
let (_ram, m) = ram_map(&p, &[(0x4000, 0x4000), (0x8000, 0x4000)]);
let dst = region(&p, 2 * PAGE);
p.script().push("mach_vm_remap", Step::value(KernReturn(1)));
let logs = crate::testkit::logs::capture();
let logs = crate::core::testkit::logs::capture();
assert!(!m.map_memory_at_virtual_address(dst, &[pr(0x4000, 2 * PAGE)], false));
assert_eq!(memory_lines(&logs), vec![NOT_REMAPPED.to_owned()]);
}
@@ -1290,7 +1290,7 @@ mod tests {
let p = plat();
let (_ram, m) = ram_map(&p, &[(0x4000, 0x4000)]);
let dst = region(&p, 2 * PAGE);
let logs = crate::testkit::logs::capture();
let logs = crate::core::testkit::logs::capture();
assert!(!m.map_memory_at_virtual_address(dst, &[pr(0x4000, 2 * PAGE)], false));
assert_eq!(
memory_lines(&logs),
@@ -1316,7 +1316,7 @@ mod tests {
let dst = region(&p, PAGE);
p.script()
.push("mach_vm_protect", Step::value(KernReturn(-1)));
let logs = crate::testkit::logs::capture();
let logs = crate::core::testkit::logs::capture();
assert!(!m.map_memory_at_virtual_address(dst, &[pr(0x4000, PAGE)], false));
// `kr` is an `int`, printed in hex as its bits.
assert_eq!(
@@ -2,8 +2,8 @@
use std::sync::Arc;
use crate::host::HostPtr;
use crate::platform::Platform;
use crate::core::host::HostPtr;
use crate::core::platform::Platform;
/// What a mapping's last release does.
pub enum Teardown<P: Platform> {
@@ -83,8 +83,8 @@ impl<P: Platform> Drop for Mapping<P> {
#[cfg(test)]
mod tests {
use super::*;
use crate::testkit::calllog::Arg;
use crate::testkit::platform::FakePlatform;
use crate::core::testkit::calllog::Arg;
use crate::core::testkit::platform::FakePlatform;
mod plain {
use super::*;
File renamed without changes.
@@ -21,9 +21,9 @@ pub mod resource;
pub mod types;
pub mod values;
use crate::raise::OnFault;
pub use crate::raise::Raise;
pub use crate::raise::RaiseResult;
use crate::core::raise::OnFault;
pub use crate::core::raise::Raise;
pub use crate::core::raise::RaiseResult;
pub use event::EventRef;
pub use host_range::HostRange;
pub use types::NilDefault;
@@ -196,7 +196,7 @@ macro_rules! nil_send {
($recv:expr, $method:ident ( $($arg:expr),* $(,)? )) => {
match &$recv {
Some(r) => r.$method($($arg),*),
None => $crate::platform::NilDefault::nil_default(),
None => $crate::core::platform::NilDefault::nil_default(),
}
};
}
@@ -16,7 +16,7 @@ use std::ops::Range;
use super::host_range::HostRange;
use super::types::{ClearColor, MtlOrigin, MtlRegion, MtlSize, NsRange};
use super::{Handle, Platform};
use crate::raise::{OnFault, RaiseResult};
use crate::core::raise::{OnFault, RaiseResult};
/// An `id<MTLResource>` core passes to `synchronizeResource:`, `useResources:count:usage:[stages:]`
/// and `memoryBarrierWithResources:count:`.
@@ -7,7 +7,7 @@
//! its accessor raises it again at the site that uses it, with the same identity and origin.
use super::types::{MtlSize, SizeAndAlign};
use crate::raise::{OnFault, RaiseResult};
use crate::core::raise::{OnFault, RaiseResult};
/// The sample counts core asks `supportsTextureSampleCount:` about, in order.
pub const SAMPLE_COUNTS: [u64; 4] = [1, 2, 4, 8];
@@ -327,8 +327,8 @@ impl DeviceCaps {
#[cfg(test)]
mod tests {
use super::*;
use crate::raise::Raise;
use crate::testkit::impls::device::fake_caps;
use crate::core::raise::Raise;
use crate::core::testkit::impls::device::fake_caps;
/// A raise kept in the caps is raised again where it is asked: the caller's under a handler,
/// and a death with none (the alignment is asked only with none); a kept answer is the
@@ -352,14 +352,14 @@ mod tests {
align: 0x4000
})
);
let death = crate::testkit::capture::catch_death(|| {
let death = crate::core::testkit::capture::catch_death(|| {
let _ = caps.min_linear_alignment_bgra8();
});
assert_eq!(
death.map_err(|d| d.file),
Err("minimumLinearTextureAlignmentForPixelFormat:")
);
let death = crate::testkit::capture::catch_death(|| {
let death = crate::core::testkit::capture::catch_death(|| {
let _ = caps.heap_buffer_page_private(OnFault::Die);
});
assert!(death.is_err());
@@ -4,7 +4,7 @@ use super::event::EventRef;
use super::types::{CommandBufferStatus, NsErrorText};
use super::values::ComputePassDesc;
use super::{Handle, Platform};
use crate::raise::{OnFault, RaiseResult};
use crate::core::raise::{OnFault, RaiseResult};
/// What a completed handler learns of its buffer: core's handlers read `status`, `error` and the
/// GPU times of the buffer they were added to, on Metal's completion thread. The platform reads
@@ -23,7 +23,7 @@ pub struct CompletedInfo {
/// The domain of the error a command buffer completes with where the platform's read of it, as
/// its completed handler ran, died in the refusal scope the handler's registration carried
/// ([`crate::raise::refusals::carry`]): the platform failed it there, where outside every scope
/// ([`crate::core::raise::refusals::carry`]): the platform failed it there, where outside every scope
/// the death ends the process. Not Metal's: only the graphics lane's handlers see it.
pub const REFUSED_DOMAIN: &str = "reims-vgpu.refused";
@@ -64,7 +64,7 @@ pub fn inside_commit() -> bool {
impl CompletedInfo {
/// What a completed handler learns of a command buffer whose read the platform refused
/// ([`REFUSED_DOMAIN`]): status `Error`, and an internal error naming the refusal.
pub fn refused(refusal: &crate::raise::refusals::Refusal) -> CompletedInfo {
pub fn refused(refusal: &crate::core::raise::refusals::Refusal) -> CompletedInfo {
CompletedInfo {
status: CommandBufferStatus::ERROR,
error: Some(NsErrorText {
@@ -100,12 +100,12 @@ impl CompletedInfo {
}
/// Runs completed handler `block` with what `read` finds of its command buffer, in the scope
/// `carried` names, the one the handler's registration carried ([`crate::raise::refusals::carry`]):
/// `carried` names, the one the handler's registration carried ([`crate::core::raise::refusals::carry`]):
/// a death in `read` hands `block` [`CompletedInfo::refused`] instead, and a death in `block` ends
/// only `block`, each logged. Outside every scope `read` and `block` run plainly, one after the
/// other, as they always did.
pub fn run_completed(
carried: crate::raise::refusals::Carried,
carried: crate::core::raise::refusals::Carried,
read: impl FnOnce() -> CompletedInfo,
block: CompletedHandler,
) {
@@ -126,7 +126,7 @@ pub fn run_completed(
/// A completed handler (`addCompletedHandler:`'s block). Runs once, on a Metal thread (4.2 item 6).
/// Where it is added inside a refusal scope, the platform runs its read of the buffer and the
/// handler in that scope ([`crate::raise::refusals::Carried`]): a death in the read hands the
/// handler in that scope ([`crate::core::raise::refusals::Carried`]): a death in the read hands the
/// handler [`CompletedInfo::refused`], and a death in the handler ends only the handler.
pub type CompletedHandler = Box<dyn FnOnce(CompletedInfo) + Send>;
@@ -15,7 +15,7 @@
use super::blit::ResourceRef;
use super::types::{MtlRegion, MtlSize, NsRange};
use super::{Handle, Platform};
use crate::raise::{OnFault, RaiseResult};
use crate::core::raise::{OnFault, RaiseResult};
/// One `MTLComputeCommandEncoder` command.
///
@@ -17,7 +17,7 @@ use super::values::{
AttachmentState, ColorAttachmentSet, DepthAttachmentSet, PassSet, StencilAttachmentSet,
};
use super::{Handle, Platform};
use crate::raise::{OnFault, RaiseResult};
use crate::core::raise::{OnFault, RaiseResult};
/// `MTLTextureDescriptor` (with its private selectors), made from a `TextureDesc` value
/// (`Platform::texture_descriptor`) or by the class method
@@ -25,7 +25,7 @@ use super::values::{
PagesPlane, RenderPipelineDesc, SamplerDesc,
};
use super::{Handle, Platform};
use crate::raise::{OnFault, RaiseResult};
use crate::core::raise::{OnFault, RaiseResult};
/// A deallocator Metal calls once when a no-copy buffer is freed (the
/// `newBufferWithBytesNoCopy:…deallocator:` block). `None` is a nil block.
@@ -1,7 +1,7 @@
//! Platform trait: `SharedEvent`; the event kinds a command buffer waits on or signals.
use super::{Handle, Platform};
use crate::raise::RaiseResult;
use crate::core::raise::RaiseResult;
/// `id<MTLSharedEvent>`.
pub trait SharedEvent<P: Platform>: Handle {
@@ -7,8 +7,8 @@
use std::marker::PhantomData;
use crate::host::HostPtr;
use crate::num::ToU64;
use crate::core::host::HostPtr;
use crate::core::num::ToU64;
/// `len` bytes of host memory at `ptr`, mapped for `'a`.
///
@@ -12,7 +12,7 @@
use super::types::{MtlRegion, MtlSize};
use super::{Handle, Platform};
use crate::raise::RaiseResult;
use crate::core::raise::RaiseResult;
/// `MTLIndirectCommandBuffer` (with `MTLIndirectCommandBufferSPI`).
pub trait IndirectCommandBuffer<P: Platform>: Handle {
@@ -11,7 +11,7 @@
use std::ffi::c_void;
use std::sync::OnceLock;
use crate::platform::Platform;
use crate::core::platform::Platform;
/// The platform's real autorelease pool.
#[derive(Debug, Clone, Copy)]
@@ -3,7 +3,7 @@
use std::time::Duration;
use crate::sync::{Condvar, MutexGuard};
use crate::core::sync::{Condvar, MutexGuard};
/// A point on the monotonic clock, in nanoseconds (name is ours: architecture 4.5 names the type;
/// the device's 2 s stamp-wait report waits on it). The clock is libc++'s
@@ -5,8 +5,8 @@
//! reference: not `Clone`, `.clone_ref()` is a `CFRetain` core makes, and `Drop` is `CFRelease`
//! (D6).
use crate::host::{HostPtr, PhysicalMemoryRange};
use crate::platform::{Handle, Platform};
use crate::core::host::{HostPtr, PhysicalMemoryRange};
use crate::core::platform::{Handle, Platform};
use super::vm::KernReturn;
@@ -4,7 +4,7 @@
use std::sync::Arc;
use super::{Clock, Deadline};
use crate::sync::{Condvar, MutexGuard};
use crate::core::sync::{Condvar, MutexGuard};
/// How core gets its threads (architecture 7.1). Core creates no OS thread that runs
/// Objective-C itself: the platform does, so that in production no Rust unwind handler sits at
@@ -5,7 +5,7 @@
use std::ops::BitOr;
use crate::host::HostPtr;
use crate::core::host::HostPtr;
/// A host virtual address (`mach_vm_address_t`). Host addresses are [`HostPtr`]s throughout core,
/// so that `guest` is the only place that turns one into a pointer.
@@ -11,8 +11,8 @@
use super::types::{MtlCoordinate2D, MtlSize, SizeAndAlign};
use super::{Handle, Platform};
use crate::host::HostPtr;
use crate::raise::{OnFault, RaiseResult};
use crate::core::host::HostPtr;
use crate::core::raise::{OnFault, RaiseResult};
/// `MTLRasterizationRateMap` (with `MTLRasterizationRateMapSPI`).
pub trait RateMap<P: Platform>: Handle {
@@ -19,7 +19,7 @@ use super::types::{
MtlRegion, MtlScissorRect, MtlSize, MtlViewport, NsRange, VertexAmplificationViewMapping,
};
use super::{Handle, Platform};
use crate::raise::{OnFault, RaiseResult};
use crate::core::raise::{OnFault, RaiseResult};
/// One `MTLRenderCommandEncoder` command.
///
@@ -14,8 +14,8 @@ use super::host_range::HostRange;
use super::types::{MtlRegion, MtlSize, NsRange, Swizzle};
use super::values::SurfacePlane;
use super::{Handle, Platform};
use crate::host::HostPtr;
use crate::raise::{OnFault, RaiseResult};
use crate::core::host::HostPtr;
use crate::core::raise::{OnFault, RaiseResult};
/// Architecture 4.1's name for the sampler state's bound (`type SamplerState: StateObject`).
pub use self::SamplerState as StateObject;
@@ -402,7 +402,7 @@ impl<T: NilDefault> NilDefault for Result<T, NsErrorText> {
}
}
impl<T: NilDefault> NilDefault for crate::raise::RaiseResult<T> {
impl<T: NilDefault> NilDefault for crate::core::raise::RaiseResult<T> {
fn nil_default() -> Self {
Ok(T::nil_default())
}
@@ -446,7 +446,7 @@ nil_default_is_default!(
PixelFormatInfo,
TextureLevelInfo,
CommandBufferStatus,
crate::host::HostPtr,
crate::core::host::HostPtr,
);
const _: () = assert!(size_of::<MtlSize>() == 24);
@@ -469,7 +469,7 @@ const _: () = assert!(std::mem::offset_of!(TextureLevelInfo, bytes_per_row) == 0
#[cfg(test)]
mod tests {
use super::*;
use crate::raise::RaiseResult;
use crate::core::raise::RaiseResult;
/// The `Make` constructors put each argument in its field
#[test]
@@ -12,7 +12,7 @@ use std::fmt;
use super::host_range::HostRange;
use super::types::{ClearColor, MtlSize, Swizzle};
use super::{Handle, ObjId, Platform};
use crate::host::HostPtr;
use crate::core::host::HostPtr;
/// One storage property of a buffer or heap descriptor. They alias one another in Metal
/// (`resourceOptions` holds the storage and hazard-tracking modes), so they apply in list order
@@ -786,7 +786,7 @@ impl Default for TextureDesc {
/// Where plane `plane` of an IOSurface lies in a buffer that stands for the surface, its first
/// byte the surface's base address, and what a texture over it reads of the surface besides
/// ([`crate::platform::resource::Buffer::new_texture_over_surface_plane`], Metal's
/// ([`crate::core::platform::resource::Buffer::new_texture_over_surface_plane`], Metal's
/// `newTextureWithDescriptor:iosurface:plane:` over such a buffer, which reads these from the
/// `IOSurfaceRef`).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -834,7 +834,7 @@ pub struct SurfaceFacts {
}
/// One plane of an IOSurface as its pages hold it, for
/// [`crate::platform::device::GpuDevice::surface_pages_in_place`]: where its rows of elements lie
/// [`crate::core::platform::device::GpuDevice::surface_pages_in_place`]: where its rows of elements lie
/// from the surface's first byte.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct PagesPlane {
@@ -857,7 +857,7 @@ impl PagesPlane {
}
/// What a device answers of textures over an IOSurface's own pages
/// ([`crate::platform::device::GpuDevice::surface_pages_in_place`]).
/// ([`crate::core::platform::device::GpuDevice::surface_pages_in_place`]).
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PagesInPlace {
/// Every texture over them, for any access, lies in place in the pages.
@@ -1040,17 +1040,17 @@ set_struct_impls!(StencilAttachmentSet { texture, resolve_texture } {
#[cfg(test)]
mod tests {
use super::*;
use crate::platform::command::{CommandBuffer, CommandQueue};
use crate::platform::descriptor::{RenderPassDescriptor, TextureDescriptor};
use crate::platform::device::GpuDevice;
use crate::platform::rate_map::RateMapDescriptor;
use crate::platform::resource::{
use crate::core::platform::command::{CommandBuffer, CommandQueue};
use crate::core::platform::descriptor::{RenderPassDescriptor, TextureDescriptor};
use crate::core::platform::device::GpuDevice;
use crate::core::platform::rate_map::RateMapDescriptor;
use crate::core::platform::resource::{
Buffer, GpuResource, Heap, Library, RenderPipeline, SamplerState,
};
use crate::raise::OnFault;
use crate::core::raise::OnFault;
use crate::testkit::calllog::Arg;
use crate::testkit::{FakePlatform, Step};
use crate::core::testkit::calllog::Arg;
use crate::core::testkit::{FakePlatform, Step};
/// The selectors sent since `m`.
fn sels(p: &FakePlatform, m: u64) -> Vec<&'static str> {
@@ -1084,8 +1084,11 @@ mod tests {
assert_eq!(sels(&p, m), ["setResourceOptions:"]);
assert_eq!((d.rotation(), d.storage_mode()), (2, 0));
let t = p.device().new_texture(OnFault::Die, &d).unwrap().unwrap();
assert_eq!(crate::platform::resource::Texture::resource_index(&t), 5);
assert_eq!(crate::platform::resource::Texture::width(&t), 8);
assert_eq!(
crate::core::platform::resource::Texture::resource_index(&t),
5
);
assert_eq!(crate::core::platform::resource::Texture::width(&t), 8);
}
/// The rate-map value, then the typed layer reads
@@ -1149,7 +1152,7 @@ mod tests {
assert_eq!(
pass.color(
2,
crate::testkit::impls::descriptor::AttachmentModel::texture_id
crate::core::testkit::impls::descriptor::AttachmentModel::texture_id
),
Some(t.id())
);
@@ -1247,7 +1250,7 @@ mod tests {
.unwrap()
.unwrap();
assert_eq!(
crate::platform::icb::IndirectCommandBuffer::resource_index(&icb),
crate::core::platform::icb::IndirectCommandBuffer::resource_index(&icb),
3
);
@@ -19,7 +19,7 @@ pub use death::{DeathId, DeathKind, DeathSite, fatal};
pub use kept::{Kept, keep_forever};
pub use on_fault::OnFault;
use crate::rt::held::Deferred;
use crate::core::rt::held::Deferred;
/// A raise's identity: what raised and why.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -66,7 +66,7 @@ pub struct Raise {
detail: Option<Box<str>>,
origin: Origin,
/// Released where a catch ends the raise, in its hold's holder
/// ([`Hold::land`](crate::rt::Hold::land)).
/// ([`Hold::land`](crate::core::rt::Hold::land)).
deferred: Deferred,
}
@@ -148,7 +148,7 @@ impl Raise {
}
/// The same raise, carrying `v` outward: `v` is released where a catch ends the raise, in its
/// hold's holder ([`Hold::land`](crate::rt::Hold::land)), after the catcher's report, and
/// hold's holder ([`Hold::land`](crate::core::rt::Hold::land)), after the catcher's report, and
/// never if it dies. It takes its place among that holder's values at the point it was
/// deferred.
pub fn defer<T: std::any::Any + Send>(mut self, v: T) -> Raise {
@@ -156,8 +156,8 @@ impl Raise {
self
}
/// What it carries, for a landing frame to add its values to ([`crate::rt::Held::raising`])
/// and a catch to land ([`Hold::land`](crate::rt::Hold::land)).
/// What it carries, for a landing frame to add its values to ([`crate::core::rt::Held::raising`])
/// and a catch to land ([`Hold::land`](crate::core::rt::Hold::land)).
pub(crate) fn deferred_mut(&mut self) -> &mut Deferred {
&mut self.deferred
}
@@ -250,16 +250,16 @@ impl fmt::Display for Raise {
#[macro_export]
macro_rules! raise {
($on:expr => $id:expr) => {
return $on.throw($crate::raise::Raise::new($id))
return $on.throw($crate::core::raise::Raise::new($id))
};
($on:expr => $id:expr, $detail:expr) => {
return $on.throw($crate::raise::Raise::new($id).with_detail($detail))
return $on.throw($crate::core::raise::Raise::new($id).with_detail($detail))
};
($id:expr) => {
return Err($crate::raise::Raise::new($id))
return Err($crate::core::raise::Raise::new($id))
};
($id:expr, $detail:expr) => {
return Err($crate::raise::Raise::new($id).with_detail($detail))
return Err($crate::core::raise::Raise::new($id).with_detail($detail))
};
}
@@ -4,7 +4,7 @@
//! process ends at the guest op that caused it and nothing after it reaches the host or the
//! guest. Where the process dies is the contract; the message and the signal are diagnostics.
//! The one exception unwinds instead: a death inside a refusal scope refuses the op it met
//! ([`crate::raise::refusals`]), which only the graphics lane opens.
//! ([`crate::core::raise::refusals`]), which only the graphics lane opens.
//!
//! [`DeathId`] names what died: an area's reason (its `Display` a dotted id), a raise nothing may
//! catch, a platform call, or a host call that raised. [`DeathSite`] and [`DeathKind`] are the
@@ -15,7 +15,7 @@
use std::fmt;
use crate::raise::{Origin, RaiseId};
use crate::core::raise::{Origin, RaiseId};
/// A death as the test capture names it: its [`DeathKind`], and the dotted id, call or selector
/// it names with a line (0 for a named id, the Rust line for a raise that dies where it was
@@ -45,7 +45,7 @@ pub enum DeathKind {
/// An out-of-bounds read that faults.
OutOfBounds,
/// A raise of core's own that dies at its site ([`DeathId::Raised`]): no handler is live
/// there, or the site lets none take it ([`crate::raise::Raise::fatal`]).
/// there, or the site lets none take it ([`crate::core::raise::Raise::fatal`]).
UnhandledRaise,
/// A platform exception with no handler live, or at a send that no handler may take.
UncaughtObjc,
@@ -83,12 +83,12 @@ pub enum DeathId {
/// The call: the block's SDK property name.
call: &'static str,
},
/// Memory's (`crate::memory::DeathKind`).
Memory(crate::memory::DeathKind),
/// Memory's (`crate::core::memory::DeathKind`).
Memory(crate::core::memory::DeathKind),
/// A display's pipelines'.
Display(crate::display::DeathKind),
Display(crate::core::display::DeathKind),
/// A panic in a refusal scope, which the scope refuses as a death there
/// ([`crate::raise::refusals`], "Panics"): no death site raises it.
/// ([`crate::core::raise::refusals`], "Panics"): no death site raises it.
Panic,
/// A test's own death at a site it names (the testkit's fakes and the tests of the death
/// machinery).
@@ -118,7 +118,7 @@ impl DeathId {
/// The site the test capture records: an area's death by its dotted name at line 0.
pub fn site(self) -> DeathSite {
match self {
DeathId::Raised { id, origin } => crate::raise::death_site(id, origin),
DeathId::Raised { id, origin } => crate::core::raise::death_site(id, origin),
DeathId::Platform { kind, call } => DeathSite {
kind,
file: call,
@@ -186,16 +186,16 @@ pub fn fatal_with_detail(id: impl Into<DeathId>, detail: &str) -> ! {
/// [`fatal`] with a detail after the id (a raise's).
pub(crate) fn die(id: DeathId, detail: Option<&str>) -> ! {
// A death inside a refusal scope (the graphics lane's ops) refuses the op instead.
crate::raise::refusals::trap(id, detail);
crate::core::raise::refusals::trap(id, detail);
#[cfg(any(test, feature = "testkit"))]
if crate::testkit::capture::capture_enabled() {
if crate::core::testkit::capture::capture_enabled() {
// A captured death unwinds quietly, before its line below is written: the line goes to
// stderr first, so a test that dies where it should not shows what it died of.
let _ = std::io::Write::write_all(
&mut std::io::stderr(),
format!("{}\n", message(&id, detail)).as_bytes(),
);
crate::testkit::capture::capture(id.site())
crate::core::testkit::capture::capture(id.site())
}
let mut line = message(&id, detail);
// The subprocess harness names the death by its site (`testkit::death::parse_death_line`).
@@ -213,7 +213,7 @@ pub(crate) fn die(id: DeathId, detail: Option<&str>) -> ! {
// One write, so the line never interleaves with another thread's.
let _ = std::io::stderr().write_all(line.as_bytes());
// The trace's last lines, the events that led here (a diagnostic).
crate::trace::flush_before_death();
crate::core::trace::flush_before_death();
#[allow(clippy::disallowed_methods)] // the one fatal path's abort (6.4)
std::process::abort()
}
@@ -230,7 +230,7 @@ fn message(id: &DeathId, detail: Option<&str>) -> String {
#[macro_export]
macro_rules! fatal {
($id:expr) => {
$crate::raise::death::fatal($id)
$crate::core::raise::death::fatal($id)
};
}
@@ -239,7 +239,7 @@ macro_rules! fatal {
macro_rules! fatal_unless {
($cond:expr, $id:expr) => {
if !($cond) {
$crate::raise::death::fatal($id)
$crate::core::raise::death::fatal($id)
}
};
}
@@ -247,7 +247,7 @@ macro_rules! fatal_unless {
#[cfg(test)]
mod tests {
use super::*;
use crate::testkit::capture::catch_death;
use crate::core::testkit::capture::catch_death;
/// `fatal` dies with the id's site; a test site names itself
#[test]
@@ -302,7 +302,7 @@ mod tests {
message(&raised, Some("the reason")),
"reims-vgpu: fatal: uncaught raise platform.raised at setPurgeableState:: the reason"
);
let area = DeathId::from(crate::display::DeathKind::NoLibrary);
let area = DeathId::from(crate::core::display::DeathKind::NoLibrary);
assert_eq!(
message(&area, None),
"reims-vgpu: fatal: display.pipeline.no_library"
@@ -5,7 +5,7 @@
//! ([`Raise::fatal`]), and a function its callers reach both ways takes an [`OnFault`] from its
//! caller, which says which of the two the call is (`raise!(on => id)`, [`OnFault::throw`]).
use crate::raise::{Raise, RaiseResult};
use crate::core::raise::{Raise, RaiseResult};
/// What a raise does in a function its callers reach both under a handler and with none: the
/// caller, which knows which of the two it is, says so. A caller reached only under a handler
@@ -34,9 +34,9 @@ impl OnFault {
#[cfg(test)]
mod tests {
use super::*;
use crate::raise::RaiseId;
use crate::raise::death::{DeathKind, DeathSite};
use crate::testkit::capture::catch_death;
use crate::core::raise::RaiseId;
use crate::core::raise::death::{DeathKind, DeathSite};
use crate::core::testkit::capture::catch_death;
fn a_raise() -> Raise {
Raise::new(RaiseId::Test { name: "on_fault" })
@@ -39,7 +39,7 @@ use std::cell::Cell;
use std::fmt;
use std::panic::{AssertUnwindSafe, catch_unwind, resume_unwind};
use crate::raise::death::DeathId;
use crate::core::raise::death::DeathId;
thread_local! {
/// How many scopes this thread is inside.
@@ -137,7 +137,7 @@ fn panic_message(payload: &(dyn std::any::Any + Send)) -> Option<String> {
fn panics_refused() -> bool {
#[cfg(any(test, feature = "testkit"))]
{
!crate::testkit::capture::capture_enabled()
!crate::core::testkit::capture::capture_enabled()
}
#[cfg(not(any(test, feature = "testkit")))]
{
@@ -207,9 +207,9 @@ pub(crate) fn trap(id: DeathId, detail: Option<&str>) {
#[cfg(test)]
mod tests {
use super::*;
use crate::raise::death::{DeathKind, DeathSite, fatal_with_detail};
use crate::raise::{Raise, RaiseResult};
use crate::testkit::capture::catch_death;
use crate::core::raise::death::{DeathKind, DeathSite, fatal_with_detail};
use crate::core::raise::{Raise, RaiseResult};
use crate::core::testkit::capture::catch_death;
const SITE: DeathSite = DeathSite {
kind: DeathKind::Abort,
@@ -340,7 +340,7 @@ mod tests {
/// passes every scope by
#[test]
fn a_panic_in_a_scope_is_its_refusal() {
use crate::testkit::capture::{capture_enabled, set_capture_enabled};
use crate::core::testkit::capture::{capture_enabled, set_capture_enabled};
assert!(capture_enabled());
let r = catch_unwind(|| refusing(|| -> u32 { panic!("a test's assertion") }));
let payload = r.unwrap_err();
@@ -349,7 +349,7 @@ mod tests {
let out = std::process::Command::new(std::env::current_exe().unwrap())
.args([
"--exact",
"raise::refusals::tests::a_panic_in_a_scope_is_its_refusal",
"core::raise::refusals::tests::a_panic_in_a_scope_is_its_refusal",
"--nocapture",
"--test-threads=1",
])
File renamed without changes.
@@ -3,7 +3,7 @@
//! A queue's block, a source's handler, a once's block and a Metal completion handler are callouts
//! an exception never unwinds out of: a raise in one with no handler of its own dies at the raise,
//! whatever handlers the thread had (measured for `dispatch_sync` on macOS 26.7). Its code holds
//! under [`Hold::NONE`](crate::rt::Hold::NONE), with no holder: a callout is `Send` and its
//! under [`Hold::NONE`](crate::core::rt::Hold::NONE), with no holder: a callout is `Send` and its
//! caller's hold is not, so none reaches it. While a queue's block runs, the thread owns the queue,
//! and a `sync` onto a queue it owns runs its block at once, as a nested call (`rt::queue`'s
//! module doc). So a queue's block or a completion handler enters:
@@ -16,7 +16,7 @@
use std::cell::Cell;
use crate::rt::thread::{OursGuard, enter_ours};
use crate::core::rt::thread::{OursGuard, enter_ours};
/// One queue of a thread's ownership chain: its id and label.
pub(crate) type Owned = (u64, &'static str);
@@ -92,7 +92,7 @@ pub(crate) struct Submitted {
owned: Vec<Owned>,
ours: bool,
#[cfg(any(test, feature = "testkit"))]
slot: Option<std::sync::Arc<crate::testkit::capture::DeathSlot>>,
slot: Option<std::sync::Arc<crate::core::testkit::capture::DeathSlot>>,
}
impl Submitted {
@@ -102,7 +102,7 @@ impl Submitted {
owned,
ours,
#[cfg(any(test, feature = "testkit"))]
slot: crate::testkit::capture::current_slot(),
slot: crate::core::testkit::capture::current_slot(),
}
}
@@ -119,7 +119,7 @@ impl Submitted {
f()
};
#[cfg(any(test, feature = "testkit"))]
return crate::testkit::capture::with_slot(slot, run);
return crate::core::testkit::capture::with_slot(slot, run);
#[cfg(not(any(test, feature = "testkit")))]
run()
}
@@ -128,7 +128,7 @@ impl Submitted {
#[cfg(test)]
mod tests {
use super::*;
use crate::rt::thread::is_our_thread;
use crate::core::rt::thread::is_our_thread;
/// A block owns its chain, marked ours; the caller's come back after
#[test]
@@ -15,11 +15,11 @@
//!
//! A hold with no holder ([`Hold::NONE`]: a queue's block, a thread's body, a drop) holds to the
//! thread's last-resort holder: a thread core started (a queue's worker, a named thread) keeps
//! one, released once the worker has left its queue ([`crate::rt::pool::drain_idle`]) and at the
//! one, released once the worker has left its queue ([`crate::core::rt::pool::drain_idle`]) and at the
//! thread's end, just before its last-resort real pool pops. On any other thread (Metal's, a
//! test's) the value drops there.
//!
//! A raise carries values outward too: [`crate::raise::Raise::defer`] puts one in the raise's
//! A raise carries values outward too: [`crate::core::raise::Raise::defer`] puts one in the raise's
//! [`Deferred`], and the catch that ends the raise ([`Hold::land`]) hands them to its hold's
//! holder. A landing frame whose body raises puts what it holds in the raise the same way. A raise
//! that dies releases none of them, and one dropped with values still in it is a bug, which builds
@@ -39,7 +39,7 @@ use std::fmt;
use std::marker::PhantomData;
use std::sync::atomic::{AtomicU64, Ordering};
use crate::raise::{Raise, RaiseResult};
use crate::core::raise::{Raise, RaiseResult};
/// A held value.
struct Value {
@@ -105,7 +105,7 @@ impl Held {
/// A landing frame: runs `body` with a new holder, which `body` names in the hold its work
/// runs under ([`Hold::of`]). When `body` returns a value the holder releases what it holds
/// there, most recent first. When it raises, what the holder holds goes on with
/// the raise instead, as [`crate::raise::Raise::defer`]'s values do, and is released where the
/// the raise instead, as [`crate::core::raise::Raise::defer`]'s values do, and is released where the
/// raise ends, after the catcher's report. A death releases none of it.
pub fn raising<T>(body: impl FnOnce(&Held) -> RaiseResult<T>) -> RaiseResult<T> {
let held = Held::new();
@@ -237,7 +237,7 @@ fn to_last_resort(v: Value) {
/// Releases the thread's last-resort holder, most recent first, and, when `again`, makes the
/// next one (the thread goes on idle; at its end, none).
pub(in crate::rt) fn release_last_resort(again: bool) {
pub(in crate::core::rt) fn release_last_resort(again: bool) {
let last = LAST_RESORT.try_with(RefCell::take).ok().flatten();
drop(last);
if again {
@@ -245,7 +245,7 @@ pub(in crate::rt) fn release_last_resort(again: bool) {
}
}
/// The values a raise carries outward ([`crate::raise::Raise::defer`], [`Held::raising`]), in the
/// The values a raise carries outward ([`crate::core::raise::Raise::defer`], [`Held::raising`]), in the
/// order they were first held, until the catch that ends the raise ([`Hold::land`]) lands them
/// in its hold's holder, among whose own values they take their place, and whose
/// drop releases them most recent first. A death forgets them.
@@ -323,9 +323,9 @@ impl Drop for Deferred {
#[cfg(test)]
mod tests {
use super::*;
use crate::raise::{OnFault, Raise, RaiseId, RaiseResult};
use crate::rt::pool::test_native::{events, note, with_test_native};
use crate::testkit::capture::catch_death;
use crate::core::raise::{OnFault, Raise, RaiseId, RaiseResult};
use crate::core::rt::pool::test_native::{events, note, with_test_native};
use crate::core::testkit::capture::catch_death;
use std::sync::Arc;
use std::sync::atomic::AtomicU32;
@@ -12,14 +12,14 @@
//! The threads core starts (a queue's worker, a named thread) also keep a last-resort pool, for
//! what is autoreleased on them outside any unit: [`drain_idle`] pops it and pushes the next once
//! the worker has left its queue, and [`drain_thread_end`] pops it at the thread's end. The
//! thread's last-resort holder ([`crate::rt::held`]) is released first at both points.
//! thread's last-resort holder ([`crate::core::rt::held`]) is released first at both points.
use std::cell::Cell;
use std::ffi::c_void;
use crate::platform::os::Autorelease;
use crate::platform::os::autorelease::NativePool;
use crate::raise::RaiseResult;
use crate::core::platform::os::Autorelease;
use crate::core::platform::os::autorelease::NativePool;
use crate::core::raise::RaiseResult;
#[cfg(test)]
thread_local! {
@@ -32,7 +32,7 @@ pub(crate) fn native() -> Option<NativePool> {
if let Some(n) = TEST_NATIVE.with(Cell::get) {
return Some(n);
}
crate::platform::os::autorelease::installed()
crate::core::platform::os::autorelease::installed()
}
/// One real pool, pushed while it lives. Thread-bound (`!Send`: the pool is the thread's).
@@ -105,7 +105,7 @@ thread_local! {
/// and pushes the next. A worker calls it once it has left its queue (as libdispatch's pool
/// around a worker's drain), a named thread at its start.
pub(crate) fn drain_idle() {
crate::rt::held::release_last_resort(true);
crate::core::rt::held::release_last_resort(true);
let Some(n) = native() else { return };
if let Some(token) = LAST_RESORT.with(Cell::take) {
(n.pop)(token);
@@ -117,7 +117,7 @@ pub(crate) fn drain_idle() {
/// A core thread's end, outside any unit: releases its last-resort holder, then pops its
/// last-resort real pool.
pub(crate) fn drain_thread_end() {
crate::rt::held::release_last_resort(false);
crate::core::rt::held::release_last_resort(false);
if let (Some(token), Some(n)) = (LAST_RESORT.with(Cell::take), native()) {
(n.pop)(token);
}
@@ -128,7 +128,7 @@ pub(crate) fn drain_thread_end() {
#[cfg(test)]
pub(crate) mod test_native {
use super::TEST_NATIVE;
use crate::platform::os::autorelease::NativePool;
use crate::core::platform::os::autorelease::NativePool;
use std::cell::{Cell, RefCell};
use std::ffi::c_void;
@@ -181,9 +181,9 @@ pub(crate) mod test_native {
mod tests {
use super::test_native::{events, note, with_test_native};
use super::*;
use crate::raise::{Raise, RaiseId};
use crate::rt::Hold;
use crate::testkit::FakePlatform;
use crate::core::raise::{Raise, RaiseId};
use crate::core::rt::Hold;
use crate::core::testkit::FakePlatform;
/// A pool pops at its drop, after the work inside it
#[test]
@@ -5,7 +5,7 @@
//! the next block starts another. What every block sees, whichever thread runs it:
//! - an async block starts with no handler, so a raise in it with no handler of its own dies at
//! the raise, its site labelled as having none (6.2). Its code holds under
//! [`Hold::NONE`](crate::rt::Hold::NONE), with no holder;
//! [`Hold::NONE`](crate::core::rt::Hold::NONE), with no holder;
//! - a sync block runs on the caller's thread, directly, once every block submitted before it has
//! run, and holds the queue until it returns. It too starts with no handler, whatever handler
//! the caller is in, so a raise in it with no handler of its own dies at the raise, even under
@@ -37,12 +37,12 @@ use std::sync::Arc;
use std::sync::atomic::{AtomicU64, Ordering};
use std::time::Duration;
use crate::platform::os::{Threads, TimerClock};
use crate::core::platform::os::{Threads, TimerClock};
#[cfg(test)]
pub(crate) use crate::rt::block_env::current_label;
use crate::rt::block_env::{Owned, Submitted, owned_chain};
use crate::rt::pool;
use crate::sync::{Condvar, Mutex, MutexGuard};
pub(crate) use crate::core::rt::block_env::current_label;
use crate::core::rt::block_env::{Owned, Submitted, owned_chain};
use crate::core::rt::pool;
use crate::core::sync::{Condvar, Mutex, MutexGuard};
/// A block submitted to a queue.
pub type Job = Box<dyn FnOnce() + Send + 'static>;
@@ -113,7 +113,7 @@ impl Turn {
struct Block {
job: Job,
#[cfg(any(test, feature = "testkit"))]
slot: Option<Arc<crate::testkit::capture::DeathSlot>>,
slot: Option<Arc<crate::core::testkit::capture::DeathSlot>>,
}
/// What a queue holds, in submission order.
@@ -213,7 +213,7 @@ impl SerialQueue {
/// Runs `f` after every block submitted before it, on the queue's worker, with no handler (a
/// raise in it with no handler of its own dies at the raise) and no holder
/// ([`Hold::NONE`](crate::rt::Hold::NONE)), owning only this queue.
/// ([`Hold::NONE`](crate::core::rt::Hold::NONE)), owning only this queue.
pub fn exec_async(&self, f: impl FnOnce() + Send + 'static) {
let block = Submitted::new(vec![self.me()], true);
Shared::submit(
@@ -221,7 +221,7 @@ impl SerialQueue {
Block {
job: Box::new(move || block.run(f)),
#[cfg(any(test, feature = "testkit"))]
slot: crate::testkit::capture::current_slot(),
slot: crate::core::testkit::capture::current_slot(),
},
);
}
@@ -256,7 +256,7 @@ impl SerialQueue {
/// Runs `f` on the caller's thread once every block submitted before it has run, and holds
/// the queue until it returns. `f` starts with no handler (a raise in it with no handler of
/// its own dies at the raise, whatever handler the caller has) and no holder
/// ([`Hold::NONE`](crate::rt::Hold::NONE)), and what it autoreleases goes to the caller's
/// ([`Hold::NONE`](crate::core::rt::Hold::NONE)), and what it autoreleases goes to the caller's
/// real pool. A caller that owns the queue already runs `f` at once (module doc).
/// `f` is `Send`, as a block of the queue's own is: it takes nothing that is bound to the
/// caller's thread, its hold included.
@@ -335,7 +335,7 @@ impl Shared {
&self,
st: &mut MutexGuard<'_, State>,
#[cfg(any(test, feature = "testkit"))] slot: &mut Option<
Arc<crate::testkit::capture::DeathSlot>,
Arc<crate::core::testkit::capture::DeathSlot>,
>,
) -> bool {
if st.owner != Owner::Idle {
@@ -366,7 +366,7 @@ impl Shared {
/// caller holds it), and ends once the last handle is gone or it has waited
/// [`IDLE_EXIT`] with nothing to do.
fn work(this: &Arc<Shared>) {
crate::rt::thread::become_ours();
crate::core::rt::thread::become_ours();
WORKER_OF.with(|w| w.set(this.id));
// The first last-resort pool.
pool::drain_idle();
@@ -391,7 +391,7 @@ impl Shared {
{
let s = slot.clone();
MutexGuard::unlocked(&mut st, || {
crate::testkit::capture::with_slot(s, pool::drain_idle)
crate::core::testkit::capture::with_slot(s, pool::drain_idle)
});
}
#[cfg(not(any(test, feature = "testkit")))]
@@ -489,14 +489,14 @@ impl Executor for SerialQueue {
#[cfg(test)]
mod tests {
use super::*;
use crate::raise::OnFault;
use crate::raise::RaiseResult;
use crate::raise::death::DeathSite;
use crate::rt::signal::CoalescingSignal;
use crate::rt::thread::is_our_thread;
use crate::rt::thread::test_threads::StdThreads;
use crate::testkit::capture::{expect_death, raise};
use crate::testkit::threads::FakeThreads;
use crate::core::raise::OnFault;
use crate::core::raise::RaiseResult;
use crate::core::raise::death::DeathSite;
use crate::core::rt::signal::CoalescingSignal;
use crate::core::rt::thread::is_our_thread;
use crate::core::rt::thread::test_threads::StdThreads;
use crate::core::testkit::capture::{expect_death, raise};
use crate::core::testkit::threads::FakeThreads;
use std::sync::atomic::AtomicBool;
use std::sync::mpsc;
use std::time::Duration;
@@ -818,7 +818,7 @@ mod tests {
let queue = q("q");
expect_death(
DeathSite {
kind: crate::raise::DeathKind::UnhandledRaise,
kind: crate::core::raise::DeathKind::UnhandledRaise,
file: "gpu_task",
line: 0,
},
@@ -842,7 +842,7 @@ mod tests {
let q3 = queue2.clone();
expect_death(
DeathSite {
kind: crate::raise::DeathKind::UnhandledRaise,
kind: crate::core::raise::DeathKind::UnhandledRaise,
file: "device",
line: 0,
},
@@ -28,7 +28,7 @@ use std::sync::Arc;
use parking_lot::Mutex;
use crate::rt::queue::Executor;
use crate::core::rt::queue::Executor;
/// How merged data combines (`DISPATCH_SOURCE_TYPE_DATA_ADD` / `_OR`).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -250,8 +250,8 @@ impl Inner {
#[cfg(test)]
mod tests {
use super::*;
use crate::rt::queue::{Job, SerialQueue};
use crate::rt::thread::test_threads::StdThreads;
use crate::core::rt::queue::{Job, SerialQueue};
use crate::core::rt::thread::test_threads::StdThreads;
use std::sync::atomic::{AtomicU64, Ordering};
/// A target that holds jobs until the test runs them: a busy queue (not suspended), as the
@@ -4,12 +4,12 @@
//! and each serial queue's worker (`rt::queue`). This wrapper adds what such a thread needs:
//! the "ours" mark the panic hook reads (6.5), the thread's own last-resort holder and pool, and,
//! in tests, the creator's death slot. Its body starts with no handler, and holds under
//! [`Hold::NONE`](crate::rt::Hold::NONE): a hold is not `Send`, so none reaches it.
//! [`Hold::NONE`](crate::core::rt::Hold::NONE): a hold is not `Send`, so none reaches it.
use std::cell::Cell;
use std::marker::PhantomData;
use crate::platform::os::Threads;
use crate::core::platform::os::Threads;
thread_local! {
static OURS: Cell<bool> = const { Cell::new(false) };
@@ -61,7 +61,7 @@ impl Drop for OursGuard {
/// A detached thread named `name` with `stack_size` bytes of stack, from the platform's
/// [`Threads::spawn`], whose body runs marked as ours, with the thread's
/// last-resort holder and real pool. The thread ends in this order: `body` returns, the
/// last-resort holder is released and the pool popped ([`crate::rt::pool::drain_thread_end`]),
/// last-resort holder is released and the pool popped ([`crate::core::rt::pool::drain_thread_end`]),
/// and then `target` is dropped, on the thread.
pub fn spawn_named(
threads: &dyn Threads,
@@ -71,7 +71,7 @@ pub fn spawn_named(
body: impl FnOnce() + Send + 'static,
) {
#[cfg(any(test, feature = "testkit"))]
let slot = crate::testkit::capture::current_slot();
let slot = crate::core::testkit::capture::current_slot();
// The target's release is the thread's too: a death there reaches the test's slot.
#[cfg(any(test, feature = "testkit"))]
let target: Box<dyn std::any::Any + Send> = Box::new(InSlot {
@@ -79,9 +79,9 @@ pub fn spawn_named(
value: Some(target),
});
let run = move || {
crate::rt::pool::drain_idle();
crate::core::rt::pool::drain_idle();
body();
crate::rt::pool::drain_thread_end();
crate::core::rt::pool::drain_thread_end();
};
threads.spawn(
name,
@@ -89,7 +89,7 @@ pub fn spawn_named(
Box::new(move || {
become_ours();
#[cfg(any(test, feature = "testkit"))]
crate::testkit::capture::with_slot(slot, run);
crate::core::testkit::capture::with_slot(slot, run);
#[cfg(not(any(test, feature = "testkit")))]
run();
drop(target);
@@ -100,7 +100,7 @@ pub fn spawn_named(
/// A value dropped with a test's death slot current (`spawn_named`'s target).
#[cfg(any(test, feature = "testkit"))]
struct InSlot {
slot: Option<std::sync::Arc<crate::testkit::capture::DeathSlot>>,
slot: Option<std::sync::Arc<crate::core::testkit::capture::DeathSlot>>,
value: Option<Box<dyn std::any::Any + Send>>,
}
@@ -108,7 +108,7 @@ struct InSlot {
impl Drop for InSlot {
fn drop(&mut self) {
let value = self.value.take();
crate::testkit::capture::with_slot(self.slot.take(), move || drop(value));
crate::core::testkit::capture::with_slot(self.slot.take(), move || drop(value));
}
}
@@ -126,7 +126,7 @@ pub(crate) mod test_threads {
use std::sync::Arc;
use crate::platform::os::{Threads, TimerClock};
use crate::core::platform::os::{Threads, TimerClock};
/// Spawns detached std threads: named ones with the requested stack, and unnamed queue
/// workers. It makes no timers.
@@ -166,7 +166,7 @@ mod tests {
use std::sync::mpsc;
/// A named thread's stack in these tests: a queue worker's and 64 KiB more.
const STACK: usize = crate::rt::queue::WORKER_STACK + 64 * 1024;
const STACK: usize = crate::core::rt::queue::WORKER_STACK + 64 * 1024;
/// The spawned body is ours and named
#[test]
@@ -221,12 +221,15 @@ mod tests {
struct Dies;
impl Drop for Dies {
fn drop(&mut self) {
crate::testkit::capture::die(crate::raise::death::DeathKind::Abort, "named")
crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"named",
)
}
}
crate::testkit::capture::expect_death(
crate::raise::death::DeathSite {
kind: crate::raise::death::DeathKind::Abort,
crate::core::testkit::capture::expect_death(
crate::core::raise::death::DeathSite {
kind: crate::core::raise::death::DeathKind::Abort,
file: "named",
line: 0,
},
@@ -258,15 +261,18 @@ mod tests {
/// A death on a spawned thread lands in the creator's slot
#[test]
fn death_on_spawned_thread_is_captured() {
crate::testkit::capture::expect_death(
crate::raise::death::DeathSite {
kind: crate::raise::death::DeathKind::Abort,
crate::core::testkit::capture::expect_death(
crate::core::raise::death::DeathSite {
kind: crate::core::raise::death::DeathKind::Abort,
file: "named",
line: 0,
},
|| {
spawn_named(&StdThreads, "reims-vgpu.test", STACK, Box::new(()), || {
crate::testkit::capture::die(crate::raise::death::DeathKind::Abort, "named")
crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"named",
)
});
loop {
std::thread::park();
@@ -11,11 +11,11 @@ use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::Duration;
use crate::platform::os::{Deadline, MonoTime, TimerClock, WallTime};
use crate::raise::{Kept, keep_forever};
use crate::rt::queue::{Executor, SerialQueue};
use crate::rt::signal::CoalescingSignal;
use crate::sync::{Condvar, Mutex};
use crate::core::platform::os::{Deadline, MonoTime, TimerClock, WallTime};
use crate::core::raise::{Kept, keep_forever};
use crate::core::rt::queue::{Executor, SerialQueue};
use crate::core::rt::signal::CoalescingSignal;
use crate::core::sync::{Condvar, Mutex};
/// What the timer's thread and its handle share.
#[derive(Default)]
@@ -77,8 +77,8 @@ impl Timer {
) -> Timer {
let Some(clock) = queue.timer_clock() else {
// No production platform lacks a clock; a fake made without one refuses here.
crate::raise::death::fatal(crate::raise::death::DeathId::Platform {
kind: crate::raise::death::DeathKind::Abort,
crate::core::raise::death::fatal(crate::core::raise::death::DeathId::Platform {
kind: crate::core::raise::death::DeathKind::Abort,
call: "timer: no clock",
})
};
@@ -94,12 +94,12 @@ impl Timer {
.name("reims-vgpu.timer".into())
.stack_size(TIMER_STACK)
.spawn(move || {
crate::rt::thread::become_ours();
crate::core::rt::thread::become_ours();
run(&*clock, &sh, &sig, start, step)
});
if r.is_err() {
crate::raise::death::fatal(crate::raise::death::DeathId::Platform {
kind: crate::raise::death::DeathKind::Abort,
crate::core::raise::death::fatal(crate::core::raise::death::DeathId::Platform {
kind: crate::core::raise::death::DeathKind::Abort,
call: "pthread_create",
})
}
@@ -174,11 +174,11 @@ fn run(clock: &dyn TimerClock, sh: &Shared, sig: &CoalescingSignal, start: Deadl
#[cfg(test)]
mod tests {
use super::*;
use crate::platform::os::{Clock, Threads};
use crate::rt::queue::current_label;
use crate::rt::thread::is_our_thread;
use crate::sync::test_clock::ManualClock;
use crate::testkit::threads::FakeThreads;
use crate::core::platform::os::{Clock, Threads};
use crate::core::rt::queue::current_label;
use crate::core::rt::thread::is_our_thread;
use crate::core::sync::test_clock::ManualClock;
use crate::core::testkit::threads::FakeThreads;
use std::sync::atomic::AtomicU64;
use std::sync::mpsc;
@@ -18,7 +18,7 @@ pub(crate) mod test_clock {
//! `VirtualClock`).
use super::{Condvar, Mutex, MutexGuard};
use crate::platform::os::{Clock, Deadline, MonoTime, TimedOut, WallTime};
use crate::core::platform::os::{Clock, Deadline, MonoTime, TimedOut, WallTime};
use std::time::Duration;
/// Virtual time. Timed waits poll in 1 ms real slices, so an `advance` is seen promptly.
@@ -154,7 +154,7 @@ pub(crate) mod test_clock {
mod tests {
use super::test_clock::ManualClock;
use super::*;
use crate::platform::os::{Clock, Deadline, MonoTime};
use crate::core::platform::os::{Clock, Deadline, MonoTime};
use std::sync::Arc;
use std::time::Duration;
@@ -18,9 +18,9 @@ use std::fmt::Debug;
use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering};
use std::sync::{Arc, Weak};
use crate::sync::Mutex;
use crate::core::sync::Mutex;
use crate::platform::{Handle, ObjId};
use crate::core::platform::{Handle, ObjId};
/// One argument of a recorded call. Handles are recorded by identity; value structs by their
/// `Debug` text ([`Arg::val`]), so a test compares them with `Arg::val(&expected)`.
@@ -434,7 +434,7 @@ pub(crate) fn as_completion_thread<R>(f: impl FnOnce() -> R) -> R {
fn thread_class() -> ThreadClass {
if COMPLETION.with(Cell::get) {
ThreadClass::Completion
} else if crate::rt::thread::is_core_thread() {
} else if crate::core::rt::thread::is_core_thread() {
if std::thread::current().name().is_some() {
ThreadClass::Core
} else {
@@ -21,8 +21,8 @@ use std::time::{Duration, Instant};
use parking_lot::{Condvar, Mutex};
use crate::raise::death::{DeathKind, DeathSite};
use crate::raise::{OnFault, Raise, RaiseId, RaiseResult};
use crate::core::raise::death::{DeathKind, DeathSite};
use crate::core::raise::{OnFault, Raise, RaiseId, RaiseResult};
/// The panic payload a captured death unwinds with.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -155,7 +155,7 @@ fn returned(thrown: RaiseResult<std::convert::Infallible>) -> Raise {
/// A test's own death of `kind` at the site `name`.
pub fn die(kind: DeathKind, name: &'static str) -> ! {
crate::raise::death::fatal(crate::raise::death::DeathId::Test { kind, name })
crate::core::raise::death::fatal(crate::core::raise::death::DeathId::Test { kind, name })
}
/// How long `expect_death` waits, in real time, for `f` to die or return.
@@ -26,9 +26,9 @@ use std::time::Duration;
use parking_lot::RawMutex;
use parking_lot::lock_api::RawMutex as _;
use crate::platform::os::{Clock, Deadline, MonoTime, TimedOut, WallTime};
use crate::sync::{Condvar, Mutex, MutexGuard};
use crate::testkit::capture::VirtualTime;
use crate::core::platform::os::{Clock, Deadline, MonoTime, TimedOut, WallTime};
use crate::core::sync::{Condvar, Mutex, MutexGuard};
use crate::core::testkit::capture::VirtualTime;
/// Wall time at virtual zero (nanoseconds since the Unix epoch): 2026-01-01T00:00:00Z. Mono
/// and wall differ, so a test can tell which clock a wait used.
@@ -473,7 +473,7 @@ mod tests {
fn works_with_expect_hang() {
let c = Arc::new(VirtualClock::new());
let c2 = c.clone();
crate::testkit::capture::expect_hang(&*c, Duration::from_secs(1), move || {
crate::core::testkit::capture::expect_hang(&*c, Duration::from_secs(1), move || {
c2.sleep_until(Deadline::Mono(MonoTime::from_nanos(5_000_000_000)));
});
}
@@ -54,14 +54,14 @@ use std::sync::OnceLock;
use std::sync::atomic::{AtomicPtr, AtomicU32, AtomicU64, AtomicUsize, Ordering};
use std::time::{Duration, Instant};
use crate::num::{ToU64, ToUsize, Truncate};
use crate::raise::death::DeathSite;
use crate::sync::Mutex;
use crate::testkit::capture::DeathSlot;
use crate::testkit::capture::VirtualTime;
use crate::testkit::capture::set_capture_enabled;
use crate::testkit::capture::with_slot;
use crate::testkit::guest_ram::{GuestRam, RawRegion};
use crate::core::num::{ToU64, ToUsize, Truncate};
use crate::core::raise::death::DeathSite;
use crate::core::sync::Mutex;
use crate::core::testkit::capture::DeathSlot;
use crate::core::testkit::capture::VirtualTime;
use crate::core::testkit::capture::set_capture_enabled;
use crate::core::testkit::capture::with_slot;
use crate::core::testkit::guest_ram::{GuestRam, RawRegion};
/// The environment marker: set to the full test name in the child that runs it.
pub const ENV_CHILD: &str = "REIMS_VGPU_DEATH_CHILD";
@@ -1426,8 +1426,8 @@ macro_rules! death_test {
$(#[$meta])*
#[test]
fn $name() {
$crate::testkit::death::run(
$crate::testkit::death::Expect::Death,
$crate::core::testkit::death::run(
$crate::core::testkit::death::Expect::Death,
$opts,
module_path!(),
stringify!($name),
@@ -1439,7 +1439,7 @@ macro_rules! death_test {
($(#[$meta:meta])* $name:ident, $body:expr, $check:expr $(,)?) => {
$crate::death_test!(
$(#[$meta])* $name,
options = $crate::testkit::death::Options::default(),
options = $crate::core::testkit::death::Options::default(),
$body,
$check
);
@@ -1448,7 +1448,7 @@ macro_rules! death_test {
/// A test whose body hangs: `hang_test!(name, |t| { …; t.hang(&clock, d, f) }, |r| check)`.
/// As [`death_test!`], but the parent asserts a hang
/// ([`Child::hang`](crate::testkit::death::Child::hang)) with nothing recorded after it. It takes
/// ([`Child::hang`](crate::core::testkit::death::Child::hang)) with nothing recorded after it. It takes
/// `options = …` as `death_test!` does.
#[macro_export]
macro_rules! hang_test {
@@ -1456,8 +1456,8 @@ macro_rules! hang_test {
$(#[$meta])*
#[test]
fn $name() {
$crate::testkit::death::run(
$crate::testkit::death::Expect::Hang,
$crate::core::testkit::death::run(
$crate::core::testkit::death::Expect::Hang,
$opts,
module_path!(),
stringify!($name),
@@ -1469,7 +1469,7 @@ macro_rules! hang_test {
($(#[$meta:meta])* $name:ident, $body:expr, $check:expr $(,)?) => {
$crate::hang_test!(
$(#[$meta])* $name,
options = $crate::testkit::death::Options::default(),
options = $crate::core::testkit::death::Options::default(),
$body,
$check
);
@@ -1479,11 +1479,11 @@ macro_rules! hang_test {
#[cfg(test)]
mod tests {
use super::*;
use crate::platform::os::{Clock as _, Deadline, MonoTime};
use crate::raise::death::DeathKind;
use crate::raise::death::DeathSite;
use crate::testkit::capture::capture_enabled;
use crate::testkit::clock::VirtualClock;
use crate::core::platform::os::{Clock as _, Deadline, MonoTime};
use crate::core::raise::death::DeathKind;
use crate::core::raise::death::DeathSite;
use crate::core::testkit::capture::capture_enabled;
use crate::core::testkit::clock::VirtualClock;
use std::sync::Arc;
use std::sync::atomic::AtomicBool;
@@ -1529,7 +1529,10 @@ mod tests {
t.op(&format!("capture={}", capture_enabled()));
ram.write_u32(0x1_0000_0040, 0xdead_beef);
t.op("effect");
crate::testkit::capture::die(crate::raise::death::DeathKind::Abort, "site_t")
crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"site_t",
)
},
|r| {
let d = r.assert_died_at(SITE, "effect");
@@ -1562,7 +1565,10 @@ mod tests {
std::thread::sleep(Duration::from_millis(50));
t.op("first: dying");
let _held = held;
crate::testkit::capture::die(crate::raise::death::DeathKind::Abort, "site_t")
crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"site_t",
)
},
|r| {
let d = r.assert_died_at(SITE, "first: dying");
@@ -1592,7 +1598,10 @@ mod tests {
ram.write_u64(0x2_0000_0008, 0x0123_4567_89ab_cdef);
assert!(root.store_16_atomic(0, 5, 6));
trace("wrote");
crate::testkit::capture::die(crate::raise::death::DeathKind::NullDeref, "site_w")
crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::NullDeref,
"site_w",
)
});
park_forever()
},
@@ -1788,8 +1797,8 @@ mod tests {
]
);
assert_eq!(
test_name("reims_vgpu_core::testkit::death::tests", "x"),
"testkit::death::tests::x"
test_name("reims_vgpu_vulkan::core::testkit::death::tests", "x"),
"core::testkit::death::tests::x"
);
assert_eq!(test_name("machines_guest", "x"), "x");
}
@@ -1889,7 +1898,10 @@ mod tests {
std::hint::spin_loop();
}
t.op("dying");
crate::testkit::capture::die(crate::raise::death::DeathKind::Abort, "site_t")
crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"site_t",
)
},
|r| {
let d = r.assert_died(SITE);
@@ -1918,8 +1930,8 @@ mod tests {
/// the op that preceded it, not at the worker's stale op
a_death_on_a_reused_worker_is_at_the_op_before_it,
|t| {
let q = crate::rt::queue::SerialQueue::new(
&crate::testkit::threads::FakeThreads::default(),
let q = crate::core::rt::queue::SerialQueue::new(
&crate::core::testkit::threads::FakeThreads::default(),
"A",
);
let done = Arc::new(AtomicBool::new(false));
@@ -1932,7 +1944,10 @@ mod tests {
wait_until(|| done.load(Ordering::Acquire));
t.op("body: submit C");
q.exec_async(|| {
crate::testkit::capture::die(crate::raise::death::DeathKind::Abort, "site_t")
crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"site_t",
)
});
park_forever()
},
@@ -1953,10 +1968,10 @@ mod tests {
/// A dying block on one of two workers that each ran a block is at the op before it
a_death_on_either_of_two_workers_is_at_the_op_before_it,
|t| {
let threads = crate::testkit::threads::FakeThreads::default();
let threads = crate::core::testkit::threads::FakeThreads::default();
let (qa, qb) = (
crate::rt::queue::SerialQueue::new(&threads, "A"),
crate::rt::queue::SerialQueue::new(&threads, "B"),
crate::core::rt::queue::SerialQueue::new(&threads, "A"),
crate::core::rt::queue::SerialQueue::new(&threads, "B"),
);
let go = Arc::new(AtomicBool::new(false));
let started = Arc::new(AtomicUsize::new(0));
@@ -1978,7 +1993,10 @@ mod tests {
wait_until(|| finished.load(Ordering::Acquire) == 2);
t.op("body: submit C");
qa.exec_async(|| {
crate::testkit::capture::die(crate::raise::death::DeathKind::Abort, "site_t")
crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"site_t",
)
});
park_forever()
},
@@ -2004,7 +2022,10 @@ mod tests {
let base = SHARED.load(Ordering::Acquire);
let _ = header_u64(base, H_CURSOR).fetch_add(1, Ordering::AcqRel);
t.op("after");
crate::testkit::capture::die(crate::raise::death::DeathKind::Abort, "site_t")
crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"site_t",
)
},
|r| {
assert!(r.torn());
@@ -2058,7 +2079,7 @@ mod tests {
}
let out = Command::new(std::env::current_exe().unwrap())
.args([
"testkit::death::tests::a_stack_overflow_without_the_harness_aborts",
"core::testkit::death::tests::a_stack_overflow_without_the_harness_aborts",
"--exact",
"--nocapture",
"--test-threads=1",
@@ -2112,7 +2133,10 @@ mod tests {
child.op("body: returning");
child.finish();
named("late", || {
crate::testkit::capture::die(crate::raise::death::DeathKind::Abort, "site_t")
crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"site_t",
)
});
park_forever()
}
@@ -2133,13 +2157,13 @@ mod tests {
let go = Arc::new(AtomicBool::new(false));
let g2 = go.clone();
let judged = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
crate::testkit::capture::expect_death(SITE, move || {
let slot = crate::testkit::capture::current_slot();
crate::core::testkit::capture::expect_death(SITE, move || {
let slot = crate::core::testkit::capture::current_slot();
named("late", move || {
crate::testkit::capture::with_slot(slot, || {
crate::core::testkit::capture::with_slot(slot, || {
wait_until(|| g2.load(Ordering::Acquire));
crate::testkit::capture::die(
crate::raise::death::DeathKind::Abort,
crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"site_t",
)
})
@@ -2159,8 +2183,8 @@ mod tests {
#[should_panic(expected = "expected a death")]
a_death_deferred_past_the_call_fails,
|t| {
let q = crate::rt::queue::SerialQueue::new(
&crate::testkit::threads::FakeThreads::default(),
let q = crate::core::rt::queue::SerialQueue::new(
&crate::core::testkit::threads::FakeThreads::default(),
"Q",
);
t.op("body: calling");
@@ -2168,7 +2192,10 @@ mod tests {
q.exec_async(|| {
let base = SHARED.load(Ordering::Acquire);
wait_until(|| header_u32(base, H_STATE).load(Ordering::Acquire) == STATE_RETURNED);
crate::testkit::capture::die(crate::raise::death::DeathKind::Abort, "site_t")
crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"site_t",
)
});
// The call returned: the body is done.
std::mem::forget(q);
@@ -2272,7 +2299,10 @@ mod tests {
|_| {
printed_not_marked("a", "site_a", 0);
named("b", || {
crate::testkit::capture::die(crate::raise::death::DeathKind::Abort, "site_b")
crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"site_b",
)
});
park_forever()
},
@@ -2328,7 +2358,10 @@ mod tests {
});
wait_until(|| marked.load(Ordering::Acquire));
named("b", || {
crate::testkit::capture::die(crate::raise::death::DeathKind::Abort, "site_b")
crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"site_b",
)
});
park_forever()
},
@@ -2354,7 +2387,10 @@ mod tests {
/// A hang test whose body dies fails (the outcome check)
#[should_panic(expected = "expected a hang")]
a_hang_test_whose_body_dies_fails,
|_| crate::testkit::capture::die(crate::raise::death::DeathKind::Abort, "site_t"),
|_| crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"site_t"
),
|_| {}
);
@@ -2375,7 +2411,10 @@ mod tests {
});
assert!(unwound.is_err());
named("late", || {
crate::testkit::capture::die(crate::raise::death::DeathKind::Abort, "site_t")
crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"site_t",
)
});
park_forever()
}
@@ -2400,13 +2439,13 @@ mod tests {
let go = Arc::new(AtomicBool::new(false));
let g2 = go.clone();
let judged = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
crate::testkit::capture::expect_death(SITE, move || {
let slot = crate::testkit::capture::current_slot();
crate::core::testkit::capture::expect_death(SITE, move || {
let slot = crate::core::testkit::capture::current_slot();
named("late", move || {
crate::testkit::capture::with_slot(slot, || {
crate::core::testkit::capture::with_slot(slot, || {
wait_until(|| g2.load(Ordering::Acquire));
crate::testkit::capture::die(
crate::raise::death::DeathKind::Abort,
crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"site_t",
)
})
@@ -2433,7 +2472,10 @@ mod tests {
named("late", || {
let base = SHARED.load(Ordering::Acquire);
wait_until(|| header_u32(base, H_STATE).load(Ordering::Acquire) == STATE_PANICKED);
crate::testkit::capture::die(crate::raise::death::DeathKind::Abort, "site_t")
crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"site_t",
)
});
t.op("body: checking");
assert_eq!(
@@ -8,8 +8,8 @@
//! are consulted in the order they were added.
use super::script::{HeldCall, Key, Script, Step};
use crate::platform::ObjId;
use crate::platform::types::NsErrorText;
use crate::core::platform::ObjId;
use crate::core::platform::types::NsErrorText;
/// What happens at the faulted call.
#[derive(Debug, Clone)]
@@ -78,14 +78,14 @@ impl Faults {
#[cfg(test)]
mod tests {
use super::*;
use crate::platform::Handle;
use crate::platform::blit::{BlitCmd, BlitEncoder};
use crate::platform::command::{CommandBuffer, CommandQueue};
use crate::platform::compute::{ComputeCmd, ComputeEncoder};
use crate::platform::device::GpuDevice;
use crate::raise::OnFault;
use crate::core::platform::Handle;
use crate::core::platform::blit::{BlitCmd, BlitEncoder};
use crate::core::platform::command::{CommandBuffer, CommandQueue};
use crate::core::platform::compute::{ComputeCmd, ComputeEncoder};
use crate::core::platform::device::GpuDevice;
use crate::core::raise::OnFault;
use crate::testkit::FakePlatform;
use crate::core::testkit::FakePlatform;
/// A fault keyed by one class leaves another class's same selector alone, and lets `skip`
/// calls of its own pass first
@@ -12,10 +12,10 @@
use std::alloc::{Layout, alloc_zeroed};
use std::sync::Arc;
use crate::sync::Mutex;
use crate::core::sync::Mutex;
use crate::host::{HostPtr, PhysicalMemoryRange};
use crate::num::{ToU64, ToUsize};
use crate::core::host::{HostPtr, PhysicalMemoryRange};
use crate::core::num::{ToU64, ToUsize};
// A vCPU's one 16-byte store and load, in one file per architecture.
#[cfg_attr(target_arch = "aarch64", path = "guest_ram/raw/aarch64.rs")]
@@ -9,9 +9,9 @@ use super::super::calllog::Arg;
use super::super::objects::{Fk, kind};
use super::super::platform::FakePlatform;
use super::res_id;
use crate::platform::blit::*;
use crate::raise::{OnFault, RaiseResult};
use crate::testkit::script::Policy;
use crate::core::platform::blit::*;
use crate::core::raise::{OnFault, RaiseResult};
use crate::core::testkit::script::Policy;
/// The name the fake logs and scripts [`BlitEncoder::copy_from_guest_ram`] under, with the runs
/// (each run's start and end, in order), the destination and its offset: no selector of Metal's
@@ -34,7 +34,7 @@ impl BlitEncoder<FakePlatform> for Fk<kind::BlitEncoder> {
&self,
on: OnFault,
runs: &[Range<u64>],
destination: &<FakePlatform as crate::platform::Platform>::Buffer,
destination: &<FakePlatform as crate::core::platform::Platform>::Buffer,
destination_offset: u64,
) -> RaiseResult<bool> {
let copies = self.world().copies_guest_ram();
@@ -49,7 +49,7 @@ impl BlitEncoder<FakePlatform> for Fk<kind::BlitEncoder> {
fn copy_to_guest_ram(
&self,
on: OnFault,
source: &<FakePlatform as crate::platform::Platform>::Buffer,
source: &<FakePlatform as crate::core::platform::Platform>::Buffer,
source_offset: u64,
runs: &[Range<u64>],
) -> RaiseResult<bool> {
@@ -8,11 +8,11 @@ use super::super::calllog::Arg;
use super::super::objects::{CommandBufferModel, Fk, Model, completion_read, kind};
use super::super::platform::FakePlatform;
use super::fatal;
use crate::platform::command::*;
use crate::platform::types::{CommandBufferStatus, NsErrorText};
use crate::platform::{EventRef, Platform};
use crate::raise::{OnFault, RaiseResult};
use crate::testkit::script::Policy;
use crate::core::platform::command::*;
use crate::core::platform::types::{CommandBufferStatus, NsErrorText};
use crate::core::platform::{EventRef, Platform};
use crate::core::raise::{OnFault, RaiseResult};
use crate::core::testkit::script::Policy;
impl CommandQueue<FakePlatform> for Fk<kind::CommandQueue> {
fn command_buffer(
@@ -43,7 +43,7 @@ impl CommandBuffer<FakePlatform> for Fk<kind::CommandBuffer> {
"addCompletedHandler:",
vec![Arg::Block(true)],
)?;
let carried = crate::raise::refusals::carry();
let carried = crate::core::raise::refusals::carry();
let block: CompletedHandler = Box::new(move |info| {
run_completed(carried, || completion_read(info), block);
});
@@ -90,7 +90,7 @@ impl CommandBuffer<FakePlatform> for Fk<kind::CommandBuffer> {
"addCompletionSeenHandler",
vec![Arg::Block(true)],
)?;
let carried = crate::raise::refusals::carry();
let carried = crate::core::raise::refusals::carry();
let block: CompletedHandler = Box::new(move |info| {
run_completed(carried, || completion_read(info), block);
});
@@ -111,12 +111,14 @@ impl CommandBuffer<FakePlatform> for Fk<kind::CommandBuffer> {
/// Its submission handlers, and those of the buffers the world takes at this commit
/// ([`World::release_submissions_at_next_commit`]), run inside the call, marked so
/// ([`crate::platform::command::committing`]), as the Vulkan platform's runtime runs them.
/// ([`crate::core::platform::command::committing`]), as the Vulkan platform's runtime runs them.
///
/// [`World::release_submissions_at_next_commit`]: crate::testkit::objects::World::release_submissions_at_next_commit
/// [`World::release_submissions_at_next_commit`]: crate::core::testkit::objects::World::release_submissions_at_next_commit
fn commit(&self, on: OnFault) -> RaiseResult<()> {
self.act(Policy::On(on), "commit", vec![])?;
crate::platform::command::committing(|| super::super::objects::commit_obj(self.obj()));
crate::core::platform::command::committing(|| {
super::super::objects::commit_obj(self.obj())
});
Ok(())
}
@@ -254,7 +256,7 @@ impl CommandBuffer<FakePlatform> for Fk<kind::CommandBuffer> {
/// A new encoder, with the value in the log.
fn compute_encoder_for_pass(
&self,
desc: &crate::platform::values::ComputePassDesc,
desc: &crate::core::platform::values::ComputePassDesc,
) -> RaiseResult<Option<<FakePlatform as Platform>::ComputeEncoder>> {
self.make(
Policy::Caught,
@@ -7,10 +7,10 @@ use super::super::calllog::Arg;
use super::super::objects::{Fk, kind};
use super::super::platform::FakePlatform;
use super::res_ids;
use crate::platform::Platform;
use crate::platform::compute::*;
use crate::raise::{OnFault, RaiseResult};
use crate::testkit::script::Policy;
use crate::core::platform::Platform;
use crate::core::platform::compute::*;
use crate::core::raise::{OnFault, RaiseResult};
use crate::core::testkit::script::Policy;
impl ComputeEncoder<FakePlatform> for Fk<kind::ComputeEncoder> {
fn encode(&self, on: OnFault, cmd: ComputeCmd<'_, FakePlatform>) -> RaiseResult<()> {
@@ -8,20 +8,20 @@
//! mode, and `setSamplePositions:count:`, which Metal checks); the others write the model, and the
//! getters read it.
use crate::testkit::script::Policy;
use crate::core::testkit::script::Policy;
use std::collections::BTreeMap;
use super::super::calllog::Arg;
use super::super::objects::{AnyHandle, Fk, Kind, TexDesc, kind};
use super::super::platform::FakePlatform;
use crate::platform::ObjId;
use crate::platform::descriptor::*;
use crate::platform::types::{ClearColor, MtlSamplePosition};
use crate::platform::values::{
use crate::core::platform::ObjId;
use crate::core::platform::descriptor::*;
use crate::core::platform::types::{ClearColor, MtlSamplePosition};
use crate::core::platform::values::{
AttachmentState, ColorAttachmentSet, DepthAttachmentSet, PassSet, StencilAttachmentSet,
TextureDesc,
};
use crate::raise::{OnFault, RaiseResult};
use crate::core::raise::{OnFault, RaiseResult};
/// A texture descriptor's model.
#[derive(Debug, Default)]
@@ -4,7 +4,7 @@
//! (`fake::script`) before its model; a value's creator logs the value. The device's
//! capabilities come from its [`DeviceModel`], neither logged nor scripted.
use crate::testkit::script::Policy;
use crate::core::testkit::script::Policy;
use std::sync::Arc;
use super::super::calllog::Arg;
@@ -16,22 +16,22 @@ use super::icb::IcbModel;
use super::rate_map::RateMapModel;
use super::resource::{MeshLimits, PipelineModel};
use super::{Backing, common, new_buffer, new_state, new_texture};
use crate::num;
use crate::platform::caps::{
use crate::core::num;
use crate::core::platform::caps::{
self, DeviceCaps, FormatAnswers, IdentityCaps, IdentityFlags, IdentitySizes,
};
use crate::platform::device::*;
use crate::platform::types::{
use crate::core::platform::device::*;
use crate::core::platform::types::{
ArgumentKind, ArgumentLayout, ArgumentMember, MtlSize, NsErrorText, PixelFormatInfo,
SizeAndAlign, TextureLevelInfo, TextureLevelQuery,
};
use crate::platform::values::{
use crate::core::platform::values::{
ArgumentDesc, BufferDesc, DepthStencilDesc, FullComputePipelineDesc,
FullMeshRenderPipelineDesc, FullRenderPipelineDesc, HeapDesc, HeapMade, IcbDesc, OptionSet,
PagesInPlace, PagesPlane, RenderPipelineDesc, SamplerDesc,
};
use crate::platform::{Handle, HostRange, Platform};
use crate::raise::{OnFault, RaiseResult};
use crate::core::platform::{Handle, HostRange, Platform};
use crate::core::raise::{OnFault, RaiseResult};
/// The name the fake logs and scripts [`GpuDevice::new_command_queue_unshared`] under: no selector
/// of Metal's names it.
@@ -146,8 +146,8 @@ impl GpuDevice<FakePlatform> for Fk<kind::Device> {
|w| {
let s = surface?;
let (base, len) = (
crate::platform::os::surface::Surface::base_address(&s),
crate::platform::os::surface::Surface::alloc_size(&s),
crate::core::platform::os::surface::Surface::base_address(&s),
crate::core::platform::os::surface::Surface::alloc_size(&s),
);
let b = new_buffer(w, len, 0, Backing::At(base), None)?;
if let Model::Buffer(m) = &mut b.state().model {
@@ -188,14 +188,14 @@ impl GpuDevice<FakePlatform> for Fk<kind::Device> {
/// Unlogged, as the property the platform answers it from: [`World::copy_guest_ram`].
///
/// [`World::copy_guest_ram`]: crate::testkit::objects::World::copy_guest_ram
/// [`World::copy_guest_ram`]: crate::core::testkit::objects::World::copy_guest_ram
fn copies_guest_ram(&self) -> bool {
self.world().copies_guest_ram()
}
/// Unlogged, as the world answers it: [`World::answer_surface_pages`].
///
/// [`World::answer_surface_pages`]: crate::testkit::objects::World::answer_surface_pages
/// [`World::answer_surface_pages`]: crate::core::testkit::objects::World::answer_surface_pages
fn surface_pages_in_place(
&self,
_pages: &<FakePlatform as Platform>::Buffer,
@@ -7,10 +7,10 @@ use super::super::calllog::Arg;
use super::super::objects::{Fk, kind};
use super::super::platform::FakePlatform;
use super::fatal;
use crate::platform::Platform;
use crate::platform::event::*;
use crate::raise::RaiseResult;
use crate::testkit::script::Policy;
use crate::core::platform::Platform;
use crate::core::platform::event::*;
use crate::core::raise::RaiseResult;
use crate::core::testkit::script::Policy;
impl SharedEvent<FakePlatform> for Fk<kind::SharedEvent> {
fn set_signaled_value(&self, signaled_value: u64) -> RaiseResult<()> {
@@ -50,7 +50,7 @@ impl SharedEvent<FakePlatform> for Fk<kind::SharedEvent> {
value: u64,
block: Notification,
) -> RaiseResult<()> {
use crate::platform::Handle as _;
use crate::core::platform::Handle as _;
self.act(
Policy::Caught,
"notifyListener:atValue:block:",
@@ -4,16 +4,16 @@
//! logs its encoded commands, which are ordered, and records what they set in its
//! [`IcbCommandModel`], which the free read-back getters answer from.
use crate::testkit::script::Policy;
use crate::core::testkit::script::Policy;
use std::collections::BTreeMap;
use super::super::calllog::Arg;
use super::super::objects::{Fk, Kind, Model, ResourceCommon, kind};
use super::super::platform::FakePlatform;
use crate::platform::Platform;
use crate::platform::icb::*;
use crate::platform::types::{MtlRegion, MtlSize};
use crate::raise::RaiseResult;
use crate::core::platform::Platform;
use crate::core::platform::icb::*;
use crate::core::platform::types::{MtlRegion, MtlSize};
use crate::core::raise::RaiseResult;
/// An indirect command buffer's model.
#[derive(Debug, Default)]
@@ -33,14 +33,14 @@ use super::objects::{
TextureModel, World, kind,
};
use super::script::Policy;
use crate::host::HostPtr;
use crate::platform::Handle;
use crate::platform::blit::ResourceRef;
use crate::platform::types::NsErrorText;
use crate::raise::RaiseResult;
use crate::core::host::HostPtr;
use crate::core::platform::Handle;
use crate::core::platform::blit::ResourceRef;
use crate::core::platform::types::NsErrorText;
use crate::core::raise::RaiseResult;
/// The identity of a resource argument.
pub fn res_id(r: &ResourceRef<'_, super::platform::FakePlatform>) -> crate::platform::ObjId {
pub fn res_id(r: &ResourceRef<'_, super::platform::FakePlatform>) -> crate::core::platform::ObjId {
match r {
ResourceRef::Buffer(b) => b.id(),
ResourceRef::Texture(t) => t.id(),
@@ -277,14 +277,14 @@ mod tests {
use super::super::platform::FakePlatform;
use super::super::script::Step;
use super::*;
use crate::platform::Platform;
use crate::platform::command::{CommandBuffer, CommandQueue};
use crate::platform::device::GpuDevice;
use crate::platform::event::SharedEvent;
use crate::platform::resource::{Buffer, GpuResource, Texture};
use crate::platform::types::{CommandBufferStatus, MtlSize};
use crate::platform::values::{IcbDesc, RateMapDesc, TextureDesc};
use crate::raise::OnFault;
use crate::core::platform::Platform;
use crate::core::platform::command::{CommandBuffer, CommandQueue};
use crate::core::platform::device::GpuDevice;
use crate::core::platform::event::SharedEvent;
use crate::core::platform::resource::{Buffer, GpuResource, Texture};
use crate::core::platform::types::{CommandBufferStatus, MtlSize};
use crate::core::platform::values::{IcbDesc, RateMapDesc, TextureDesc};
use crate::core::raise::OnFault;
/// Buffers get a GPU VA, contents unless private, and refuse past the fake's limit
#[test]
@@ -345,7 +345,7 @@ mod tests {
let p = FakePlatform::new();
let q = p.device().new_command_queue().unwrap();
let cb = q.command_buffer(OnFault::Die).unwrap().unwrap();
let seen = Arc::new(crate::sync::Mutex::new(Vec::new()));
let seen = Arc::new(crate::core::sync::Mutex::new(Vec::new()));
let s = seen.clone();
cb.add_completed_handler(OnFault::Die, Box::new(move |i| s.lock().push(i.status)))
.unwrap();
@@ -362,7 +362,7 @@ mod tests {
/// A device answers the fake's default caps until a test sets its own
#[test]
fn device_caps() {
use crate::platform::caps::DeviceCaps;
use crate::core::platform::caps::DeviceCaps;
let p = FakePlatform::new();
let d = p.device();
let read = d.caps();
@@ -372,7 +372,7 @@ mod tests {
let mut caps = DeviceCaps::clone(&read);
caps.limits.max_viewport_count = 3;
caps.flags.supports_tile_shaders = false;
caps.families[0] = Err(crate::raise::Raise::foreign("supportsFamily:"));
caps.families[0] = Err(crate::core::raise::Raise::foreign("supportsFamily:"));
caps.gpu_core_count = None;
d.set_caps(caps.clone());
assert_eq!(*d.caps(), caps);
@@ -381,11 +381,11 @@ mod tests {
/// The model setters change what the free getters answer, and log nothing
#[test]
fn model_setters() {
use crate::platform::descriptor::TextureDescriptor;
use crate::platform::icb::{IndirectCommandBuffer, IndirectRenderCommand};
use crate::platform::rate_map::{RateMap, RateMapDescriptor, RateMapLayerDescriptor};
use crate::platform::resource::ComputePipeline;
use crate::platform::types::SizeAndAlign;
use crate::core::platform::descriptor::TextureDescriptor;
use crate::core::platform::icb::{IndirectCommandBuffer, IndirectRenderCommand};
use crate::core::platform::rate_map::{RateMap, RateMapDescriptor, RateMapLayerDescriptor};
use crate::core::platform::resource::ComputePipeline;
use crate::core::platform::types::SizeAndAlign;
let p = FakePlatform::new();
let d = p.device();
let td = p.texture_descriptor(&TextureDesc {
@@ -415,8 +415,8 @@ mod tests {
.unwrap();
let quiet = p.call_log().mark();
layer.set_sample_count(MtlSize::new(1, 1, 0));
layer.set_horizontal_sample_storage(crate::host::HostPtr::NULL);
layer.set_vertical_sample_storage(crate::host::HostPtr::from_addr(0x40));
layer.set_horizontal_sample_storage(crate::core::host::HostPtr::NULL);
layer.set_vertical_sample_storage(crate::core::host::HostPtr::from_addr(0x40));
assert!(p.call_log().since(quiet).is_empty());
assert_eq!(layer.sample_count(), MtlSize::new(1, 1, 0));
assert!(layer.horizontal_sample_storage().is_null());
@@ -447,7 +447,7 @@ mod tests {
cmd.set_command_type(0x10);
assert_eq!(cmd.command_type(), 0x10);
assert_eq!(cmd.draw_args(), None);
cmd.encode(crate::platform::icb::IcbRenderCmd::DrawPrimitives {
cmd.encode(crate::core::platform::icb::IcbRenderCmd::DrawPrimitives {
primitive_type: 3,
vertex_start: 1,
vertex_count: 6,
@@ -457,7 +457,7 @@ mod tests {
.unwrap();
assert_eq!(
cmd.draw_args(),
Some(crate::platform::icb::DrawArgs {
Some(crate::core::platform::icb::DrawArgs {
primitive_type: 3,
vertex_start: 1,
vertex_count: 6,
@@ -466,13 +466,13 @@ mod tests {
})
);
// A reset forgets the draw and its type.
cmd.encode(crate::platform::icb::IcbRenderCmd::Reset)
cmd.encode(crate::core::platform::icb::IcbRenderCmd::Reset)
.unwrap();
assert_eq!((cmd.draw_args(), cmd.command_type()), (None, 0));
let compute = icb.compute_command(1).unwrap().unwrap();
compute.set_command_type(0x20);
assert_eq!(
crate::platform::icb::IndirectComputeCommand::command_type(&compute),
crate::core::platform::icb::IndirectComputeCommand::command_type(&compute),
0x20
);
}
@@ -4,7 +4,7 @@
//! index); a rate map holds what it was made from. The ordered calls (`setLayer:atIndex:`, the
//! map's copies, mappings and reset) are logged and scripted; the getters read the models.
use crate::testkit::script::Policy;
use crate::core::testkit::script::Policy;
use std::sync::Arc;
use super::super::calllog::Arg;
@@ -12,12 +12,12 @@ use super::super::guest_ram::RawRegion;
use super::super::objects::{Fk, LayerModel, Model, ResourceCommon, World, kind};
use super::super::platform::FakePlatform;
use super::fatal;
use crate::host::HostPtr;
use crate::platform::Platform;
use crate::platform::rate_map::*;
use crate::platform::types::{MtlCoordinate2D, MtlSize, SizeAndAlign};
use crate::platform::values::RateMapDesc;
use crate::raise::{OnFault, RaiseResult};
use crate::core::host::HostPtr;
use crate::core::platform::Platform;
use crate::core::platform::rate_map::*;
use crate::core::platform::types::{MtlCoordinate2D, MtlSize, SizeAndAlign};
use crate::core::platform::values::RateMapDesc;
use crate::core::raise::{OnFault, RaiseResult};
/// A rasterization rate map's model.
#[derive(Debug)]
@@ -8,9 +8,9 @@ use super::super::calllog::Arg;
use super::super::objects::{Fk, kind};
use super::super::platform::FakePlatform;
use super::res_ids;
use crate::platform::render::*;
use crate::raise::{OnFault, RaiseResult};
use crate::testkit::script::Policy;
use crate::core::platform::render::*;
use crate::core::raise::{OnFault, RaiseResult};
use crate::core::testkit::script::Policy;
impl RenderEncoder<FakePlatform> for Fk<kind::RenderEncoder> {
fn encode(&self, on: OnFault, cmd: RenderCmd<'_, FakePlatform>) -> RaiseResult<()> {
@@ -8,13 +8,13 @@ use super::super::calllog::Arg;
use super::super::objects::{Fk, Model, ResourceCommon, TexDesc, TextureModel, kind};
use super::super::platform::FakePlatform;
use super::{Backing, new_buffer, new_texture};
use crate::host::HostPtr;
use crate::platform::resource::*;
use crate::platform::types::{MtlRegion, MtlSize, NsRange, Swizzle};
use crate::platform::values::SurfacePlane;
use crate::platform::{Handle, HostRange, Platform};
use crate::raise::{OnFault, RaiseResult};
use crate::testkit::script::Policy;
use crate::core::host::HostPtr;
use crate::core::platform::resource::*;
use crate::core::platform::types::{MtlRegion, MtlSize, NsRange, Swizzle};
use crate::core::platform::values::SurfacePlane;
use crate::core::platform::{Handle, HostRange, Platform};
use crate::core::raise::{OnFault, RaiseResult};
use crate::core::testkit::script::Policy;
impl Fk<kind::Buffer> {
/// `f` of the buffer's model; the default of `T` for a buffer a test made with no model.
@@ -731,7 +731,7 @@ impl Library<FakePlatform> for Fk<kind::Library> {
&self,
on: OnFault,
function_name: &str,
constants: &[crate::platform::resource::FunctionConstant],
constants: &[crate::core::platform::resource::FunctionConstant],
) -> RaiseResult<Option<<FakePlatform as Platform>::Function>> {
let name = function_name.to_owned();
let mut args = vec![Arg::Str(function_name.to_owned())];
@@ -752,7 +752,7 @@ impl Library<FakePlatform> for Fk<kind::Library> {
&self,
on: OnFault,
function_name: &str,
constants: &[crate::platform::resource::FunctionConstant],
constants: &[crate::core::platform::resource::FunctionConstant],
options: u64,
specialized_name: Option<&str>,
) -> RaiseResult<Option<<FakePlatform as Platform>::Function>> {
@@ -8,7 +8,7 @@
//!
//! A test that captures relies on nextest running each test in its own process: only there are
//! the lines it takes its own test's, and is the test logger sure to be the process's rather than
//! [`crate::logging`]'s. Under `cargo test`'s threads, a line another test writes during the
//! [`crate::core::logging`]'s. Under `cargo test`'s threads, a line another test writes during the
//! capture is taken with it.
//!
//! ```ignore
@@ -26,7 +26,7 @@ use std::sync::OnceLock;
use log::{Level, LevelFilter, Log, Metadata, Record};
use crate::sync::{Mutex, MutexGuard};
use crate::core::sync::{Mutex, MutexGuard};
/// One line: its level, its target and its message.
pub type Line = (Level, String, String);
@@ -31,7 +31,7 @@ use std::collections::HashMap;
use std::fmt::{Debug, Display};
use std::path::{Path, PathBuf};
use crate::sync::Mutex;
use crate::core::sync::Mutex;
/// The longest byte buffer a file of answers holds as `hex`: a longer one is in its `.xz` file.
pub const HEX_LIMIT: usize = 256;
@@ -400,7 +400,7 @@ raw_tuple!(
(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H)
);
impl Raw for crate::platform::types::TextureLevelInfo {
impl Raw for crate::core::platform::types::TextureLevelInfo {
fn raw(&self, out: &mut Vec<u8>) {
for v in [
self.field_0,
@@ -422,7 +422,7 @@ impl Raw for crate::platform::types::TextureLevelInfo {
}
}
impl Raw for crate::platform::types::PixelFormatInfo {
impl Raw for crate::core::platform::types::PixelFormatInfo {
fn raw(&self, out: &mut Vec<u8>) {
self.name.raw(out);
for v in [
@@ -442,12 +442,14 @@ impl Raw for crate::platform::types::PixelFormatInfo {
#[macro_export]
macro_rules! metal_check_raw {
($ours:expr $(,)?) => {
$crate::metal_check_bytes!(&$crate::testkit::metal_answers::Raw::raw_bytes(&$ours))
$crate::metal_check_bytes!(&$crate::core::testkit::metal_answers::Raw::raw_bytes(
&$ours
))
};
($key:expr, $ours:expr $(,)?) => {
$crate::metal_check_bytes!(
$key,
&$crate::testkit::metal_answers::Raw::raw_bytes(&$ours)
&$crate::core::testkit::metal_answers::Raw::raw_bytes(&$ours)
)
};
}
@@ -456,12 +458,14 @@ macro_rules! metal_check_raw {
#[macro_export]
macro_rules! metal_matches_raw {
($ours:expr $(,)?) => {
$crate::metal_matches_bytes!(&$crate::testkit::metal_answers::Raw::raw_bytes(&$ours))
$crate::metal_matches_bytes!(&$crate::core::testkit::metal_answers::Raw::raw_bytes(
&$ours
))
};
($key:expr, $ours:expr $(,)?) => {
$crate::metal_matches_bytes!(
$key,
&$crate::testkit::metal_answers::Raw::raw_bytes(&$ours)
&$crate::core::testkit::metal_answers::Raw::raw_bytes(&$ours)
)
};
}
@@ -470,7 +474,12 @@ macro_rules! metal_matches_raw {
#[macro_export]
macro_rules! metal_near {
($key:expr, $ours:expr $(,)?) => {
$crate::testkit::metal_answers::near(file!(), env!("CARGO_MANIFEST_DIR"), &$key, $ours)
$crate::core::testkit::metal_answers::near(
file!(),
env!("CARGO_MANIFEST_DIR"),
&$key,
$ours,
)
};
}
@@ -478,7 +487,12 @@ macro_rules! metal_near {
#[macro_export]
macro_rules! metal_answer {
($key:expr, $ours:expr $(,)?) => {
$crate::testkit::metal_answers::answer(file!(), env!("CARGO_MANIFEST_DIR"), &$key, $ours)
$crate::core::testkit::metal_answers::answer(
file!(),
env!("CARGO_MANIFEST_DIR"),
&$key,
$ours,
)
};
}
@@ -486,7 +500,7 @@ macro_rules! metal_answer {
#[macro_export]
macro_rules! metal_full {
($key:expr $(,)?) => {
$crate::testkit::metal_answers::full(file!(), env!("CARGO_MANIFEST_DIR"), &$key)
$crate::core::testkit::metal_answers::full(file!(), env!("CARGO_MANIFEST_DIR"), &$key)
};
}
@@ -494,7 +508,7 @@ macro_rules! metal_full {
#[macro_export]
macro_rules! metal_value {
($key:expr $(,)?) => {
$crate::testkit::metal_answers::value(file!(), env!("CARGO_MANIFEST_DIR"), &$key)
$crate::core::testkit::metal_answers::value(file!(), env!("CARGO_MANIFEST_DIR"), &$key)
};
}
@@ -502,15 +516,20 @@ macro_rules! metal_value {
#[macro_export]
macro_rules! metal_check {
($ours:expr $(,)?) => {
$crate::testkit::metal_answers::check(
$crate::core::testkit::metal_answers::check(
file!(),
env!("CARGO_MANIFEST_DIR"),
&$crate::testkit::metal_answers::next_key(file!(), env!("CARGO_MANIFEST_DIR")),
&$crate::core::testkit::metal_answers::next_key(file!(), env!("CARGO_MANIFEST_DIR")),
&$ours,
)
};
($key:expr, $ours:expr $(,)?) => {
$crate::testkit::metal_answers::check(file!(), env!("CARGO_MANIFEST_DIR"), &$key, &$ours)
$crate::core::testkit::metal_answers::check(
file!(),
env!("CARGO_MANIFEST_DIR"),
&$key,
&$ours,
)
};
}
@@ -518,15 +537,15 @@ macro_rules! metal_check {
#[macro_export]
macro_rules! metal_check_bytes {
($ours:expr $(,)?) => {
$crate::testkit::metal_answers::check_bytes(
$crate::core::testkit::metal_answers::check_bytes(
file!(),
env!("CARGO_MANIFEST_DIR"),
&$crate::testkit::metal_answers::next_key(file!(), env!("CARGO_MANIFEST_DIR")),
&$crate::core::testkit::metal_answers::next_key(file!(), env!("CARGO_MANIFEST_DIR")),
$ours,
)
};
($key:expr, $ours:expr $(,)?) => {
$crate::testkit::metal_answers::check_bytes(
$crate::core::testkit::metal_answers::check_bytes(
file!(),
env!("CARGO_MANIFEST_DIR"),
&$key,
@@ -539,15 +558,20 @@ macro_rules! metal_check_bytes {
#[macro_export]
macro_rules! metal_matches {
($ours:expr $(,)?) => {
$crate::testkit::metal_answers::matches(
$crate::core::testkit::metal_answers::matches(
file!(),
env!("CARGO_MANIFEST_DIR"),
&$crate::testkit::metal_answers::next_key(file!(), env!("CARGO_MANIFEST_DIR")),
&$crate::core::testkit::metal_answers::next_key(file!(), env!("CARGO_MANIFEST_DIR")),
&$ours,
)
};
($key:expr, $ours:expr $(,)?) => {
$crate::testkit::metal_answers::matches(file!(), env!("CARGO_MANIFEST_DIR"), &$key, &$ours)
$crate::core::testkit::metal_answers::matches(
file!(),
env!("CARGO_MANIFEST_DIR"),
&$key,
&$ours,
)
};
}
@@ -555,15 +579,15 @@ macro_rules! metal_matches {
#[macro_export]
macro_rules! metal_matches_bytes {
($ours:expr $(,)?) => {
$crate::testkit::metal_answers::matches_bytes(
$crate::core::testkit::metal_answers::matches_bytes(
file!(),
env!("CARGO_MANIFEST_DIR"),
&$crate::testkit::metal_answers::next_key(file!(), env!("CARGO_MANIFEST_DIR")),
&$crate::core::testkit::metal_answers::next_key(file!(), env!("CARGO_MANIFEST_DIR")),
$ours,
)
};
($key:expr, $ours:expr $(,)?) => {
$crate::testkit::metal_answers::matches_bytes(
$crate::core::testkit::metal_answers::matches_bytes(
file!(),
env!("CARGO_MANIFEST_DIR"),
&$key,
@@ -33,8 +33,8 @@ use std::marker::PhantomData;
use std::sync::atomic::{AtomicBool, AtomicI64, AtomicU64, Ordering};
use std::sync::{Arc, Weak};
use crate::platform::values::{PagesInPlace, PagesPlane};
use crate::sync::{Condvar, Mutex, MutexGuard};
use crate::core::platform::values::{PagesInPlace, PagesPlane};
use crate::core::sync::{Condvar, Mutex, MutexGuard};
use super::calllog::{Arg, CallLog, Event, ReleaseContext};
use super::clock::VirtualClock;
@@ -46,16 +46,16 @@ use super::impls::rate_map::{RateMapDescriptorModel, RateMapModel};
use super::impls::resource::PipelineModel;
use super::script::{HeldCall, Script, Step};
use super::vm::FakeVm;
use crate::host::HostPtr;
use crate::num;
use crate::platform::command::{CompletedHandler, CompletedInfo, ScheduledHandler};
use crate::platform::device::NoCopyDeallocator;
use crate::platform::event::Notification;
use crate::platform::os::{Clock, Deadline};
use crate::platform::types::{
use crate::core::host::HostPtr;
use crate::core::num;
use crate::core::platform::command::{CompletedHandler, CompletedInfo, ScheduledHandler};
use crate::core::platform::device::NoCopyDeallocator;
use crate::core::platform::event::Notification;
use crate::core::platform::os::{Clock, Deadline};
use crate::core::platform::types::{
CommandBufferStatus, MtlSize, NsErrorText, ResourceAddressRange, Swizzle,
};
use crate::platform::{Handle, ObjId};
use crate::core::platform::{Handle, ObjId};
/// A handle kind: the Objective-C class the fake stands in for.
pub trait Kind: Send + Sync + 'static {
@@ -161,7 +161,7 @@ pub const PURGEABLE_NON_VOLATILE: u64 = 2;
pub enum CompleteOn {
/// On the calling thread, as a foreign thread would run them: owning no queue
/// (`rt::BlockEnv::foreign`), with no handler live and no holder
/// ([`Hold::NONE`](crate::rt::Hold::NONE)), as every completion handler runs, so a raise in a
/// ([`Hold::NONE`](crate::core::rt::Hold::NONE)), as every completion handler runs, so a raise in a
/// handler dies as it does on Metal's completion thread. The calling thread's locks stay held,
/// though, which Metal's thread never holds: use it only where the caller holds no core lock (a
/// test thread, or `commit` under auto-complete from code that holds none); otherwise use
@@ -411,9 +411,9 @@ pub struct SurfaceModel {
/// Outstanding `IOSurfaceLock`s.
pub lock_count: i64,
/// The creation spec, when made by `IOSurfaceCreate`.
pub spec: Option<crate::platform::os::surface::SurfaceSpec>,
pub spec: Option<crate::core::platform::os::surface::SurfaceSpec>,
/// The creation properties, when made by `initWithProperties:`.
pub backing_spec: Option<crate::platform::os::surface::BackingSurfaceSpec>,
pub backing_spec: Option<crate::core::platform::os::surface::BackingSurfaceSpec>,
}
/// A rasterization-rate layer: its sample count and sample storage.
@@ -725,7 +725,7 @@ impl<K: Kind> Drop for Fk<K> {
.push(self.id(), K::CLASS, "CFRelease", vec![]);
}
if !std::thread::panicking() && self.obj().world.take_release_death(self.id()) {
crate::raise::Raise::platform("release")
crate::core::raise::Raise::platform("release")
.with_detail("the platform died letting go of the object")
.fatal();
}
@@ -937,12 +937,12 @@ pub struct World {
splits: AtomicBool,
/// What the devices' [`GpuDevice::copies_guest_ram`] answers ([`World::copy_guest_ram`]).
///
/// [`GpuDevice::copies_guest_ram`]: crate::platform::device::GpuDevice::copies_guest_ram
/// [`GpuDevice::copies_guest_ram`]: crate::core::platform::device::GpuDevice::copies_guest_ram
guest_ram_copies: AtomicBool,
/// What the devices' [`GpuDevice::surface_pages_in_place`] answers
/// ([`World::answer_surface_pages`]), and the planes each call was asked of, in order.
///
/// [`GpuDevice::surface_pages_in_place`]: crate::platform::device::GpuDevice::surface_pages_in_place
/// [`GpuDevice::surface_pages_in_place`]: crate::core::platform::device::GpuDevice::surface_pages_in_place
surface_pages: Mutex<(PagesInPlace, Vec<Vec<PagesPlane>>)>,
}
@@ -989,7 +989,7 @@ impl World {
/// Has the devices answer `answer` to [`GpuDevice::surface_pages_in_place`] from now on;
/// [`PagesInPlace::Yes`] at first.
///
/// [`GpuDevice::surface_pages_in_place`]: crate::platform::device::GpuDevice::surface_pages_in_place
/// [`GpuDevice::surface_pages_in_place`]: crate::core::platform::device::GpuDevice::surface_pages_in_place
pub fn answer_surface_pages(&self, answer: PagesInPlace) {
self.surface_pages.lock().0 = answer;
}
@@ -997,7 +997,7 @@ impl World {
/// What the devices answer to [`GpuDevice::surface_pages_in_place`] asked of `planes`, the
/// call recorded ([`World::surface_pages_asked`]).
///
/// [`GpuDevice::surface_pages_in_place`]: crate::platform::device::GpuDevice::surface_pages_in_place
/// [`GpuDevice::surface_pages_in_place`]: crate::core::platform::device::GpuDevice::surface_pages_in_place
pub fn surface_pages_in_place(&self, planes: &[PagesPlane]) -> PagesInPlace {
let mut state = self.surface_pages.lock();
state.1.push(planes.to_vec());
@@ -1006,7 +1006,7 @@ impl World {
/// The planes each call of [`GpuDevice::surface_pages_in_place`] was asked of, in order.
///
/// [`GpuDevice::surface_pages_in_place`]: crate::platform::device::GpuDevice::surface_pages_in_place
/// [`GpuDevice::surface_pages_in_place`]: crate::core::platform::device::GpuDevice::surface_pages_in_place
pub fn surface_pages_asked(&self) -> Vec<Vec<PagesPlane>> {
self.surface_pages.lock().1.clone()
}
@@ -1028,7 +1028,7 @@ impl World {
/// not, as a device of the Vulkan platform handed the guest's RAM whole does; not at first.
/// The copies answer as scripted ([`GUEST_RAM_TO_BUFFER`], [`BUFFER_TO_GUEST_RAM`]).
///
/// [`GpuDevice::copies_guest_ram`]: crate::platform::device::GpuDevice::copies_guest_ram
/// [`GpuDevice::copies_guest_ram`]: crate::core::platform::device::GpuDevice::copies_guest_ram
/// [`GUEST_RAM_TO_BUFFER`]: super::impls::blit::GUEST_RAM_TO_BUFFER
/// [`BUFFER_TO_GUEST_RAM`]: super::impls::blit::BUFFER_TO_GUEST_RAM
pub fn copy_guest_ram(&self, on: bool) {
@@ -1037,7 +1037,7 @@ impl World {
/// What the devices' [`GpuDevice::copies_guest_ram`] answers.
///
/// [`GpuDevice::copies_guest_ram`]: crate::platform::device::GpuDevice::copies_guest_ram
/// [`GpuDevice::copies_guest_ram`]: crate::core::platform::device::GpuDevice::copies_guest_ram
pub fn copies_guest_ram(&self) -> bool {
self.guest_ram_copies.load(Ordering::SeqCst)
}
@@ -1046,8 +1046,8 @@ impl World {
// `this` is set at construction and `self` is alive, so the upgrade holds.
match self.this.upgrade() {
Some(w) => w,
None => crate::testkit::capture::die(
crate::raise::death::DeathKind::Abort,
None => crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"fake/objects.rs",
),
}
@@ -1463,7 +1463,7 @@ fn with_read_death<R>(detail: Option<String>, f: impl FnOnce() -> R) -> R {
/// Vulkan platform dies at for a failure it reads there.
pub(crate) fn completion_read(info: CompletedInfo) -> CompletedInfo {
if let Some(detail) = READ_DIES.with(|d| d.borrow().clone()) {
crate::raise::Raise::platform("commit")
crate::core::raise::Raise::platform("commit")
.with_detail(detail)
.fatal();
}
@@ -1514,14 +1514,14 @@ pub fn complete_obj(
};
match on {
CompleteOn::Caller => {
let _env = crate::rt::BlockEnv::foreign();
let _env = crate::core::rt::BlockEnv::foreign();
run()
}
CompleteOn::Thread | CompleteOn::Detached => {
let slot = crate::testkit::capture::current_slot();
let slot = crate::core::testkit::capture::current_slot();
let spawned = std::thread::Builder::new()
.name("com.Metal.CompletionQueueDispatch".into())
.spawn(move || crate::testkit::capture::with_slot(slot, run));
.spawn(move || crate::core::testkit::capture::with_slot(slot, run));
if on == CompleteOn::Thread
&& let Ok(j) = spawned
{
@@ -1602,7 +1602,7 @@ pub fn wait_status(cb: &Arc<FakeObj>, at_least: CommandBufferStatus) {
#[cfg(test)]
mod tests {
use super::*;
use crate::num::ToU64;
use crate::core::num::ToU64;
/// Handles count retains; erase and cast keep the object
#[test]
@@ -1794,8 +1794,8 @@ mod tests {
/// the caller's mark is restored after
#[test]
fn caller_mode_handlers_run_as_foreign_thread() {
use crate::rt::block_env::current_label;
use crate::rt::is_our_thread;
use crate::core::rt::block_env::current_label;
use crate::core::rt::is_our_thread;
let w = World::new();
let cb: Fk<kind::CommandBuffer> =
w.new_obj(Model::CommandBuffer(CommandBufferModel::default()));
@@ -1956,8 +1956,8 @@ mod tests {
// In a sync block of a queue, on the caller's thread.
let p = super::super::platform::FakePlatform::new();
let q = crate::rt::queue::SerialQueue::new(
crate::platform::Platform::threads(&p),
let q = crate::core::rt::queue::SerialQueue::new(
crate::core::platform::Platform::threads(&p),
"test.events.sync",
);
let h: Fk<kind::Heap> = w.new_obj(Model::None);
@@ -1978,8 +1978,8 @@ mod tests {
let p = super::super::platform::FakePlatform::new();
let w = p.world().clone();
p.record_events(true);
let threads = crate::platform::Platform::threads(&p);
let q = crate::rt::queue::SerialQueue::new(threads, "test.events.async");
let threads = crate::core::platform::Platform::threads(&p);
let q = crate::core::rt::queue::SerialQueue::new(threads, "test.events.async");
let a: Fk<kind::Buffer> = w.new_obj(Model::None);
let a_id = a.id();
let (tx, rx) = std::sync::mpsc::channel();
@@ -1991,7 +1991,7 @@ mod tests {
rx.recv().unwrap();
let c: Fk<kind::Buffer> = w.new_obj(Model::None);
let c_id = c.id();
crate::rt::thread::spawn_named(
crate::core::rt::thread::spawn_named(
threads,
"test.events.thread",
1 << 20,
@@ -11,8 +11,8 @@
//! p.world().complete_all(CompleteOn::Thread); // the GPU finishes
//! ```
use crate::num::ToU64;
use crate::testkit::script::Policy;
use crate::core::num::ToU64;
use crate::core::testkit::script::Policy;
use std::sync::Arc;
use super::calllog::{Arg, CallLog};
@@ -25,13 +25,13 @@ use super::script::Script;
use super::surfaces::FakeSurfaces;
use super::threads::FakeThreads;
use super::vm::FakeVm;
use crate::platform::os::Threads;
use crate::platform::os::surface::IoSurfaces;
use crate::platform::os::vm::HostVm;
use crate::platform::types::{MtlSize, ResourceAddressRange};
use crate::platform::values::{RateMapDesc, TextureDesc};
use crate::platform::{Handle, ObjId, Platform};
use crate::raise::{OnFault, RaiseResult};
use crate::core::platform::os::Threads;
use crate::core::platform::os::surface::IoSurfaces;
use crate::core::platform::os::vm::HostVm;
use crate::core::platform::types::{MtlSize, ResourceAddressRange};
use crate::core::platform::values::{RateMapDesc, TextureDesc};
use crate::core::platform::{Handle, ObjId, Platform};
use crate::core::raise::{OnFault, RaiseResult};
/// The fake's device registry ID (`-[MTLDevice registryID]`).
pub const FAKE_REGISTRY_ID: u64 = 0x1_0000_0f00;
@@ -325,10 +325,10 @@ impl Platform for FakePlatform {
mod tests {
use super::super::script::Step;
use super::*;
use crate::platform::descriptor::TextureDescriptor;
use crate::platform::device::GpuDevice;
use crate::platform::rate_map::RateMapLayerDescriptor;
use crate::platform::values::{RateMapDesc, TextureDesc};
use crate::core::platform::descriptor::TextureDescriptor;
use crate::core::platform::device::GpuDevice;
use crate::core::platform::rate_map::RateMapLayerDescriptor;
use crate::core::platform::values::{RateMapDesc, TextureDesc};
/// Class methods make fresh objects; only the listener's `new` is ordered, and logged
#[test]
@@ -434,7 +434,10 @@ mod tests {
}])
.unwrap();
assert!(matches!(&r.state().model, Model::Ranges(v) if v.len() == 1));
assert_eq!(p.vm().page_size(), crate::testkit::guest_ram::PAGE_SIZE);
assert_eq!(
p.vm().page_size(),
crate::core::testkit::guest_ram::PAGE_SIZE
);
let _ = p.clock();
let _ = p.threads();
}
@@ -19,12 +19,12 @@ use std::any::Any;
use std::sync::Arc;
use std::time::Duration;
use crate::sync::{Condvar, Mutex};
use crate::core::sync::{Condvar, Mutex};
use crate::platform::ObjId;
use crate::platform::types::NsErrorText;
use crate::raise::death::{DeathId, DeathKind, DeathSite, fatal};
use crate::raise::{OnFault, Raise, RaiseResult};
use crate::core::platform::ObjId;
use crate::core::platform::types::NsErrorText;
use crate::core::raise::death::{DeathId, DeathKind, DeathSite, fatal};
use crate::core::raise::{OnFault, Raise, RaiseResult};
/// What a scripted raise at a send does: the label the platform's answer layer gives the same send
/// (the Vulkan crate's `answer::Policy`), so that the fake decides each raise as the real platform
@@ -65,7 +65,7 @@ pub enum Step {
/// method without an error out-parameter treats it as `Nil`.
Error(NsErrorText),
/// A creator the platform refuses for a gap of its own, where Metal makes the object: noted
/// as a relayed gap ([`crate::platform::device::note_relayed_gap`]), then as `Error`, nil
/// as a relayed gap ([`crate::core::platform::device::note_relayed_gap`]), then as `Error`, nil
/// with this `NSError` where the creator has an error out-parameter, else `Nil`.
Gap(NsErrorText),
/// Metal raised `name` with `reason` at the send (6.3).
@@ -281,7 +281,7 @@ impl Step {
) -> RaiseResult<Option<T>> {
self.throws(policy, sel)?;
if let Step::Gap(_) = self {
crate::platform::device::note_relayed_gap();
crate::core::platform::device::note_relayed_gap();
}
if self.is_nil() {
return Ok(None);
@@ -301,7 +301,7 @@ impl Step {
match self {
Step::Error(e) => Ok(Err(e.clone())),
Step::Gap(e) => {
crate::platform::device::note_relayed_gap();
crate::core::platform::device::note_relayed_gap();
Ok(Err(e.clone()))
}
Step::Nil => Ok(Ok(None)),
@@ -452,7 +452,7 @@ impl Script {
#[cfg(test)]
mod tests {
use super::*;
use crate::testkit::capture::catch_death;
use crate::core::testkit::capture::catch_death;
/// One-shot, counted and permanent entries
#[test]
@@ -544,7 +544,10 @@ mod tests {
let r = Step::raise("NSInvalidArgumentException", "bad")
.throws(Policy::Caught, "setLineWidth:");
let t = r.unwrap_err();
assert_eq!(t.origin(), crate::raise::Origin::Boundary("setLineWidth:"));
assert_eq!(
t.origin(),
crate::core::raise::Origin::Boundary("setLineWidth:")
);
let u = Step::unrecognized("setLineWidth:").create::<u8>(
Policy::On(OnFault::Return),
"setLineWidth:",
@@ -12,10 +12,10 @@ use super::calllog::Arg;
use super::guest_ram::RawRegion;
use super::objects::{FAKE_MAX_BYTES, Fk, Model, SurfaceModel, World, kind};
use super::platform::FakePlatform;
use crate::host::HostPtr;
use crate::num::ToU64;
use crate::platform::os::surface::{BackingSurfaceSpec, IoSurfaces, Surface, SurfaceSpec};
use crate::platform::os::vm::KernReturn;
use crate::core::host::HostPtr;
use crate::core::num::ToU64;
use crate::core::platform::os::surface::{BackingSurfaceSpec, IoSurfaces, Surface, SurfaceSpec};
use crate::core::platform::os::vm::KernReturn;
/// A fake `IOSurfaceRef`.
pub type FakeSurface = Fk<kind::Surface>;
@@ -59,7 +59,7 @@ impl FakeSurfaces {
impl IoSurfaces<FakePlatform> for FakeSurfaces {
fn create(&self, spec: &SurfaceSpec) -> Option<FakeSurface> {
self.world.log.push(
crate::platform::ObjId(0),
crate::core::platform::ObjId(0),
"IOSurface",
"IOSurfaceCreate",
vec![Arg::val(spec)],
@@ -67,7 +67,7 @@ impl IoSurfaces<FakePlatform> for FakeSurfaces {
let step = self
.world
.script
.next(crate::platform::ObjId(0), "IOSurfaceCreate");
.next(crate::core::platform::ObjId(0), "IOSurfaceCreate");
step.getter("IOSurfaceCreate");
if step.is_nil() {
return None;
@@ -93,7 +93,7 @@ impl IoSurfaces<FakePlatform> for FakeSurfaces {
fn create_backing(&self, spec: &BackingSurfaceSpec) -> Option<FakeSurface> {
self.world.log.push(
crate::platform::ObjId(0),
crate::core::platform::ObjId(0),
"IOSurface",
"initWithProperties:",
vec![Arg::val(spec)],
@@ -101,7 +101,7 @@ impl IoSurfaces<FakePlatform> for FakeSurfaces {
let step = self
.world
.script
.next(crate::platform::ObjId(0), "initWithProperties:");
.next(crate::core::platform::ObjId(0), "initWithProperties:");
step.getter("initWithProperties:");
if step.is_nil() {
return None;
@@ -259,8 +259,8 @@ impl Surface for Fk<kind::Surface> {
mod tests {
use super::super::script::Step;
use super::*;
use crate::platform::Handle;
use crate::platform::os::surface::BackingPlaneSpec;
use crate::core::platform::Handle;
use crate::core::platform::os::surface::BackingPlaneSpec;
fn surfaces() -> (Arc<World>, FakeSurfaces) {
let w = World::new();
@@ -2,9 +2,9 @@
use std::sync::Arc;
use crate::platform::os::{Threads, TimerClock};
use crate::sync::{Condvar, Mutex, MutexGuard};
use crate::testkit::objects::World;
use crate::core::platform::os::{Threads, TimerClock};
use crate::core::sync::{Condvar, Mutex, MutexGuard};
use crate::core::testkit::objects::World;
/// `Threads` over `std::thread`: no Objective-C runs on a fake thread, so a Rust thread base is
/// harmless here (4.5). Named spawns are recorded `(name, stack size)`, and each queue worker's
@@ -40,7 +40,7 @@ impl Default for FakeThreads {
struct WorldClock(Arc<World>);
impl TimerClock for WorldClock {
fn now_on(&self, d: crate::platform::os::Deadline) -> u64 {
fn now_on(&self, d: crate::core::platform::os::Deadline) -> u64 {
TimerClock::now_on(&self.0.clock, d)
}
@@ -48,7 +48,7 @@ impl TimerClock for WorldClock {
&self,
cv: &Condvar,
g: &mut MutexGuard<'_, bool>,
d: crate::platform::os::Deadline,
d: crate::core::platform::os::Deadline,
) {
TimerClock::wait_until(&self.0.clock, cv, g, d)
}
@@ -97,7 +97,10 @@ fn spawn_std(name: Option<&'static str>, stack_size: usize, body: Box<dyn FnOnce
#[allow(clippy::disallowed_methods)] // see above
let r = b.spawn(body);
if r.is_err() {
crate::testkit::capture::die(crate::raise::death::DeathKind::Abort, "testkit/threads.rs")
crate::core::testkit::capture::die(
crate::core::raise::death::DeathKind::Abort,
"testkit/threads.rs",
)
}
}
@@ -146,7 +149,7 @@ mod tests {
#[test]
fn queue_workers_are_recorded_by_label() {
let th = FakeThreads::default();
let q = crate::rt::queue::SerialQueue::new(&th, "reims-vgpu.test-queue");
let q = crate::core::rt::queue::SerialQueue::new(&th, "reims-vgpu.test-queue");
assert_eq!(th.queues(), vec!["reims-vgpu.test-queue"]);
assert!(th.spawned().is_empty());
let (tx, rx) = mpsc::channel();
@@ -21,18 +21,18 @@
use std::sync::Arc;
use crate::sync::Mutex;
use crate::core::sync::Mutex;
use super::calllog::{Arg, CallLog};
use super::guest_ram::{GuestRam, PAGE_SIZE, RawRegion, copy_between};
use super::script::Script;
use crate::host::HostPtr;
use crate::num::{self, ToU64, ToUsize};
use crate::platform::ObjId;
use crate::platform::os::vm::{HostAddr, HostVm, KernReturn, VmProt};
use crate::raise::death::DeathKind;
use crate::raise::death::DeathSite;
use crate::raise::death::fatal;
use crate::core::host::HostPtr;
use crate::core::num::{self, ToU64, ToUsize};
use crate::core::platform::ObjId;
use crate::core::platform::os::vm::{HostAddr, HostVm, KernReturn, VmProt};
use crate::core::raise::death::DeathKind;
use crate::core::raise::death::DeathSite;
use crate::core::raise::death::fatal;
/// `KERN_INVALID_ADDRESS`.
pub const KERN_INVALID_ADDRESS: KernReturn = KernReturn(1);
@@ -466,7 +466,7 @@ impl HostVm for FakeVm {
mod tests {
use super::super::script::Step;
use super::*;
use crate::testkit::capture::catch_death;
use crate::core::testkit::capture::catch_death;
fn vm() -> (FakeVm, CallLog, Script) {
let (log, script) = (CallLog::new(), Script::new());
@@ -19,7 +19,7 @@ use std::io::{BufWriter, Write as _};
use std::sync::OnceLock;
use std::sync::atomic::{AtomicU64, Ordering};
use crate::sync::Mutex;
use crate::core::sync::Mutex;
/// The environment variable naming the file.
pub const ENV_VAR: &str = "REIMS_VGPU_TRACE";
@@ -81,7 +81,7 @@ fn open(path: &OsStr) -> Option<Mutex<Writer>> {
}
/// Writes the lines the buffer holds to the file, for a death, which ends the process with no
/// `Drop` run ([`crate::raise::death`]). It opens no file, and takes the file's lock only where
/// `Drop` run ([`crate::core::raise::death`]). It opens no file, and takes the file's lock only where
/// it is free: the dying thread may hold it, or a thread the death stops before it lets go.
pub fn flush_before_death() {
if let Some(mut w) = WRITER
+6 -6
View File
@@ -59,11 +59,11 @@ pub mod ycbcr;
use std::ops::Range;
use crate::core::platform::types::{MtlOrigin, MtlRegion, MtlSize, NsRange, Swizzle};
use metal2vulkan::metal::{
PixelFormat, TextureSwizzle, TextureSwizzleChannels, TextureType, TextureUsage,
};
use metal2vulkan_runtime as rt;
use reims_vgpu_core::platform::types::{MtlOrigin, MtlRegion, MtlSize, NsRange, Swizzle};
use crate::answer::unrepresentable;
@@ -226,16 +226,16 @@ pub(crate) fn resource_options(sel: &'static str, raw: u64) -> rt::ResourceOptio
#[cfg(test)]
mod tests {
use super::*;
use reims_vgpu_core::raise::death::DeathKind;
use reims_vgpu_core::testkit::capture::catch_death;
use crate::core::raise::death::DeathKind;
use crate::core::testkit::capture::catch_death;
/// The platform's own buffers lie outside the Metal address space, `[2^47, 2^48)`, where no
/// guest buffer lies
#[test]
fn own_buffers_take_no_metal_address() {
use reims_vgpu_core::platform::device::GpuDevice as _;
use reims_vgpu_core::platform::resource::Buffer as _;
use reims_vgpu_core::raise::OnFault;
use crate::core::platform::device::GpuDevice as _;
use crate::core::platform::resource::Buffer as _;
use crate::core::raise::OnFault;
let d = crate::gpu::device::tests::dev();
let shared = rt::ResourceOptions::shared();
Loaded 100 of 261 files, more files were not shown because too many files have changed in this diff. Show more