From 3466b61c58ecec65dc62090832ab9f460a040d58 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Sat, 3 Oct 2026 12:49:34 +0800 Subject: [PATCH] =?UTF-8?q?test(zlib):=20=E5=90=AF=E7=94=A8=20test=5Fhuffm?= =?UTF-8?q?an=5Ftree=EF=BC=88=E5=89=8D=E7=BD=AE=E5=88=B0=E5=B9=B2=E5=87=80?= =?UTF-8?q?=E5=A0=86=EF=BC=89=E5=B9=B6=E8=A1=A5=20257=20=E7=AC=A6=E5=8F=B7?= =?UTF-8?q?=E5=85=A8=E9=87=8F=E5=BE=80=E8=BF=94=EF=BC=8C=E5=A4=8D=E7=8E=B0?= =?UTF-8?q?=E7=A0=81=E8=A1=A8=E6=9E=84=E5=BB=BA=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZlibTest/App/test_pyzlib.vp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/ZlibTest/App/test_pyzlib.vp b/ZlibTest/App/test_pyzlib.vp index 9dccf3e..ea2ab0c 100644 --- a/ZlibTest/App/test_pyzlib.vp +++ b/ZlibTest/App/test_pyzlib.vp @@ -761,6 +761,29 @@ def test_huffman_tree(): stdlib.free(w.buf) + # 全量 257 符号往返:ZlibDbg 随机数据的失败只在"多符号码表"场景出现, + # 上面 4 符号抽样覆盖不到——这里把 0..256 全部编码再解码逐一比对, + # 与 ZlibDbg 的失败形态(码表把部分符号编成无码位/错码位)直接对齐。 + w2 = zdef.zbit_writer(None) + for i in range(257): + of_tree.encode_symbol(i, c.Addr(w2)) + + r2 = zdef.zbit_reader() + r2.buf = w2.buf + r2.length = w2.byte_pos + (1 if (w2.bit_pos > 0) else 0) + r2.byte_pos = 0 + r2.bit_pos = 0 + + full_ok: t.CInt = 1 + for i in range(257): + got: t.CInt = dt.decode_symbol(c.Addr(r2)) + if got != i: + full_ok = 0 + printf(" FULL ROUNDTRIP MISMATCH at %d: got %d\n", i, got) + break + check("257-symbol full encode/decode roundtrip", full_ok, "full roundtrip failed") + stdlib.free(w2.buf) + printf("\n --- Kraft inequality check ---\n") kf_freqs: t.CArray[t.CInt, 256] @@ -851,6 +874,11 @@ def main123456() -> t.CInt: printf(" Python zlib - C Implementation Tests\n") printf("==============================================\n") + # Huffman 树/码表构建前置:此前以 "skip: heap corruption from earlier tests" + # 跳过——排在其它用例之后时,前面用例造成的堆破坏会让本用例崩溃,从而掩盖 + # 它自己的结论。前置后可在干净堆上独立复现(ZlibDbg 随机数据 roundtrip 失败 + # 已定位到"多符号码表构建"这一层,本用例是当前最小复现入口)。 + test_huffman_tree() test_constants() test_version() test_compress_decompress() @@ -867,7 +895,7 @@ def main123456() -> t.CInt: test_gzip_format() test_raw_deflate() test_zdict() - # test_huffman_tree() # skip: heap corruption from earlier tests + # test_huffman_tree() # 已前置到 main123456 开头(理由见该处注释) test_error_handling() printf("\n==============================================\n")