From 42924b47093ecda8d812ad426554f24c998ad1ea Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Tue, 27 Oct 2026 22:51:09 -0647 Subject: [PATCH 1/3] omamobile-audio tests: the fake mixer and PipeWire write their state atomically The watchdog's jump test changes a control from a background job while the watchdog reads the fake mixer's state file, and CI once caught the read halfway through the write (JSONDecodeError, the test failed). Both fakes now write a temporary file and rename it over the state. --- packages/omamobile-audio/test/fake-amixer | 6 +++++- packages/omamobile-audio/test/fake-pw | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/omamobile-audio/test/fake-amixer b/packages/omamobile-audio/test/fake-amixer index 79d6b8776..fd00ead52 100755 --- a/packages/omamobile-audio/test/fake-amixer +++ b/packages/omamobile-audio/test/fake-amixer @@ -76,8 +76,12 @@ def load(): def save(c): - with open(state_path, 'w') as f: + # write and rename, so a reader running at the same moment (the + # watchdog while a test changes a control) never sees half a file + tmp = f'{state_path}.{os.getpid()}' + with open(tmp, 'w') as f: json.dump(c, f) + os.replace(tmp, state_path) def show(name, ctl): diff --git a/packages/omamobile-audio/test/fake-pw b/packages/omamobile-audio/test/fake-pw index 2577c4e6c..7a23b7c54 100755 --- a/packages/omamobile-audio/test/fake-pw +++ b/packages/omamobile-audio/test/fake-pw @@ -62,8 +62,10 @@ if me == 'pw-cli': if k not in vals or os.environ.get('FAKE_PW_IGNORE') == '1': continue # the filter ignores unknown controls vals[k] = float(v) - with open(state, 'w') as f: + tmp = f'{state}.{os.getpid()}' + with open(tmp, 'w') as f: json.dump(vals, f) + os.replace(tmp, state) log(args[3]) sys.exit(0) if me == 'wpctl': From 67517a9fceee5ce16c7c5b202da7bfddfad39998 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Wed, 28 Oct 2026 00:34:35 -0647 Subject: [PATCH 2/3] omamobile-audio 0.5.5: the tests' control backend writes atomically too The flake had a second writer: JsonCtl, the json: control backend the tests run the speaker code against, rewrites the fake mixer's state on every heartbeat read, in place. The fake mixer reading at that moment saw an empty file. JsonCtl now writes a temporary file and renames it, as the fakes do. Nothing changes on the palmtop: JsonCtl is used only with OMAMOBILE_CTL_BACKEND=json:. --- packages/omamobile-audio/lib/speaker_dsp.py | 14 ++++++++++---- packages/omamobile-audio/version | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/omamobile-audio/lib/speaker_dsp.py b/packages/omamobile-audio/lib/speaker_dsp.py index 162bde627..6842cf3ee 100644 --- a/packages/omamobile-audio/lib/speaker_dsp.py +++ b/packages/omamobile-audio/lib/speaker_dsp.py @@ -221,6 +221,14 @@ def _load(self): except (OSError, ValueError): return {} + def _save(self, state): + # rename over the file, so the fake mixer reading it at the same + # moment never sees half of it + tmp = f'{self.path}.{os.getpid()}' + with open(tmp, 'w') as f: + json.dump(state, f) + os.replace(tmp, self.path) + def names(self): return list(self._load()) @@ -238,8 +246,7 @@ def read(self, name): if name.endswith('HALO_HEARTBEAT') and os.environ.get('FAKE_HB_STUCK') != '1' and not frozen: v += 1 # the firmware's heartbeat moves while it runs c['v'] = list(v.to_bytes(4, 'big')) - with open(self.path, 'w') as f: - json.dump(state, f) + self._save(state) return v if t == 'ENUMERATED': return c['items'][c['v']] @@ -274,8 +281,7 @@ def write_bytes(self, name, data): if log_path: with open(log_path, 'a') as f: f.write(name + '\n') - with open(self.path, 'w') as f: - json.dump(state, f) + self._save(state) return True diff --git a/packages/omamobile-audio/version b/packages/omamobile-audio/version index 7d8568351..d1d899fa3 100644 --- a/packages/omamobile-audio/version +++ b/packages/omamobile-audio/version @@ -1 +1 @@ -0.5.4 +0.5.5 From 8f0618c634446b69b634ffffa427702cacb4f4e0 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Wed, 28 Oct 2026 00:55:29 -0647 Subject: [PATCH 3/3] omamobile-audio tests: the temperature jump comes after the watchdog's first reading The jump tests changed the estimate 0.4 s after starting the watchdog. On a slow CI runner the watchdog wasn't reading yet, took the raised value as its baseline, saw no jump and didn't mute. The jump now waits for the watchdog's start line and a few intervals, and the watchdog runs 60 iterations. --- packages/omamobile-audio/test/all | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/omamobile-audio/test/all b/packages/omamobile-audio/test/all index 4b17bed90..a694a0928 100755 --- a/packages/omamobile-audio/test/all +++ b/packages/omamobile-audio/test/all @@ -351,8 +351,12 @@ pass "watchdog: mutes on DSP errors, bypass, levels, runtime PM, a stuck heartbe # level drop, so a jump there must not mute; OMAMOBILE_SPK_TEMP_JUMP brings it back. jump() { # name [wprep...]: watchdog on a running stream; the bottom's estimate goes 25 -> 40 C a moment in local n=$1; shift; echo 'state: RUNNING' > "$r/asound/card0/pcm5p/sub0/status"; wprep=("$@") - ( sleep 0.4; amx cset "name=Bottom DSP1 Protection cd CSPL_TEMPERATURE" 0x00,0x0a,0x00,0x00 >/dev/null ) & - watchrun; wait + # the jump comes once the watchdog has its first reading (its start line, + # then a few intervals), not at a fixed time: a slow runner started it late + rm -f "$r/watch.out" + ( for _ in $(seq 1 100); do grep -c 'watchdog: watching' "$r/watch.out" >/dev/null 2>&1 && break; sleep 0.05; done + sleep 0.3; amx cset "name=Bottom DSP1 Protection cd CSPL_TEMPERATURE" 0x00,0x0a,0x00,0x00 >/dev/null ) & + WATCH_N=60 watchrun; wait } startok w-jump8; jump w-jump8 ((rc == 0)) && ! muted && grep -c 'jump rule off' "$r/watch.out" >/dev/null || { cat "$r/watch.out" >&2; fail "watchdog: at analog 10 or below a 15 C jump of the estimate does not mute (C9j)"; }