Skip to navigation

holoscan.testing

Beta
View as Markdown

Module Contents

Classes

NameDescription
CaptureFailureOwn a failed capture’s sample metadata and native error without retaining the payload or a
ClockTestOutcome-
ControlledClockRunObserve one positive period-boundary tick with a shared clock initially frozen at zero.
FrameRelease-
OperatorTestHarnessConstruct fresh registered C++ or Python operators through ordinary Graph services.
RetainRequest native Tensor backing without a host copy.
RunningFixtureOwn an attempt created by OperatorTestHarness.run_async; finish joins it.
SchemaSnapshotOwn copied schema metadata and independent host snapshots of every present admitted Tensor
TensorSnapshotOwn contiguous host content and original Tensor metadata independently of runtime pools.
TestLifecycleOptionsImmutable tested-operator restart permissions, independent and denied by default.
TestResultOwn joined diagnostics and captures independently of the harness.
TestRunOptionsConfigure one finite attempt.
TestSampleOne payload with an optional integer nanosecond capture coordinate.
_NativeRunningOwnerOpaque native owner created only by OperatorTestHarness.run_async.

Functions

NameDescription
result_ofReturn the joined test result directly attached to an exception, if any.
sample_atCreate one timestamped staging envelope.

API

class holoscan.testing.CaptureFailure()

Own a failed capture’s sample metadata and native error without retaining the payload or a finite read claim.

error
DiagnosticError

Return the native error code and detail explaining why capture failed.

metadata
SampleMetadata

Return native sample metadata associated with the failed capture.

class holoscan.testing.ClockTestOutcome

Bases: enum.Enum

FAILED
= 3
NOT_REQUESTED
= 0
RETIRED
= 1
SUPPRESSED
= 2
class holoscan.testing.ControlledClockRun(
tick_ns: int,
observation_capacity: int = 1024,
timeout_ms: int = 30000
)

Observe one positive period-boundary tick with a shared clock initially frozen at zero.

The startup tick is real. This restricted profile is not an operator stepping API.

observation_capacity
int

Positive bound on native observation records and total publication attempts; defaults to 1024.

tick_ns
int

Positive tick coordinate in integer nanoseconds, exactly on a boundary of the operator clock period.

timeout_ms
int

Positive steady-clock cooperative watchdog in integer milliseconds, independent of synthetic time; defaults to 30000.

class holoscan.testing.FrameRelease

Bases: enum.Enum

AUTOMATIC
= 0
MANUAL
= 1
class holoscan.testing.OperatorTestHarness(
params: collections.abc.Mapping[str, object] | None = None,
outputs: str | collections.abc.Sequence[str] | None = None
)

Construct fresh registered C++ or Python operators through ordinary Graph services.

holoscan.testing.OperatorTestHarness.__enter__() -> typing.Self
holoscan.testing.OperatorTestHarness.__exit__(
exc_type: type[BaseException] | None,
exc: BaseException | None,
traceback: types.TracebackType | None
) -> None
holoscan.testing.OperatorTestHarness.capture(
port: str,
capacity: int = 1024
) -> None

Replace the selected output policy with value capture and a positive finite record limit.

Tensor-bearing outputs require capture_snapshot or explicit capture_native. Overflow fails the run without silent truncation; Python objects retain identity rather than an implicit deep copy.

holoscan.testing.OperatorTestHarness.capture_native(
port: str,
policy: holoscan.testing.Retain | None = None
) -> None

Opt into native Tensor retention, retaining source backing instead of copying to host.

The finite source, single output, capacity and completion must satisfy native admission. None selects the default Retain record limit.

holoscan.testing.OperatorTestHarness.capture_snapshot(
port: str,
capacity: int = 1024,
maximum_bytes: int = 67108864
) -> None

Replace the output policy with independent host snapshots.

capacity bounds records; maximum_bytes bounds each complete record, including all admitted Tensor fields of a schema. Both limits are positive. Overflow fails capture without publishing a partial record.

holoscan.testing.OperatorTestHarness.clear_input_flow(
port: str
) -> None

Remove the input edge override and restore native fixture derivation.

holoscan.testing.OperatorTestHarness.clear_input_queue_depth(
port: str
) -> None

Remove this port’s input queue depth override.

holoscan.testing.OperatorTestHarness.clear_input_source_device(
port: str
) -> None

Remove this port’s input source device override.

holoscan.testing.OperatorTestHarness.clear_input_source_tensor_spec(
port: str
) -> None

Remove this port’s input source tensor spec override.

holoscan.testing.OperatorTestHarness.clear_input_tensor_spec(
port: str
) -> None

Remove this port’s input tensor spec override.

