把 Test/ 纳入 https://git.gvsds.com/GVSDS/Viper_RegressionTesting 。 1) 新增 .gitignore —— 只保留测试源码,剔除全部构建产物: 目录 **/output*/(output / output_opt / output_orig / output_verify / output_dbg)、 **/temp*/(temp / temp_opt)、**/.tpv_build/ 二进制 *.exe *.obj *.o *.out *.a *.lib *.dll 中间物 *.ll *.vpi *.pyi *.deps.txt *.deps.json *.doc.json *_sha1_map.txt _pyi_cache_v1.pkl _pyi_cache_v1.sig.json _shared_sym.json _phase1_manifest.json 其它 build_all.txt(构建日志)、*.log、__pycache__/、*.bak、IDE 目录 保留 App/*.vp、project.json / project_opt.json / project.vpj、README.md、两个 .py 实测 `git add -A --dry-run`:196 个文件,无任何构建产物混入。 2) TestsOverview.md → README.md(作为仓库首页文档)。 3) SequentialRegressionTest.py:7 处 TestsOverview.md 引用同步改为 README.md (文档串、OVERVIEW 路径、read_test_order 文档与报错文案、argparse description、 启动横幅);同时修正入口路径 PROJECTRANS —— 旧值 <root>/Projectrans.py 已不存在, 改为 <root>/TransPyC/Projectrans.py(与 regression_test.py:45-48 记录一致), 否则本脚本会以 "can't open file" 全量失败。 regression_test.py 无需改动:它按目录扫描 project.json 找项目,不引用该文档。
124 lines
3.7 KiB
Plaintext
124 lines
3.7 KiB
Plaintext
import t, c
|
|
import stdio
|
|
import stdlib
|
|
import string
|
|
import testcheck
|
|
import hashlib
|
|
import binascii
|
|
import base64
|
|
import w32.win32console
|
|
|
|
|
|
# ==============================================
|
|
# 工具函数:打印十六进制哈希串
|
|
# ==============================================
|
|
def print_hex(buf: t.CUInt8T | t.CPtr, length: t.CInt):
|
|
for i in range(length):
|
|
stdio.printf("%02x", buf[i])
|
|
stdio.printf("\n")
|
|
|
|
|
|
def default_value_test_function(a: t.CInt, b: t.CInt = 1):
|
|
print(a, b)
|
|
|
|
|
|
def main() -> t.CInt | t.CExport:
|
|
w32.win32console.SetConsoleCP(65001)
|
|
w32.win32console.SetConsoleOutputCP(65001)
|
|
|
|
testcheck.begin("HashLibTest: 哈希与校验测试")
|
|
|
|
# ---------- hashlib 摘要测试 ----------
|
|
testcheck.section("HASHLIB")
|
|
plain: str = "hello123"
|
|
|
|
md5_buf: t.CArray[t.CUInt8T, hashlib.MD5_DIGEST_LEN]
|
|
mctx = hashlib.md5()
|
|
mctx.update(plain)
|
|
mctx.final(md5_buf)
|
|
print("MD5: ")
|
|
print_hex(md5_buf, hashlib.MD5_DIGEST_LEN)
|
|
testcheck.ok("HASHLIB md5 completed")
|
|
|
|
sha1_buf: t.CArray[t.CUInt8T, hashlib.SHA1_DIGEST_LEN]
|
|
s1ctx = hashlib.sha1()
|
|
s1ctx.update(plain)
|
|
s1ctx.final(sha1_buf)
|
|
print("SHA1: ")
|
|
print_hex(sha1_buf, hashlib.SHA1_DIGEST_LEN)
|
|
testcheck.ok("HASHLIB sha1 completed")
|
|
|
|
sha256_buf: t.CArray[t.CUInt8T, hashlib.SHA256_DIGEST_LEN]
|
|
s2ctx = hashlib.sha256()
|
|
s2ctx.update(plain)
|
|
s2ctx.final(sha256_buf)
|
|
print("SHA256: ")
|
|
print_hex(sha256_buf, hashlib.SHA256_DIGEST_LEN)
|
|
testcheck.ok("HASHLIB sha256 completed")
|
|
|
|
sha512_buf: t.CArray[t.CUInt8T, hashlib.SHA512_DIGEST_LEN]
|
|
s5ctx = hashlib.sha512()
|
|
s5ctx.update(plain)
|
|
s5ctx.final(sha512_buf)
|
|
print("SHA512: ")
|
|
print_hex(sha512_buf, hashlib.SHA512_DIGEST_LEN)
|
|
testcheck.ok("HASHLIB sha512 completed")
|
|
|
|
default_value_test_function(b=2, a=1)
|
|
testcheck.ok("default value test completed")
|
|
|
|
# ---------- base64 编解码测试 ----------
|
|
testcheck.section("BASE64")
|
|
b64_out: t.CArray[t.CChar, 256]
|
|
b64_dec: t.CArray[t.CUInt8T, 256]
|
|
base64.b64encode(plain, b64_out)
|
|
print("Base64 编码:", b64_out)
|
|
dlen: t.CSizeT = base64.b64decode(b64_out, b64_dec)
|
|
b64_dec[dlen] = 0
|
|
print("Base64 解码:", b64_dec)
|
|
testcheck.ok("BASE64 encode/decode completed")
|
|
|
|
# ---------- binascii 全套测试 ----------
|
|
testcheck.section("BINASCII")
|
|
binascii.init_binascii()
|
|
raw: str = "HelloWorld!"
|
|
raw_length: t.CInt = 11
|
|
|
|
hex_out: str = binascii.b2a_hex(raw, raw_length)
|
|
if hex_out:
|
|
stdio.printf("Hex: %s\n", hex_out)
|
|
stdlib.free(hex_out)
|
|
testcheck.ok("BINASCII b2a_hex completed")
|
|
|
|
crc_val: t.CUnsignedInt = binascii.crc32(raw, raw_length, 0)
|
|
stdio.printf("CRC32: %u\n", crc_val)
|
|
testcheck.ok("BINASCII crc32 completed")
|
|
|
|
b64_out2: str = binascii.b2a_base64(raw, raw_length)
|
|
if b64_out2:
|
|
stdio.printf("Base64: %s\n", b64_out2)
|
|
stdlib.free(b64_out2)
|
|
testcheck.ok("BINASCII b2a_base64 completed")
|
|
|
|
uu_out: str = binascii.b2a_uu(raw, raw_length)
|
|
if uu_out:
|
|
stdio.printf("UU: %s\n", uu_out)
|
|
stdlib.free(uu_out)
|
|
testcheck.ok("BINASCII b2a_uu completed")
|
|
|
|
hqx_in: t.CArray[t.CChar, 4] = ['A', 'B', 'C', '\0']
|
|
hqx_crc: t.CUnsignedShort = 0
|
|
hqx_out: str
|
|
unhqx: str
|
|
hqx_out, hqx_crc = binascii.b2a_hqx(hqx_in, 3)
|
|
unhqx, hqx_crc = binascii.a2b_hqx(hqx_out)
|
|
stdio.printf("HQX Test: ABC -> %s -> %s (CRC:%u)\n", hqx_out, unhqx, hqx_crc)
|
|
stdlib.free(hqx_out); stdlib.free(unhqx)
|
|
testcheck.ok("BINASCII hqx completed")
|
|
|
|
adler_val: t.CUnsignedInt = binascii.adler32(raw, raw_length, 1)
|
|
stdio.printf("Adler32: %u\n", adler_val)
|
|
testcheck.ok("BINASCII adler32 completed")
|
|
|
|
return testcheck.end()
|