阶段 D 步骤 10:测试固化(CLI 级 + 写侧自检)。

- codegen_test line1:compiler::StbView 自检(model_matches STATOR1 + sha_ok),
  篡改一字节 → sha 校验失败
- CTest 新增:cli_compile(--machine 编译退出 0)、cli_missing_machine(缺参 WILL_FAIL)
- 冻结哈希确认:工程哈希只依赖源文件内容(0xc3fe4ae74ad45900 不变,compiler_test 通过)
- 全量 ctest 14/14 全绿(新增 2 个 CLI 用例)
This commit is contained in:
2026-08-21 22:33:14 +08:00
parent a5f49caa94
commit 40bfd175c4
2 changed files with 20 additions and 0 deletions
+10
View File
@@ -698,6 +698,16 @@ static bool test_line1() {
CHECK(std::strcmp(buf, "STORE_Q r8, 3") == 0); // Q0_0io.output
isa::disasm(im[16], buf, sizeof buf);
CHECK(std::strcmp(buf, "RET") == 0);
// 12.13 写侧自检:型号标识 + SHA-256compiler::StbView
const compiler::StbView self = compiler::StbView::from(img);
CHECK(self.ok());
CHECK(self.model_matches("STATOR", 1));
CHECK(self.sha_ok());
std::vector<uint8_t> tampered = img;
tampered[100] ^= 0x01; // 篡改代码段一字节
const compiler::StbView bad = compiler::StbView::from(tampered);
CHECK(bad.ok() && !bad.sha_ok()); // 结构可解析但 SHA 校验失败
return true;
}