holoscan.testing.OperatorTestHarness.clear_lifecycle_options() -> None

Clear both permissions while preserving staging and compile options.

holoscan.testing.OperatorTestHarness.clear_output_device(
port: str
) -> None

Remove this port’s output device override.

holoscan.testing.OperatorTestHarness.clear_output_flow(
port: str
) -> None

Remove the output edge override and restore native fixture derivation.

holoscan.testing.OperatorTestHarness.clear_output_tensor_spec(
port: str
) -> None

Remove this port’s output tensor spec override.

holoscan.testing.OperatorTestHarness.close() -> None

Release the builder resources.

Existing results and independently owned running attempts remain valid.

holoscan.testing.OperatorTestHarness.push(
port: str,
value: object
) -> None

Append one payload to an input.

Containers remain one payload; None is data on an admitted object port. Reject mixing grouped and independent producers for an input.

holoscan.testing.OperatorTestHarness.push_frame(
entries: collections.abc.Mapping[str, object] | collections.abc.Iterable[tuple[str, object]],
capture_timestamp_ns: int | None = None
) -> None

Atomically append one frame from a mapping or ordered unique (port, payload) pairs.

Values share the optional nanosecond capture coordinate; omitted ports publish nothing. Reject duplicate ports and mixing grouped and independent producers.

holoscan.testing.OperatorTestHarness.push_many(
port: str,
values: collections.abc.Iterable[object]
) -> None

Atomically append an explicit batch in caller order.

Reject strings, bytes, bytearrays and mappings as ambiguous batches. Conversion failure leaves pending input unchanged.

holoscan.testing.OperatorTestHarness.push_samples(
port: str,
samples: collections.abc.Iterable[holoscan.testing.TestSample]
) -> None

Atomically append TestSample envelopes in caller order.

Capture coordinates do not sort inputs or advance time. Reject non-sample entries and invalid timestamps before staging changes.

