把 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 找项目,不引用该文档。
72 lines
2.4 KiB
Plaintext
72 lines
2.4 KiB
Plaintext
import t, c
|
|
import stdio
|
|
import testcheck
|
|
import atom
|
|
|
|
|
|
# ============================================================
|
|
# G6: 验证 atom 模块的内联汇编原子操作
|
|
#
|
|
# TPV 在编译 atom.py 的 __atomic_test_and_set 时崩溃
|
|
# (ACCESS_VIOLATION in ASM args loop ai3=2)
|
|
# 此测试用 TPC 编译验证 atom 模块是否正确工作
|
|
# ============================================================
|
|
|
|
|
|
def test_atomic_test_and_set():
|
|
testcheck.section("Test 1: __atomic_test_and_set")
|
|
flag: t.CUInt8T = 0
|
|
result: t.CBool = atom.__atomic_test_and_set(c.Addr(flag), atom.ATOMIC_ACQUIRE)
|
|
# test_and_set 返回旧值: flag=0 -> 返回 0, flag 变为 1
|
|
testcheck.check(result == t.CBool(0), "first set returns old value 0", "expect 0")
|
|
testcheck.check(flag == 1, "flag is 1 after set", "expect 1")
|
|
|
|
# 第二次设置应返回 1(旧值已为 1)
|
|
result2: t.CBool = atom.__atomic_test_and_set(c.Addr(flag), atom.ATOMIC_ACQUIRE)
|
|
testcheck.check(result2 == t.CBool(1), "second set returns old value 1", "expect 1")
|
|
|
|
|
|
def test_atomic_clear():
|
|
testcheck.section("Test 2: __atomic_clear")
|
|
flag: t.CUInt8T = 1
|
|
atom.__atomic_clear(c.Addr(flag), atom.ATOMIC_RELEASE)
|
|
testcheck.check(flag == 0, "flag is 0 after clear", "expect 0")
|
|
|
|
|
|
def test_atomic_thread_fence():
|
|
testcheck.section("Test 3: __atomic_thread_fence")
|
|
# 只是验证不崩溃
|
|
atom.__atomic_thread_fence(atom.ATOMIC_SEQ_CST)
|
|
testcheck.ok("mfence executed OK")
|
|
|
|
|
|
def test_atomic_lock_free():
|
|
testcheck.section("Test 4: __atomic_is_lock_free")
|
|
flag: t.CUInt8T = 0
|
|
result: t.CBool = atom.__atomic_is_lock_free(1, c.Addr(flag))
|
|
testcheck.check(result == t.CBool(1), "1-byte is lock free", "expect 1")
|
|
|
|
|
|
def test_atomic_spinlock():
|
|
testcheck.section("Test 5: spinlock pattern (test_and_set + clear)")
|
|
lock: t.CUInt8T = 0
|
|
|
|
# 获取锁
|
|
while atom.__atomic_test_and_set(c.Addr(lock), atom.ATOMIC_ACQUIRE) == t.CBool(1):
|
|
pass
|
|
testcheck.check(lock == 1, "lock acquired", "expect lock=1")
|
|
|
|
# 释放锁
|
|
atom.__atomic_clear(c.Addr(lock), atom.ATOMIC_RELEASE)
|
|
testcheck.check(lock == 0, "lock released", "expect lock=0")
|
|
|
|
|
|
def main() -> t.CInt:
|
|
testcheck.begin("G6: atom module (inline asm atomic operations)")
|
|
test_atomic_test_and_set()
|
|
test_atomic_clear()
|
|
test_atomic_thread_fence()
|
|
test_atomic_lock_free()
|
|
test_atomic_spinlock()
|
|
return testcheck.end()
|