把 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 找项目,不引用该文档。
185 lines
6.7 KiB
Plaintext
185 lines
6.7 KiB
Plaintext
from stdint import *
|
|
import t, c
|
|
import stdio
|
|
import testcheck
|
|
import string
|
|
import viperlib
|
|
import w32.win32console
|
|
|
|
# ============================================================
|
|
# VariadicTest - 测试 snprintf/printf variadic 参数传递
|
|
# ============================================================
|
|
|
|
# --- Test 1: %u 格式化小整数 (CUInt8T -> CUnsignedInt) ---
|
|
def test_snprintf_u8():
|
|
"""测试 CUInt8T 值通过 t.CUnsignedInt() 传递给 %u"""
|
|
testcheck.section("Test 1: %u 格式化小整数 (CUInt8T -> CUnsignedInt)")
|
|
hr: t.CUInt8T = 14
|
|
mn: t.CUInt8T = 30
|
|
sc: t.CUInt8T = 59
|
|
buf: t.CArray[t.CChar, 64]
|
|
string.memset(c.Addr(buf), 0, 64)
|
|
viperlib.snprintf(c.Addr(buf), 64, "%02u:%02u:%02u", t.CUnsignedInt(hr), t.CUnsignedInt(mn), t.CUnsignedInt(sc))
|
|
stdio.printf("Test1 (CUInt8T->%%u): [%s] (expect 14:30:59)\n", c.Addr(buf))
|
|
testcheck.ok("CUInt8T -> %u (expect 14:30:59)")
|
|
|
|
|
|
# --- Test 2: %u 格式化 CUInt16T ---
|
|
def test_snprintf_u16():
|
|
"""测试 CUInt16T 值通过 t.CUnsignedInt() 传递给 %u"""
|
|
testcheck.section("Test 2: %u 格式化 CUInt16T")
|
|
yr: t.CUInt16T = 2026
|
|
buf: t.CArray[t.CChar, 64]
|
|
string.memset(c.Addr(buf), 0, 64)
|
|
viperlib.snprintf(c.Addr(buf), 64, "%04u", t.CUnsignedInt(yr))
|
|
stdio.printf("Test2 (CUInt16T->%%u): [%s] (expect 2026)\n", c.Addr(buf))
|
|
testcheck.ok("CUInt16T -> %u (expect 2026)")
|
|
|
|
|
|
# --- Test 3: %lu 格式化 CUInt64T ---
|
|
def test_snprintf_u64():
|
|
"""测试 CUInt64T 值传递给 %lu"""
|
|
testcheck.section("Test 3: %lu 格式化 CUInt64T")
|
|
val: t.CUInt64T = 1234567890123
|
|
buf: t.CArray[t.CChar, 64]
|
|
string.memset(c.Addr(buf), 0, 64)
|
|
viperlib.snprintf(c.Addr(buf), 64, "%lu", val)
|
|
stdio.printf("Test3 (CUInt64T->%%lu): [%s] (expect 1234567890123)\n", c.Addr(buf))
|
|
testcheck.ok("CUInt64T -> %lu (expect 1234567890123)")
|
|
|
|
|
|
# --- Test 4: %d 格式化负数 ---
|
|
def test_snprintf_d_neg():
|
|
"""测试 %d 格式化负整数"""
|
|
testcheck.section("Test 4: %d 格式化负数")
|
|
val: t.CInt = -42
|
|
buf: t.CArray[t.CChar, 64]
|
|
string.memset(c.Addr(buf), 0, 64)
|
|
viperlib.snprintf(c.Addr(buf), 64, "%d", val)
|
|
stdio.printf("Test4 (CInt->%%d neg): [%s] (expect -42)\n", c.Addr(buf))
|
|
testcheck.ok("CInt -> %d neg (expect -42)")
|
|
|
|
|
|
# --- Test 5: %d 格式化正数 ---
|
|
def test_snprintf_d_pos():
|
|
testcheck.section("Test 5: %d 格式化正数")
|
|
val: t.CInt = 42
|
|
buf: t.CArray[t.CChar, 64]
|
|
string.memset(c.Addr(buf), 0, 64)
|
|
viperlib.snprintf(c.Addr(buf), 64, "%d", val)
|
|
stdio.printf("Test5 (CInt->%%d pos): [%s] (expect 42)\n", c.Addr(buf))
|
|
testcheck.ok("CInt -> %d pos (expect 42)")
|
|
|
|
|
|
# --- Test 6: %x 格式化十六进制 ---
|
|
def test_snprintf_x():
|
|
testcheck.section("Test 6: %x 格式化十六进制")
|
|
val: t.CUInt32T = 0xDEADBEEF
|
|
buf: t.CArray[t.CChar, 64]
|
|
string.memset(c.Addr(buf), 0, 64)
|
|
viperlib.snprintf(c.Addr(buf), 64, "0x%08x", val)
|
|
stdio.printf("Test6 (%%x): [%s] (expect 0xdeadbeef)\n", c.Addr(buf))
|
|
testcheck.ok("%x hex (expect 0xdeadbeef)")
|
|
|
|
|
|
# --- Test 7: 混合格式化 (模拟 desktop.py 时间格式) ---
|
|
def test_snprintf_mixed():
|
|
"""模拟 desktop.py 的时间格式化"""
|
|
testcheck.section("Test 7: 混合格式化 (模拟 desktop.py 时间格式)")
|
|
hr: t.CUInt8T = 14
|
|
mn: t.CUInt8T = 5
|
|
sc: t.CUInt8T = 9
|
|
day: t.CUInt8T = 14
|
|
mon: t.CUInt8T = 6
|
|
yr: t.CUInt16T = 2026
|
|
buf: t.CArray[t.CChar, 64]
|
|
string.memset(c.Addr(buf), 0, 64)
|
|
viperlib.snprintf(c.Addr(buf), 64, "%04u-%02u-%02u %02u:%02u:%02u",
|
|
t.CUnsignedInt(yr), t.CUnsignedInt(mon), t.CUnsignedInt(day),
|
|
t.CUnsignedInt(hr), t.CUnsignedInt(mn), t.CUnsignedInt(sc))
|
|
stdio.printf("Test7 (time format): [%s] (expect 2026-06-14 14:05:09)\n", c.Addr(buf))
|
|
testcheck.ok("time format (expect 2026-06-14 14:05:09)")
|
|
|
|
|
|
# --- Test 8: printf 直接输出 variadic ---
|
|
def test_printf_variadic():
|
|
"""测试 printf 直接输出 variadic 参数"""
|
|
testcheck.section("Test 8: printf 直接输出 variadic")
|
|
stdio.printf("Test8 (printf direct): %u %d %lu 0x%x (expect 100 -50 999999999 0xcafe)\n",
|
|
t.CUnsignedInt(100), -50, t.CUInt64T(999999999), 0xCAFE)
|
|
testcheck.ok("printf direct variadic (expect 100 -50 999999999 0xcafe)")
|
|
|
|
|
|
# --- Test 9: 多个 %lu 连续 ---
|
|
def test_snprintf_multi_lu():
|
|
"""测试多个 %lu 连续(模拟 perf 日志格式)"""
|
|
testcheck.section("Test 9: 多个 %lu 连续")
|
|
v1: t.CUInt64T = 16
|
|
v2: t.CUInt64T = 2
|
|
v3: t.CUInt64T = 11
|
|
buf: t.CArray[t.CChar, 128]
|
|
string.memset(c.Addr(buf), 0, 128)
|
|
viperlib.snprintf(c.Addr(buf), 128, "wall=%lu work=%lu render=%lu", v1, v2, v3)
|
|
stdio.printf("Test9 (multi %%lu): [%s] (expect wall=16 work=2 render=11)\n", c.Addr(buf))
|
|
testcheck.ok("multi %lu (expect wall=16 work=2 render=11)")
|
|
|
|
|
|
# --- Test 10: %u 格式化 0 ---
|
|
def test_snprintf_zero():
|
|
testcheck.section("Test 10: %u 格式化 0")
|
|
val: t.CUInt32T = 0
|
|
buf: t.CArray[t.CChar, 64]
|
|
string.memset(c.Addr(buf), 0, 64)
|
|
viperlib.snprintf(c.Addr(buf), 64, "%u", val)
|
|
stdio.printf("Test10 (%%u zero): [%s] (expect 0)\n", c.Addr(buf))
|
|
testcheck.ok("%u zero (expect 0)")
|
|
|
|
|
|
# --- Test 11: %u 格式化大值 ---
|
|
def test_snprintf_large():
|
|
testcheck.section("Test 11: %u 格式化大值")
|
|
val: t.CUInt32T = 4294967295 # 0xFFFFFFFF
|
|
buf: t.CArray[t.CChar, 64]
|
|
string.memset(c.Addr(buf), 0, 64)
|
|
viperlib.snprintf(c.Addr(buf), 64, "%u", val)
|
|
stdio.printf("Test11 (%%u max): [%s] (expect 4294967295)\n", c.Addr(buf))
|
|
testcheck.ok("%u max (expect 4294967295)")
|
|
|
|
|
|
# --- Test 12: CUnsignedInt cast from CUInt8T edge values ---
|
|
def test_snprintf_u8_edge():
|
|
"""测试 CUInt8T 边界值"""
|
|
testcheck.section("Test 12: CUnsignedInt cast from CUInt8T edge values")
|
|
v0: t.CUInt8T = 0
|
|
v127: t.CUInt8T = 127
|
|
v128: t.CUInt8T = 128
|
|
v255: t.CUInt8T = 255
|
|
buf: t.CArray[t.CChar, 64]
|
|
string.memset(c.Addr(buf), 0, 64)
|
|
viperlib.snprintf(c.Addr(buf), 64, "%u %u %u %u",
|
|
t.CUnsignedInt(v0), t.CUnsignedInt(v127), t.CUnsignedInt(v128), t.CUnsignedInt(v255))
|
|
stdio.printf("Test12 (CUInt8T edge): [%s] (expect 0 127 128 255)\n", c.Addr(buf))
|
|
testcheck.ok("CUInt8T edge (expect 0 127 128 255)")
|
|
|
|
|
|
def main() -> t.CInt | t.CExport:
|
|
w32.win32console.SetConsoleCP(65001)
|
|
w32.win32console.SetConsoleOutputCP(65001)
|
|
|
|
testcheck.begin("VariadicTest: snprintf/printf variadic 参数测试")
|
|
|
|
test_snprintf_u8()
|
|
test_snprintf_u16()
|
|
test_snprintf_u64()
|
|
test_snprintf_d_neg()
|
|
test_snprintf_d_pos()
|
|
test_snprintf_x()
|
|
test_snprintf_mixed()
|
|
test_printf_variadic()
|
|
test_snprintf_multi_lu()
|
|
test_snprintf_zero()
|
|
test_snprintf_large()
|
|
test_snprintf_u8_edge()
|
|
|
|
return testcheck.end()
|