test(zlib-dbg): 输出改用 testcheck(PASS/FAIL 计数 + 退出码取失败数)
This commit is contained in:
1 parent
9fef174f3e
commit
91ebacf36b
1 file changed
+24
-23
+24
-23
@@ -5,8 +5,8 @@ import zlib.zinflate as zinflate
|
||||
import zlib.zdef as zdef
|
||||
import string
|
||||
import stdlib
|
||||
import testcheck
|
||||
import t, c
|
||||
from stdio import printf
|
||||
|
||||
|
||||
def fill_data(data: BYTEPTR, size: t.CSizeT, seed: t.CSizeT, repeating: t.CInt):
|
||||
@@ -26,8 +26,8 @@ def roundtrip(seed: t.CSizeT, size: t.CSizeT, repeating: t.CInt, wbits: t.CInt)
|
||||
comp: BYTEPTR = pyzlib.compress(None, data, size,
|
||||
pyzlib.Z_DEFAULT_COMPRESSION, wbits, c.Addr(out_len))
|
||||
if not comp:
|
||||
printf(" [seed=%zu size=%zu rep=%d wbits=%d] COMPRESS FAILED: %d %s\n",
|
||||
seed, size, repeating, wbits, pyzlib.get_error_code(), pyzlib.get_error())
|
||||
testcheck.fail(f"seed={seed} size={size} rep={repeating} wbits={wbits}: "
|
||||
f"compress 失败 err={pyzlib.get_error_code()} {pyzlib.get_error()}")
|
||||
stdlib.free(data)
|
||||
return -1
|
||||
|
||||
@@ -36,17 +36,17 @@ def roundtrip(seed: t.CSizeT, size: t.CSizeT, repeating: t.CInt, wbits: t.CInt)
|
||||
pyzlib.DEF_BUF_SIZE, c.Addr(dec_len))
|
||||
ok: t.CInt = 1
|
||||
if not dec:
|
||||
printf(" [seed=%zu size=%zu rep=%d wbits=%d] DECOMPRESS FAILED: err=%d msg=%s (comp=%zu bytes)\n",
|
||||
seed, size, repeating, wbits, pyzlib.get_error_code(), pyzlib.get_error(), out_len)
|
||||
ok = 0
|
||||
testcheck.fail(f"seed={seed} size={size} rep={repeating} wbits={wbits}: "
|
||||
f"decompress 失败 comp={out_len} err={pyzlib.get_error_code()} {pyzlib.get_error()}")
|
||||
elif dec_len != size or string.memcmp(dec, data, size) != 0:
|
||||
ok = 0
|
||||
testcheck.fail(f"seed={seed} size={size} rep={repeating} wbits={wbits}: "
|
||||
f"内容不匹配 comp={out_len} dec={dec_len}")
|
||||
else:
|
||||
printf(" [seed=%zu size=%zu rep=%d wbits=%d] comp=%zu dec=%zu ",
|
||||
seed, size, repeating, wbits, out_len, dec_len)
|
||||
if dec_len != size or string.memcmp(dec, data, size) != 0:
|
||||
printf("CONTENT MISMATCH\n")
|
||||
ok = 0
|
||||
else:
|
||||
printf("OK\n")
|
||||
testcheck.ok(f"seed={seed} size={size} rep={repeating} wbits={wbits}: "
|
||||
f"comp={out_len} dec={dec_len}")
|
||||
|
||||
if dec: stdlib.free(dec)
|
||||
stdlib.free(comp)
|
||||
stdlib.free(data)
|
||||
@@ -54,21 +54,22 @@ def roundtrip(seed: t.CSizeT, size: t.CSizeT, repeating: t.CInt, wbits: t.CInt)
|
||||
|
||||
|
||||
def main() -> t.CInt:
|
||||
printf("== zlib roundtrip >256B ==\n")
|
||||
testcheck.begin("ZlibDbg: zlib 多 seed/size/wbits 往返")
|
||||
|
||||
testcheck.section("随机数据 (wbits=15)")
|
||||
sizes: t.CArray[t.CSizeT, None] = [250, 255, 256, 257, 260, 300, 500, 1000, 4096, 20000]
|
||||
n: t.CInt
|
||||
failed: t.CInt = 0
|
||||
for n in range(10):
|
||||
if roundtrip(t.CSizeT(n), sizes[n], 0, pyzlib.MAX_WBITS) != 0: failed = 1
|
||||
printf("-- random data done --\n")
|
||||
roundtrip(t.CSizeT(n), sizes[n], 0, pyzlib.MAX_WBITS)
|
||||
|
||||
testcheck.section("重复数据 (wbits=15)")
|
||||
sizes2: t.CArray[t.CSizeT, None] = [256, 257, 300, 1000, 20000]
|
||||
n = 0
|
||||
for n in range(5):
|
||||
if roundtrip(t.CSizeT(n), sizes2[n], 1, pyzlib.MAX_WBITS) != 0: failed = 1
|
||||
printf("-- repeating data done --\n")
|
||||
roundtrip(t.CSizeT(n), sizes2[n], 1, pyzlib.MAX_WBITS)
|
||||
|
||||
testcheck.section("gzip 容器 (wbits=31)")
|
||||
sizes3: t.CArray[t.CSizeT, None] = [300, 1000]
|
||||
n = 0
|
||||
for n in range(2):
|
||||
if roundtrip(t.CSizeT(n), sizes3[n], 0, pyzlib.MAX_WBITS + 16) != 0: failed = 1
|
||||
printf("-- gzip container done --\n")
|
||||
return 1 if failed else 0
|
||||
roundtrip(t.CSizeT(n), sizes3[n], 0, pyzlib.MAX_WBITS + 16)
|
||||
|
||||
return testcheck.end()
|
||||
Reference in new issue
Block a user