把 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 找项目,不引用该文档。
86 lines
3.1 KiB
Plaintext
86 lines
3.1 KiB
Plaintext
import t
|
|
import stdio
|
|
import string
|
|
import testcheck
|
|
import w32.win32memory
|
|
|
|
def test_strlen():
|
|
testcheck.section("Test 1: strlen")
|
|
s: t.CChar | t.CPtr = "Hello, World!"
|
|
length: t.CUInt64T = string.strlen(s)
|
|
testcheck.check(length == 13, "strlen (len=13)", "strlen (expect 13)")
|
|
|
|
def test_strcpy():
|
|
testcheck.section("Test 2: strcpy")
|
|
buf: t.CChar | t.CPtr = w32.win32memory.VirtualAlloc(None, 64, 12288, 4)
|
|
if t.CUInt64T(buf) == 0:
|
|
stdio.printf("SKIP: VirtualAlloc returned NULL\n")
|
|
return
|
|
string.memset(buf, 0, 64)
|
|
string.strcpy(buf, "test string")
|
|
cmp_result: t.CInt = string.strcmp(buf, "test string")
|
|
testcheck.check(cmp_result == 0, "strcpy (result=test string)", "strcpy (cmp mismatch)")
|
|
|
|
def test_strcat():
|
|
testcheck.section("Test 3: strcat (via memcpy)")
|
|
buf: t.CChar | t.CPtr = w32.win32memory.VirtualAlloc(None, 64, 12288, 4)
|
|
if t.CUInt64T(buf) == 0:
|
|
stdio.printf("SKIP: VirtualAlloc returned NULL\n")
|
|
return
|
|
string.memset(buf, 0, 64)
|
|
# 手动拼接: 先拷贝 "Hello",再拷贝 " World"
|
|
hello: t.CChar | t.CPtr = "Hello"
|
|
world: t.CChar | t.CPtr = " World"
|
|
string.memcpy(buf, hello, 5)
|
|
string.memcpy(t.CPtr(t.CUInt64T(buf) + 5), world, 6)
|
|
cmp_result: t.CInt = string.strcmp(buf, "Hello World")
|
|
testcheck.check(cmp_result == 0, "strcat via memcpy", "strcat via memcpy (cmp mismatch)")
|
|
|
|
def test_strcmp():
|
|
testcheck.section("Test 4: strcmp")
|
|
r1: t.CInt = string.strcmp("abc", "abc")
|
|
r2: t.CInt = string.strcmp("abc", "abd")
|
|
r3: t.CInt = string.strcmp("abd", "abc")
|
|
testcheck.check(r1 == 0 and r2 < 0 and r3 > 0, "strcmp (eq=0 lt<0 gt>0)", "strcmp (expect eq=0 lt<0 gt>0)")
|
|
|
|
def test_strncpy():
|
|
testcheck.section("Test 5: strncpy")
|
|
buf: t.CChar | t.CPtr = w32.win32memory.VirtualAlloc(None, 64, 12288, 4)
|
|
if t.CUInt64T(buf) == 0:
|
|
stdio.printf("SKIP: VirtualAlloc returned NULL\n")
|
|
return
|
|
string.memset(buf, 0, 64)
|
|
string.strncpy(buf, "ABCDEFGHIJ", 5)
|
|
cmp_result: t.CInt = string.strcmp(buf, "ABCDE")
|
|
testcheck.check(cmp_result == 0, "strncpy (result=ABCDE)", "strncpy (cmp mismatch)")
|
|
|
|
def test_char_access():
|
|
testcheck.section("Test 6: char access")
|
|
s: t.CChar | t.CPtr = "ABCDE"
|
|
val: t.CUInt8T = s[2] # 'C' = 67
|
|
testcheck.check(val == 67, "char access (s[2]=67='C')", "char access (s[2] expect 67)")
|
|
|
|
def test_snprintf():
|
|
testcheck.section("Test 7: snprintf")
|
|
buf: t.CChar | t.CPtr = w32.win32memory.VirtualAlloc(None, 128, 12288, 4)
|
|
if t.CUInt64T(buf) == 0:
|
|
stdio.printf("SKIP: VirtualAlloc returned NULL\n")
|
|
return
|
|
string.memset(buf, 0, 128)
|
|
stdio.snprintf(buf, 128, "value=%d hex=0x%x str=%s", 42, 255, "test")
|
|
cmp_result: t.CInt = string.strcmp(buf, "value=42 hex=0xff str=test")
|
|
testcheck.check(cmp_result == 0, "snprintf (result=value=42 hex=0xff str=test)", "snprintf (result mismatch)")
|
|
|
|
import w32.win32memory
|
|
|
|
def main() -> t.CInt:
|
|
testcheck.begin("StringTest: 字符串操作基准测试")
|
|
test_strlen()
|
|
test_strcpy()
|
|
test_strcat()
|
|
test_strcmp()
|
|
test_strncpy()
|
|
test_char_access()
|
|
test_snprintf()
|
|
return testcheck.end()
|