holoscan.testing.OperatorTestHarness.run(
options: holoscan.testing.TestRunOptions | None = None,
check: bool = True

Execute and join a fresh attempt.

By default, failure raises the native HoloscanError subclass with .result attached; check=False returns that result. Invalid configuration can still raise before a result exists. Joining releases the GIL and rejects Runtime callback contexts.

holoscan.testing.OperatorTestHarness.run_async(
options: holoscan.testing.TestRunOptions | None = None

Start a fresh attempt owning resources independently of the builder.

Inputs must already be staged; payloads become available only in joined finish results. One active attempt per harness is permitted.

holoscan.testing.OperatorTestHarness.run_controlled_clock(
check: bool = True

Run and join the restricted native clock-observation profile.

Requires one sample per scalar input, ordinary OnClock/LatestWithin/Skip semantics and capture of every output. Unsupported configurations reject before staged input is consumed. Checked failures expose .result.

holoscan.testing.OperatorTestHarness.set_compile_options(
) -> None

Copy compile options for subsequent fresh attempts.

Later caller mutation does not change this copy. Native application order and active- attempt mutation rejection remain authoritative.

holoscan.testing.OperatorTestHarness.set_input_flow(
port: str,
queue_policy: holoscan.QueuePolicy = ...,
queue_depth: int | None = None,
topic_name: str | None = None,
memory_conversion: holoscan.tensor.MemoryConversionPolicy | None = None,
max_inflight_samples: int | None = None
) -> None

Replace the input edge options using the canonical Graph keyword rules.

Omitted/None fields take Graph defaults. With no keywords, set default options; use clear_input_flow to restore native fixture derivation. Values are copied. Invalid options and active attempts leave prior state intact.

holoscan.testing.OperatorTestHarness.set_input_queue_depth(
port: str,
depth: int | None
) -> None

Replace tested-operator input history depth, distinct from edge queue capacity.

None clears the override. Native range/direction checks and active-attempt rejection preserve previous configuration on failure.

holoscan.testing.OperatorTestHarness.set_input_source_device(
port: str,
) -> None

Copy or clear staged-source CUDA placement.

holoscan.testing.OperatorTestHarness.set_input_source_tensor_spec(
port: str,
) -> None

Copy or clear a staged producer Tensor promise.

holoscan.testing.OperatorTestHarness.set_input_tensor_spec(
port: str,
) -> None

Copy or clear an operator Tensor input contract.

holoscan.testing.OperatorTestHarness.set_lifecycle_options(
) -> None

Copy replacement permissions; None denies both.

Reject active-attempt changes atomically.

holoscan.testing.OperatorTestHarness.set_output_device(
port: str,
) -> None

Copy or clear tested-operator CUDA output placement.

holoscan.testing.OperatorTestHarness.set_output_flow(
port: str,
queue_policy: holoscan.QueuePolicy = ...,
queue_depth: int | None = None,
topic_name: str | None = None,
memory_conversion: holoscan.tensor.MemoryConversionPolicy | None = None,
max_inflight_samples: int | None = None
) -> None

Replace the output edge options using the canonical Graph keyword rules.

Omitted/None fields take Graph defaults. With no keywords, set default options; use clear_output_flow to restore native fixture derivation. Values are copied. Invalid options and active attempts leave prior state intact.

holoscan.testing.OperatorTestHarness.set_output_tensor_spec(
port: str,
) -> None

Copy or clear an operator Tensor output contract.

holoscan.testing.OperatorTestHarness.set_params(
params: collections.abc.Mapping[str, object]
) -> None

Replace parameters atomically after validating pending inputs, capture selectors and overrides.

Failed construction or validation preserves prior state. Automatic outputs follow new declarations; explicit selections must remain valid.

class holoscan.testing.Retain(
max_records: int = 1024
)

Request native Tensor backing without a host copy.

Admission requires a finite source with one output and proven capacity and completion; unsupported geometries reject.

max_records
int

Positive finite retained-record limit; defaults to 1024.

Overflow fails capture without truncating output.

class holoscan.testing.RunningFixture(
)

Own an attempt created by OperatorTestHarness.run_async; finish joins it.

is_running
bool

Report whether the native attempt is still active; do not join.

termination
RunTermination

Return the native termination observation without joining the attempt.

holoscan.testing.RunningFixture.__enter__() -> typing.Self
holoscan.testing.RunningFixture.__exit__(
exc_type: type[BaseException] | None,
exc: BaseException | None,
traceback: types.TracebackType | None
) -> None
holoscan.testing.RunningFixture.close() -> None

Request cooperative stop and join with the GIL released.

This has no hard timeout and rejects Runtime callback joins. Use finish to inspect the resulting outcome.

holoscan.testing.RunningFixture.finish(
check: bool = True

Join normally with the GIL released and return the same result on repeated calls.

Default checking raises with .result attached; check=False returns a failed result for inspection. Reject joins from Runtime callbacks.

holoscan.testing.RunningFixture.lifecycle_control(

Create Core lifecycle control restricted by run-bound targets and source stages in the policy.

Graph permissions and transaction capacities remain required; creating control does not request restart.

holoscan.testing.RunningFixture.operator_ref(

Return the tested operator reference bound to this run, or bind the supplied plan reference through Core.

Foreign and stale identities reject.

holoscan.testing.RunningFixture.output_count(
port: str
) -> int

Observe the captured record count without exposing unjoined payloads.

holoscan.testing.RunningFixture.release_frame(
timeout_ms: int | None = None
) -> None

Admit the next pre-staged manual frame.

None or zero attempts release once without waiting; positive integer milliseconds allow bounded admission waiting. Success does not mean the frame has been computed or captured.

holoscan.testing.RunningFixture.request_stop() -> None

Request cooperative stop without joining; permitted in Runtime callbacks.

holoscan.testing.RunningFixture.wait_for_output(
port: str,
minimum: int,
timeout_ms: int
) -> bool

Wait up to timeout_ms milliseconds for a count; zero only polls.

Return False when the count is not reached before timeout or completion. This releases the GIL while waiting and never joins or reruns the operator.

class holoscan.testing.SchemaSnapshot()

Own copied schema metadata and independent host snapshots of every present admitted Tensor field.

Absent optional fields retain their absence.

metadata
object

Return copied schema metadata with Tensor members unset.

Use tensor() for field content; this metadata is not a complete payload to republish.

sample_metadata
SampleMetadata

Return semantic sample metadata copied when the schema output was collected.

tensor_fields
list[str]

Return all admitted Tensor field names, including absent optional fields.

holoscan.testing.SchemaSnapshot.has_tensor(
name: str
) -> bool

Return whether a known Tensor field was present.

Raise ValueError for an unknown field.

holoscan.testing.SchemaSnapshot.tensor(
name: str

Return the independent host snapshot of a present Tensor field.

Raise ValueError for an absent or unknown field.

class holoscan.testing.TensorSnapshot()

Own contiguous host content and original Tensor metadata independently of runtime pools.

This inspection record is not a Tensor for publication.

bytes
bytes

Return a Python bytes copy of contiguous logical Tensor content.

Source strides and offset describe the original allocation, not this host buffer.

dtype
DLDataType

Return the original DLPack element representation.

sample_metadata
SampleMetadata

Return semantic sample metadata copied when the output was collected.

shape
list[int]

Return the original logical dimension extents.

source_byte_offset
int

Return the logical Tensor byte offset within its original source allocation.

source_byte_strides
list[int]

Return the original layout strides in bytes, including explicit contiguous strides.

source_device
DLDevice

Return the original DLPack device, which can differ from the snapshot host storage.

class holoscan.testing.TestLifecycleOptions(
allow_self_restart: bool = False,
allow_external_restart: bool = False
)
Dataclass

Immutable tested-operator restart permissions, independent and denied by default.

__test__
bool
allow_external_restart
bool = False

Permit external control subject to the native runtime access policy.

allow_self_restart
bool = False

Permit the tested operator to request its own restart.

holoscan.testing.TestLifecycleOptions.__post_init__() -> None
class holoscan.testing.TestResult()

Own joined diagnostics and captures independently of the harness.

Inspection never executes work. Python-object identity is retained; snapshots own host content. Retaining the plan can retain staged Tensor leases.

__test__
bool
clock_outcome
ClockTestOutcome

Return the controlled tick retirement or suppression outcome; ordinary runs return NOT_REQUESTED.

diagnostics
list[Diagnostic]

Return a copied list of compile and runtime diagnostics retained after join.

ok
bool

Report whether admission, capture and expected completion succeeded.

Watchdog expiry and capture failures fail the test; a clean stopped run needs expect_stop or the native controlled-clock/retention completion proof.

plan
Plan

Return the compiled plan, including rejected-admission diagnostics.

Inspection does not execute it.

termination
RunTermination

Return actual native run termination, independently of whether the test passed.

holoscan.testing.TestResult.capture_failure(
name: str

Return the failed capture error and sample metadata, or None if collection did not fail.

Reject unknown or uncaptured outputs. The failed payload is not retained.

holoscan.testing.TestResult.clock_selection(
name: str

Return the named input selection at the completed controlled tick.

Reject ordinary runs, incomplete observations and unknown inputs.

holoscan.testing.TestResult.describe_failure() -> str

Describe rejected admission, termination, capture errors and watchdog expiry; return an empty string on success.

holoscan.testing.TestResult.samples(
name: str
) -> list[holoscan.Sample]

Return value or native-retention captures with native sample metadata, preserving Python-object identity.

Raise ValueError for unknown, unselected or snapshot outputs.

holoscan.testing.TestResult.snapshot(
name: str

Return the sole Tensor or schema snapshot.

Raise ValueError unless exactly one record exists, or for unknown, unselected or value- capture outputs.

holoscan.testing.TestResult.snapshots(
name: str

Return independent host Tensor or schema snapshots in collection order, possibly empty.

Raise ValueError for unknown, unselected or value-capture outputs.

holoscan.testing.TestResult.value(
name: str
) -> object

Return the sole value or native-retention payload.

Raise ValueError unless exactly one record exists, or for unknown, unselected or snapshot outputs.

holoscan.testing.TestResult.values(
name: str
) -> list[object]

Return a new list of value or native-retention captures in collection order, possibly empty.

Python objects are not deep-copied. Raise ValueError for unknown, unselected or snapshot outputs.

class holoscan.testing.TestRunOptions(
timeout_ms: int = 30000,
expect_stop: bool = False,
frames: holoscan.testing.FrameRelease = FrameRelease.AUTOMATIC
)

Configure one finite attempt.

Values are copied for the run; invalid options reject when the attempt starts.

__test__
bool
expect_stop
bool

Accept clean cooperative stop as expected.

Errors, watchdog expiry and missing controlled-clock/retention completion proof still fail.

frames
FrameRelease

Select automatic or manual finite frame release.

Manual release requires run_async and grouped input staging.

timeout_ms
int

Positive steady-clock watchdog in integer milliseconds; defaults to 30000.

Expiry requests cooperative stop and fails the test, but cannot interrupt a blocked callback.

class holoscan.testing.TestSample(
data: object,
capture_timestamp_ns: int | None = None
)
Dataclass

One payload with an optional integer nanosecond capture coordinate.

__test__
bool
capture_timestamp_ns
int | None = None
data
object
holoscan.testing.TestSample.__post_init__() -> None
class holoscan.testing._NativeRunningOwner()

Opaque native owner created only by OperatorTestHarness.run_async.

holoscan.testing.result_of(
error: BaseException

Return the joined test result directly attached to an exception, if any.

Preserve the original result’s identity and partial outputs. Unrelated exceptions and attachments return None; causes are not searched. Inspection never executes or joins an operator.

holoscan.testing.sample_at(
data: object,
capture_timestamp_ns: int

Create one timestamped staging envelope.

Coordinates are signed 64-bit integer nanoseconds in the fixture clock domain; they do not advance time or schedule compute. Reject booleans, non-integers and out-of-range values.