Repository navigation
ci(qemu): make the runtime-bundle build prove its own closure - #1927
Merged
Merged
Conversation
`ci/build_qemu_linux_runtime.py` was the last untested workflow-invoked gate. It builds the tar.zst that `esp_qemu_runtime.rs` downloads, and three of its checks could not fail: * the breadth-first closure walk was a fixed `for _round in 1..8` loop that simply ENDED with a non-empty frontier, so a deeper graph produced a short archive and the five-name required check still passed; * completeness was five hand-typed names while the `--version` selftest removed only three of the five apt packages -- libgcrypt20 and zlib1g stay installed (zlib1g is priority:required), so a gap behind either was unobservable; * a truncated `tar | zstd` copies out of the container with exit code 0 and was hashed and published. Now: the walk converges or is FATAL; `verify_closure()` proves every DT_NEEDED of every bundled library is glibc or present (via a separate `needed()` reader that keeps `=> not found` entries, which `deps()` rightly drops); the archive must contain MANIFEST.txt and at least the required number of lib/ entries (`zstd -dc | tar -t`, since the image's tar 1.30 has no `--zstd`); and `_assert_payload()` refuses a missing or empty artifact, with the container removed in a `finally`. The tag, archive version, required libraries and glibc family are declared once and injected into the payload, and tests compare them against the constants in `esp_qemu.rs` / `esp_qemu_runtime.rs` instead of a "keep in sync" comment. ci/test_build_qemu_linux_runtime.py: 31 tests -- the Python half through a fake `docker` on PATH, and the bash closure logic executed against a stubbed `ldd` straight from the rendered payload between marker lines.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ci/build_qemu_linux_runtime.pyis the last untested workflow-invoked gate inthe
ci/gate_script_tests.tomlratchet. It builds thetar.zstbundle thatevery Linux host downloads when it cannot start Espressif's QEMU itself, and
esp_qemu_runtime.rsnames that asset by composingqemu-esp-linux-runtime-<arch>-<RUNTIME_VERSION>.tar.zst.Three of its "proofs" were not proofs, and the tag/libraries it shares with Rust
were joined to the consumer by a comment asking the next person to keep them in
sync.
The defects
The closure walk ended silently when it did not converge.
for _round in 1 2 3 4 5 6 7 8 ... doneleft a still-unexpanded frontier onthe floor. A graph deeper than the cap produced a short archive and every
later check only looked for the same five names, so it shipped green.
The completeness check could not see the gap it was written to catch.
Five hand-typed names were checked, and the
--versionselftest that wassupposed to prove the closure removes only three of the five apt packages.
libgcrypt20andzlib1gnecessarily stay installed (zlib1g ispriority: required), so a missing transitively-reachable library behindeither one was invisible: the binary starts, the archive publishes, and the
failure lands on a user's machine.
A truncated
tar czf-equivalent published as success.docker cpreturns 0 for a zero-byte or half-written file, so a
tar | zstdkilled midflight was hashed and handed out as an install candidate.
The bridge to Rust was a comment.
QEMU_RELEASE_TAGlived in threeplaces (
esp_qemu.rs,esp_qemu_runtime.rs, this script) and the fiverequired libraries in two, with no test comparing them. Drift in the tag
makes the published asset name not match the URL the consumer fetches --
and nothing in the builder would notice.
The fix
collect_closure()is now awhilewalk whose frontier contains onlynon-glibc libraries, so convergence is "frontier empty" and hitting
MAX_CLOSURE_ROUNDSis aFATALnaming what was left unexpanded.verify_closure()proves the bundle is a complete closure: everyDT_NEEDEDof every bundled library is either the glibc family / loader orpresent in
lib/. It uses a separateneeded()reader becausedeps()drops=> not foundlines (right for copying, wrong for judging completeness).No apt packages have to be removed for this one, so it has no blind spot.
MANIFEST.txtmust bein it and the
lib/entry count must be at least the number of requiredlibraries.
zstd -dc | tar -trather thantar --zstd, because the buildimage's tar is 1.30 and
--zstdarrived in 1.31._assert_payload()rejects a missing or empty archive/manifest, and thecontainer is removed in a
finallyeven when a copy fails.once in Python and injected into the payload;
render_script()raises ifany
__PLACEHOLDER__survives, and a test compares the tag and the librarylist against their
esp_qemu*.rscounterparts.Tests
ci/test_build_qemu_linux_runtime.py(31 tests) covers the fix three ways:dockeronPATH-- argv(
--platform linux/arm64for aarch64), the payload that actually reaches thecontainer, container cleanup, a failed run, a missing artifact, an empty
archive, an empty manifest, and
main()'s printed SHA-256 checked againstthe bytes on disk;
closure-logicmarkers in the rendered payload is extracted and run underset -euo pipefailagainst a stubbedldd, covering a complete closure,glibc/loader exclusion, a gap behind a bundled library, an unsettled walk, a
walk exactly at the cap (every real library links libc), and an unreadable
ELF;
bash -non therendered payload and a check that the README does not document a different
build image than the code uses.
Real output
RED proven by five in-place mutations, each restored afterwards: the silent
round cap (1 failure),
needed()readingnot foundas a soname (1), dropping_assert_payload(2), lettingverify_closurecount glibc deps (3), anddropping the glibc filter from the walk frontier (1 -- the cap test, because a
real library's libc dependency would otherwise eat a round).
Verified against the real container
Not just the fakes: the hardened builder was run for real
(
docker run ubuntu:20.04, real Espressif QEMU tarballs, realldd):43 libraries,
verify_closure()clean, archive inspection clean, bothemulators starting from the bundle after the three removable apt packages were
stripped. The tightening does not false-RED the published path.
Ratchet
[scripts.build_qemu_linux_runtime].testsdeclared,untestedemptied,MAX_UNTESTED1 -> 0 inci/test_gate_script_coverage.py, registered in bothentry points (
ci/local_suites.pyand theci-workflow-drift.ymlunittestcommand). The README bullet also said the bundle is built on
ubuntu:22.04;the code has always used
ubuntu:20.04(and must, for the 2.30 glibc floor),so the doc is corrected and a test now asserts the two agree.