The gzip, lz4, and zstd branches of image_decomp_get_uncompressed_size()
are exercised end-to-end by test/py/tests/test_fit.py's
kernel_noload_decomp_*_hdr_sized cases. The lzma branch cannot be
reached that way: standard Ubuntu ships xz-utils' lzma shim (as does
Python's lzma.FORMAT_ALONE), and both always write the header's 8-byte
uncompressed-size field as the "unknown" marker 0xff..ff, so a
runtime-generated stream would only ever exercise the -EOPNOTSUPP
fallback path.
Add a hand-crafted lzma_with_size_compressed blob built with the
standalone lzma-alone tool (whose header carries the real size) and a
new unit test compression_test_image_decomp_lzma that asserts:
- the existing lzma_compressed blob (unknown-size marker) returns
-EOPNOTSUPP so bootm falls back to its 8x heuristic;
- the new lzma_with_size_compressed blob returns strlen(plain) so
bootm can pre-size the noload decompression buffer.
Signed-off-by: Aristo Chen <[email protected]>
---
test/lib/compression.c | 66 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
diff --git a/test/lib/compression.c b/test/lib/compression.c
index 31b6e5b1eb4..930cd542294 100644
--- a/test/lib/compression.c
+++ b/test/lib/compression.c
@@ -74,6 +74,31 @@ static const char lzma_compressed[] =
"\xfd\xf5\x50\x8d\xca";
static const unsigned long lzma_compressed_size = sizeof(lzma_compressed) - 1;
+/*
+ * lzma -kf plain.txt (standalone lzma-alone tool, not the xz-utils shim)
+ * The 8-byte uncompressed-size field at offset 5 holds strlen(plain) rather
+ * than the 0xff..ff "unknown" marker written by xz-utils and Python's
+ * lzma.FORMAT_ALONE. Used to exercise the size-parsing branch of
+ * image_decomp_get_uncompressed_size() for lzma streams.
+ */
+static const char lzma_with_size_compressed[] =
+ "\x5d\x00\x00\x80\x00\x5e\x01\x00\x00\x00\x00\x00\x00\x00\x24\x88"
+ "\x08\x26\xd8\x41\xff\x99\xc8\xcf\x66\x3d\x80\xac\xba\x17\xf1\xc8"
+ "\xb9\xdf\x49\x37\xb1\x68\xa0\x2a\xdd\x63\xd1\xa7\xa3\x66\xf8\x15"
+ "\xef\xa6\x67\x8a\x14\x18\x80\xcb\xc7\xb1\xcb\x84\x6a\xb2\x51\x16"
+ "\xa1\x45\xa0\xd6\x3e\x55\x44\x8a\x5c\xa0\x7c\xe5\xa8\xbd\x04\x57"
+ "\x8f\x24\xfd\xb9\x34\x50\x83\x2f\xf3\x46\x3e\xb9\xb0\x00\x1a\xf5"
+ "\xd3\x86\x7e\x8f\x77\xd1\x5d\x0e\x7c\xe1\xac\xde\xf8\x65\x1f\x4d"
+ "\xce\x7f\xa7\x3d\xaa\xcf\x26\xa7\x58\x69\x1e\x4c\xea\x68\x8a\xe5"
+ "\x89\xd1\xdc\x4d\xc7\xe0\x07\x42\xbf\x0c\x9d\x06\xd7\x51\xa2\x0b"
+ "\x7c\x83\x35\xe1\x85\xdf\xee\xfb\xa3\xee\x2f\x47\x5f\x8b\x70\x2b"
+ "\xe1\x37\xf3\x16\xf6\x27\x54\x8a\x33\x72\x49\xea\x53\x7d\x60\x0b"
+ "\x21\x90\x66\xe7\x9e\x56\x61\x5d\xd8\xdc\x59\xf0\xac\x2f\xd6\x49"
+ "\x6b\x85\x40\x08\x1f\xdf\x26\x25\x3b\x72\x44\xb0\xb8\x21\x2f\xb3"
+ "\xd7\x9b\x24\x30\x78\x26\x44\x07\xc3\x33\xd1\x4c\xe1\x05\x55\x6d";
+static const unsigned long lzma_with_size_compressed_size =
+ sizeof(lzma_with_size_compressed) - 1;
+
/* lzop -c /tmp/plain.txt > /tmp/plain.lzo */
static const char lzo_compressed[] =
"\x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a\x10\x30\x20\x60\x09\x40\x01"
@@ -606,3 +631,44 @@ static int compression_test_bootm_none(struct
unit_test_state *uts)
return run_bootm_test(uts, IH_COMP_NONE, compress_using_none);
}
LIB_TEST(compression_test_bootm_none, 0);
+
+/*
+ * image_decomp_get_uncompressed_size() has a dedicated code path per
+ * format. gzip, lz4 with --content-size, and zstd are covered end-to-end
+ * by test/py/tests/test_fit.py's kernel_noload_decomp_*_hdr_sized cases.
+ * The lzma path is exercised here instead: standard Ubuntu ships xz-utils'
+ * lzma shim (as does Python's lzma.FORMAT_ALONE), and both always write
+ * the header size as "unknown" (0xff..ff), so a runtime-generated stream
+ * cannot reach the size-parsing branch. A hand-crafted static blob is the
+ * only portable way to cover it.
+ */
+static int compression_test_image_decomp_lzma(struct unit_test_state *uts)
+{
+ ulong sz;
+
+ /*
+ * The existing lzma_compressed blob was made with the xz-utils
+ * shim and carries the 0xff..ff "unknown" size marker. Bootm must
+ * decline to size the buffer from that.
+ */
+ ut_asserteq(-EOPNOTSUPP,
+ image_decomp_get_uncompressed_size(IH_COMP_LZMA,
+ lzma_compressed,
+ lzma_compressed_size,
+ &sz));
+
+ /*
+ * The lzma_with_size_compressed blob was made with the standalone
+ * lzma-alone tool and carries the real size in the header. Bootm
+ * must return that size so the noload path can pre-size its buffer.
+ */
+ sz = 0;
+ ut_assertok(image_decomp_get_uncompressed_size(IH_COMP_LZMA,
+
lzma_with_size_compressed,
+
lzma_with_size_compressed_size,
+ &sz));
+ ut_asserteq(strlen(plain), sz);
+
+ return 0;
+}
+LIB_TEST(compression_test_image_decomp_lzma, 0);
--
2.43.0