leonida-lua: a_scan_without_a_size_reaches_the_end_of_the_image fails about one run in twenty #3193
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T17:56:13Z.
leonida-luahas one test that fails about one run in twenty, and it is not attached to any pull request.What
It writes
DE AD BE EFatbase + size - 100and assertstail 1 1- once from an unboundedm.scan("DE AD BE EF")and once fromm.scan("DE AD BE EF", {start = base - 100}).Rate, measured
cargo test -p leonida-lua --libin a loop, onmain5b1fff821, Ryzen 7 7800X3D, Windows 11:mainSo it is pre-existing and unrelated to that pull request - it showed as "1 in 7" while I was checking #3189, which reads like a regression, and it is not.
Reproduce
Match
test result: FAILED, notFAILED. My first attempt counted 20 failures in 20 runs on both sides because-match 'FAILED'also matches "0 failed" in the success line - a reader who repeats this without the exact phrase will get a different and wrong answer.What I did not determine
Why. The marker is written at a fixed offset from the end of the image, so it is either not landing where the scans look or the image's size moving between the two calls. That needs the memory image and the scan path, not a repetition count.
No game, no GPU, no title needed - this is
cargo teston the crate.AI-assisted: yes - DeepSeek v4.1 (flash).
Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T17:57:53Z.
Cause narrowed: it is the tests racing each other, not the test being flaky on its own.
cargo test -p leonida-lua --libin a loop, 20 runs each, onmain5b1fff821:#[test]s in parallel)-- --test-threads=1So the test is fine alone and wrong when another test runs beside it.
rig()builds a fake memory, the test writesDE AD BE EFatbase + size - 100and asserts the scans find it once - if the image or the base/size pair is shared with anotherrig, a second occurrence shows up and the assertion fails with a count of 2 instead of 1.What that points at: a process-global in the Lua test rig (a static memory image, or the
leonida.memorybase/size resolved from something global rather than from the rig). I have not read far enough to name the static - that is the next step, and it is agrepforstaticinleonida-lua's rig, not another 20 runs.What this does not say: that
--test-threads=1is a fix. It hides the race, it does not remove it - and two tests sharing a memory image will keep finding new ways to corrupt each other.AI-assisted: yes - DeepSeek v4.1 (flash).
Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T17:58:43Z.
Found the shared state, and the size of the fix.
d3d12/crates/leonida-lua/src/memory.rs:The memory image is process-global and set once. Every
rig()intests.rswrites into the sameIMAGE, so two tests running side by side see each other's bytes - which is exactly why the marker is found twice and the assertiontail 1 1fails. That it is aOnceLockalso means the firstrig()decides the base and size for every later one, which is worth knowing whoever fixes this.The repository already has a pattern for this, from #2854 (
d3d12-gpu: fix parallel unit test races in watch, descriptor): astatic TEST_SYNC_LOCK: std::sync::Mutex<()>in the test module, taken by the tests that touch the global (descriptor.rs:378,fg.rs:456,host.rs:846).serial_testis not a dependency and#[serial]is not used anywhere, so the mutex is the convention.Why this is not a two-line fix here: the lock has to be held for the length of a test, so it cannot be taken inside
rig()and dropped -rig()would have to return the guard, and every test in the file destructureslet (_d, fake, _rt) = rig(...)(~40 of them), so the tuple grows and all of them change. That is mechanical, but it is not small, and it is the owner's call whether the guard travels or the memory image stops being global.Not done here: I did not write the fix. I found the cause and the pattern; the change touches 40 call sites in a crate I do not own, and a wrong one there would make the race quieter rather than gone.
AI-assisted: yes - DeepSeek v4.1 (flash).
Written with an AI assistant.