From: Aristo Chen <aristo.chen@canonical.com>
To: u-boot@lists.u-boot-project.org
Cc: sjg@chromium.org, nora.schiffer@ew.tq-group.com,
Aristo Chen <aristo.chen@canonical.com>,
Tom Rini <trini@konsulko.com>
Subject: [PATCH v2 8/8] test: fit: cover the kernel_noload lzma header-size and unknown-size paths
Date: Tue, 18 Aug 2026 13:23:22 +0000 [thread overview]
Message-ID: <20260818132332.324173-9-aristo.chen@canonical.com> (raw)
In-Reply-To: <20260818132332.324173-1-aristo.chen@canonical.com>
Exercise bootm_lzma_uncompressed_size() end-to-end on sandbox:
- test_fit_kernel_noload_decomp_lzma_hdr_sized boots a 6 MiB
kernel_noload payload that lzma compresses far past the 8x fallback
heuristic, so the boot only succeeds when bootm sizes the buffer
from the header's uncompressed-size field. Streaming encoders write
the "unknown" marker into that field, so the test compresses with
Python's lzma module and patches the real size into the fixed
8-byte field, matching what LZMA SDK style encoders record.
- test_fit_kernel_noload_decomp_lzma_unknown_size leaves the marker in
place and checks that bootm falls back to the 8x heuristic buffer
and still boots the image.
No external tool is required: Python's lzma module is part of the
standard library.
Signed-off-by: Aristo Chen <aristo.chen@canonical.com>
---
test/py/tests/test_fit.py | 98 +++++++++++++++++++++++++++++++++++++++
1 file changed, 98 insertions(+)
diff --git a/test/py/tests/test_fit.py b/test/py/tests/test_fit.py
index 42edddb0600..0edf875a9e1 100755
--- a/test/py/tests/test_fit.py
+++ b/test/py/tests/test_fit.py
@@ -704,6 +704,104 @@ class TestFitImage:
'bootm rejected a well-compressed zstd kernel_noload image whose '
'frame header records the real content size: %s' % text)
+ @pytest.mark.buildconfigspec('lzma')
+ def test_fit_kernel_noload_decomp_lzma_hdr_sized(self, ubman, fsetup):
+ """A well-compressed lzma kernel_noload image fits when the header
+ records the real uncompressed size.
+
+ Same as test_fit_kernel_noload_decomp_gzip_hdr_sized but for lzma.
+ Streaming encoders write the "unknown" marker into the .lzma-alone
+ size field, so compress with Python's lzma module and patch the
+ real size into the fixed 8-byte header field, the way LZMA SDK
+ style encoders record it.
+ """
+ lzma = pytest.importorskip('lzma')
+ sz_1m = 1 << 20
+ bootm_len = int(ubman.config.buildconfig['config_sys_bootm_len'], 0)
+
+ decomp_size = 6 * sz_1m
+ assert decomp_size <= bootm_len, (
+ 'Test setup error: decomp_size (%#x) must be <= '
+ 'CONFIG_SYS_BOOTM_LEN (%#x)' % (decomp_size, bootm_len))
+ kernel = fit_util.make_fname(ubman, 'test-noload-kernel-lzma.bin')
+ with open(kernel, 'wb') as fd:
+ fd.write(b'\0' * decomp_size)
+ filters = [{'id': lzma.FILTER_LZMA1, 'preset': 6,
+ 'dict_size': 1 << 20}]
+ blob = lzma.compress(self.read_file(kernel),
+ format=lzma.FORMAT_ALONE, filters=filters)
+ assert blob[5:13] == b'\xff' * 8, (
+ 'Test setup error: expected the streaming encoder to write the '
+ '"unknown" size marker')
+ blob = blob[:5] + decomp_size.to_bytes(8, 'little') + blob[13:]
+ kernel_lzma = kernel + '.lzma'
+ with open(kernel_lzma, 'wb') as fd:
+ fd.write(blob)
+
+ image_len = self.filesize(kernel_lzma)
+ heuristic_bound = (image_len * 8 + sz_1m - 1) // sz_1m * sz_1m
+ assert heuristic_bound < decomp_size, (
+ 'Test setup error: 8x heuristic bound (%#x) must be < uncompressed '
+ 'size (%#x); if this fires, lzma got less effective and the test '
+ 'needs a bigger payload' % (heuristic_bound, decomp_size))
+
+ fit = fit_util.make_fit(ubman, fsetup['mkimage'], NOLOAD_ITS,
+ {'kernel': kernel_lzma, 'compression': 'lzma'},
+ basename='test-noload-lzma-hdrsized.fit')
+ fit_addr = fsetup['fit_addr']
+
+ output = ubman.run_command_list([
+ 'host load hostfs 0 %x %s' % (fit_addr, fit),
+ 'bootm start %x' % fit_addr,
+ 'bootm loados',
+ ])
+ text = '\n'.join(output)
+ assert 'Image too large' not in text, (
+ 'bootm rejected a well-compressed lzma kernel_noload image whose '
+ 'header records the real uncompressed size: %s' % text)
+
+ @pytest.mark.buildconfigspec('lzma')
+ def test_fit_kernel_noload_decomp_lzma_unknown_size(self, ubman, fsetup):
+ """An lzma stream with the "unknown" size marker falls back cleanly
+
+ Streaming encoders write 0xff..ff into the .lzma-alone size field.
+ bootm must fall back to the 8x heuristic buffer and still boot the
+ image.
+ """
+ lzma = pytest.importorskip('lzma')
+ sz_1m = 1 << 20
+
+ # Incompressible data keeps the real size well inside the 8x
+ # fallback buffer.
+ payload = os.urandom(sz_1m)
+ kernel = fit_util.make_fname(ubman, 'test-noload-kernel-lzma-unk.bin')
+ filters = [{'id': lzma.FILTER_LZMA1, 'preset': 6,
+ 'dict_size': 1 << 20}]
+ blob = lzma.compress(payload, format=lzma.FORMAT_ALONE,
+ filters=filters)
+ assert blob[5:13] == b'\xff' * 8, (
+ 'Test setup error: expected the streaming encoder to write the '
+ '"unknown" size marker')
+ kernel_lzma = kernel + '.lzma'
+ with open(kernel_lzma, 'wb') as fd:
+ fd.write(blob)
+
+ fit = fit_util.make_fit(ubman, fsetup['mkimage'], NOLOAD_ITS,
+ {'kernel': kernel_lzma, 'compression': 'lzma'},
+ basename='test-noload-lzma-unk.fit')
+ fit_addr = fsetup['fit_addr']
+
+ output = ubman.run_command_list([
+ 'host load hostfs 0 %x %s' % (fit_addr, fit),
+ 'bootm start %x' % fit_addr,
+ 'bootm loados',
+ ])
+ text = '\n'.join(output)
+ assert 'Image too large' not in text, (
+ 'bootm rejected an lzma kernel_noload image carrying the '
+ '"unknown" size marker; the 8x fallback should have covered '
+ 'it: %s' % text)
+
@pytest.mark.buildconfigspec('gzip')
def test_fit_kernel_noload_decomp_gzip_boundary(self, ubman, fsetup):
"""Test that decompression succeeds exactly at the buffer limit
--
2.43.0
next prev parent reply other threads:[~2026-08-18 13:51 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-09 4:23 [PATCH 0/3] bootm: size the noload buffer from the compressor header Aristo Chen via U-Boot
2026-08-09 4:23 ` [PATCH 1/3] bootm: size the noload decompression " Aristo Chen via U-Boot
2026-08-09 15:27 ` Tom Rini
2026-08-10 2:32 ` Aristo Chen via U-Boot
2026-08-10 16:37 ` Tom Rini
2026-08-12 7:45 ` Nora Schiffer
2026-08-12 15:57 ` Tom Rini
2026-08-15 18:33 ` Simon Glass
2026-08-17 16:01 ` Aristo Chen via U-Boot
2026-08-17 19:24 ` Tom Rini
2026-08-09 4:23 ` [PATCH 2/3] test: fit: cover the kernel_noload header-size and lying-header paths Aristo Chen via U-Boot
2026-08-09 4:23 ` [PATCH 3/3] test: lib: cover image_decomp_get_uncompressed_size() for lzma streams Aristo Chen via U-Boot
2026-08-18 13:23 ` [PATCH v2 0/8] bootm: size the noload buffer from the compressor header Aristo Chen
2026-08-18 13:23 ` [PATCH v2 1/8] bootm: size the noload gzip decompression buffer from ISIZE Aristo Chen
2026-08-18 13:23 ` [PATCH v2 2/8] test: fit: cover the kernel_noload gzip header-size and lying-header paths Aristo Chen
2026-08-18 13:23 ` [PATCH v2 3/8] bootm: size the noload zstd decompression buffer from Frame_Content_Size Aristo Chen
2026-08-18 13:23 ` [PATCH v2 4/8] test: fit: cover the kernel_noload zstd header-size path Aristo Chen
2026-08-18 13:23 ` [PATCH v2 5/8] bootm: size the noload lz4 decompression buffer from Content_Size Aristo Chen
2026-08-18 13:23 ` [PATCH v2 6/8] test: fit: cover the kernel_noload lz4 header-size path Aristo Chen
2026-08-18 13:23 ` [PATCH v2 7/8] bootm: size the noload lzma decompression buffer from the header Aristo Chen
2026-08-18 13:23 ` Aristo Chen [this message]
2026-08-18 22:10 ` [PATCH v2 0/8] bootm: size the noload buffer from the compressor header Tom Rini
2026-08-19 14:53 ` Aristo Chen
2026-08-21 18:55 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260818132332.324173-9-aristo.chen@canonical.com \
--to=aristo.chen@canonical.com \
--cc=nora.schiffer@ew.tq-group.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.