b6fdee8bfc
Consolidated release: the cross-platform Linux port (engine, generators, CLI, REPL, NRT, portable DSP), live ALSA audio + ALSA MIDI + POSIX OSC + portable WAV codec, the GTK4 GUI (LyrebirdUI on the SwiftOpenUI backend), and the Linux live-coding scratchpad (LiveCompile). Apple platforms unchanged; all additive. See RELEASES.md and LINUX_README.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
48 lines
1.8 KiB
Swift
48 lines
1.8 KiB
Swift
// ALSARecoveryActionTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Testing
|
|
import LyrebirdSynth
|
|
|
|
// The xrun policy decides whether the render loop recovers, retries, or dies.
|
|
// It is pure arithmetic over ALSA's return value, so it is tested on every
|
|
// platform even though the driver consuming it is Linux-only.
|
|
|
|
@Suite("ALSA transfer recovery policy")
|
|
struct ALSARecoveryActionTests {
|
|
|
|
@Test func successReportsFramesTransferred() {
|
|
#expect(ALSARecoveryAction.classify(512) == .transferred(frames: 512))
|
|
}
|
|
|
|
@Test func shortTransferIsStillSuccess() {
|
|
// A partial write is normal; the loop resumes from where it stopped.
|
|
#expect(ALSARecoveryAction.classify(37) == .transferred(frames: 37))
|
|
}
|
|
|
|
@Test func zeroFramesIsSuccessNotAnError() {
|
|
#expect(ALSARecoveryAction.classify(0) == .transferred(frames: 0))
|
|
}
|
|
|
|
@Test func signalInterruptionIsDistinctFromDeviceNotReady() {
|
|
// Kept apart on purpose: a signal is not a device fault, so it reissues
|
|
// immediately and must not spend the patience budget that a device
|
|
// which never becomes ready does.
|
|
#expect(ALSARecoveryAction.classify(-4) == .interrupted) // -EINTR
|
|
#expect(ALSARecoveryAction.classify(-11) == .wouldBlock) // -EAGAIN
|
|
}
|
|
|
|
@Test func underrunAndSuspendRecover() {
|
|
#expect(ALSARecoveryAction.classify(-32) == .recover) // -EPIPE (xrun)
|
|
#expect(ALSARecoveryAction.classify(-86) == .recover) // -ESTRPIPE (suspended)
|
|
}
|
|
|
|
@Test func unknownErrorIsFatal() {
|
|
#expect(ALSARecoveryAction.classify(-19) == .fail) // -ENODEV, device unplugged
|
|
#expect(ALSARecoveryAction.classify(-77) == .fail) // -EBADFD
|
|
}
|
|
}
|