silk.testing.exchange.
The binary plan and receipt formats that let silk test control the test runner.
When to use#
silk.testing.runner uses this module. The host (the silk test driver) writes a plan file,
and the runner writes a receipt file. You do not call it from normal code.
Details#
A plan is exactly 256 bytes: the magic SLKTPLN1, a version (1), the mode 2, a 32-byte
nonce, a SHA-256 digest of the catalog (see updateCatalogDigest) and the test count, then
zero padding. All integers are little-endian.
A receipt starts with the magic SLKTRCP1, the version, the mode, the nonce of the plan, and
the SHA-256 of the complete plan. Then come the counts and the status, then zero padding to 256
bytes.
A progress record lets the host continue a run after a test traps. It is exactly 48 bytes: the
magic SLKTPRG1, the ordinal of the test that is starting, then the cached, executed, passed
and failed counts before that test. The runner writes one before each test body runs, so after
an abnormal exit the record names the test that stopped the process.
Gotchas#
A
Plandoes not stop at the first error. After a failure it reads as empty, andfailedstays true. Checkfailedor theboolresults before a test body runs.Test output goes to the inherited stdout and stderr. Only the receipt decides the result.
Import as TestExchange with import silk.testing.exchange as TestExchange.
Public declarations: 11.
Plan#
pub struct Plan<'a>A cursor over one borrowed plan file that the silk test driver wrote.
Gotchas#
It does not stop at the first error. After a failure it reads as empty, and failed
stays true. Check failed or the bool results before a test body runs.
Progress#
pub struct ProgressA run's position when a test started: the catalog ordinal of that test and the counts before it.
Details#
The runner writes it with progressRecord before each test body runs. After the process
stops abnormally, readProgress reads it back, and a new runner continues after that test.
Field ordinal#
pub ordinal: u64The catalog ordinal of the test that was starting.
Field cachedCount#
pub cachedCount: u64The cached passes before that test.
Field executed#
pub executed: u64The tests executed before that test.
Field passed#
pub passed: u64The tests that passed before that test, cached passes included.
Field failedCount#
pub failedCount: u64The tests that failed before that test.
Receipt#
pub struct ReceiptAn owned receipt under construction. Start it with beginReceipt.
openPlan#
pub fn openPlan<'a>(bytes: &'a [u8]) -> Plan<'a>Opens a plan and checks its magic, version, mode and nonce framing.
If a check fails, the returned plan is already rejected: it reads as empty, and failed
returns true.
failed#
pub fn failed(plan: &Plan<'_>) -> boolReturns true after a check on the plan fails. It does not become false again.
validate#
pub fn validate(
plan: &mut Plan<'_>,
expectedCatalogDigest: &[u8],
expectedDiscovered: u64,
) -> boolChecks a plan: exactly 256 bytes, the catalog digest, the test count, and zero padding.
updateCatalogDigest#
pub fn updateCatalogDigest(state: &mut Sha256, ordinal: u64, identity: &[u8]) -> ()Adds one catalog identity to the digest of a plan.
It hashes the ordinal and the identity length as 8-byte little-endian values, then the identity.
beginReceipt#
pub effect fn beginReceipt(plan: &[u8]) -> Receipt ! OutOfMemoryError ? &mut AllocatorStarts a receipt for plan. It copies the nonce and hashes the complete plan.
finishReceipt#
pub effect fn finishReceipt(
receipt: Receipt,
discovered: u64,
selected: u64,
cachedCount: u64,
executed: u64,
passed: u64,
failedCount: u64,
status: u32,
) -> Bytes ! OutOfMemoryError ? &mut AllocatorAppends the counts and the status, and returns the receipt bytes, padded to exactly 256 bytes.
Details#
cachedCount counts the selected tests the runner did not run because they passed before with
the same code and inputs; passed includes them.
progressRecord#
pub effect fn progressRecord(progress: &Progress) -> Bytes ! OutOfMemoryError ? &mut AllocatorReturns the 48-byte progress record of progress.
Details#
The record is the magic SLKTPRG1, then the ordinal and the four counts as 8-byte
little-endian integers.
readProgress#
pub fn readProgress(bytes: &[u8]) -> Option<Progress>Reads a progress record that progressRecord wrote.
Details#
It returns None unless bytes is exactly one record with the SLKTPRG1 magic.
Category: Testing.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.