test(svd): assert the inheritance measurement bound (#17353)

* test(svd): assert the inheritance measurement bound

* test(svd): isolate the numeric lower bound assertion
This commit is contained in:
Vincent Koc
2026-12-06 09:59:09 +08:00
committed by GitHub
parent 9db36ae19d
commit fa83020b60
@@ -960,18 +960,25 @@ describe("firmwareLiteralPools domain scanner", () => {
expect(compactArrRes.value.intervals).toHaveLength(1);
}
// 8. Reverse-declared 4,000-deep derivedFrom chain adding 1 distinct register per peripheral shares persistent links without O(N^2) heap copies and refuses promptly.
// 8. The reverse-declared chain shares inherited registers. It reaches the
// logical measurement ceiling before the budget for allocated tree nodes.
const chainPeriphs = Array.from({ length: 4_000 }, (_, i) => {
const derived = i < 3_999 ? ` derivedFrom="CH_${String(i + 1)}"` : "";
return `<peripheral${derived}><name>CH_${String(i)}</name><baseAddress>0x${(0x5000_0000 + i * 0x1000).toString(16)}</baseAddress><size>32</size><registers><register><name>R_${String(i)}</name><addressOffset>0x${(i * 4).toString(16)}</addressOffset></register></registers></peripheral>`;
}).join("");
const chainStart = performance.now();
const chainRes = parseSvdPeripheralSpans(
`<device><peripherals>${chainPeriphs}</peripherals></device>`,
200_000,
);
expect(chainRes.ok).toBe(false);
expect(performance.now() - chainStart).toBeLessThan(1000);
if (chainRes.ok) throw new Error("expected the SVD measurement limit");
// The first 1,414 layouts account for 1,000,405 logical frames.
const { detail, ...failure } = chainRes.error.failure;
expect(failure).toEqual({
kind: "limit",
format: "cmsis-svd",
limit: { name: "max_svd_xml_nodes", maximum: 200_000 },
});
expect(detail).toMatch(/\b1000405\b/u);
// 9. 12,000-peripheral derivedFrom chain repeatedly overriding the same register "R" replaces shadowed nodes in O(log K) and completes in linearithmic time.
const overrideChainPeriphs = Array.from({ length: 12_000 }, (_, i) => {