From 8ac04a0c2f5cd949a45866f938bd1aa72fbe56e2 Mon Sep 17 00:00:00 2001 From: cirakg Date: Mon, 19 Oct 2026 15:27:37 +0200 Subject: test(storage): cover records, vault, PINs, lockout and migrations 34 new tests (65 per device): round trips per entry type, every tampered byte, swapped records, the pending queue, the entry cap, a full store at 67 fill levels, the lockout schedule on a fake clock including restarts, erase, PIN change and reset, auto-lock wiping, and v0 to v1 migration. Adds an in-memory store with a size limit and storage benchmarks. Co-Authored-By: Claude Opus 5.5 --- test/BenchTest.mc | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'test/BenchTest.mc') diff --git a/test/BenchTest.mc b/test/BenchTest.mc index 7e1f612..df12db1 100644 --- a/test/BenchTest.mc +++ b/test/BenchTest.mc @@ -1,5 +1,5 @@ // Author: cirakg & claude ai -// Summary: Benchmarks of the crypto and OTP primitives; logs BENCH lines for docs/PERFORMANCE.md, never fails. +// Summary: Benchmarks of the crypto, OTP and storage code; logs BENCH lines for docs/PERFORMANCE.md, never fails. // // Simulator timings run on the PC's CPU, so they only compare primitives with // each other (for example how much SHA-512 costs against native SHA-1). @@ -55,6 +55,38 @@ module Bench { SelfTest.run(); } } + + // A vault with 20 OTP entries, for list and open timings. + class VaultCases { + var vault as Vault; + var ids as Array; + + function initialize() { + vault = new Vault(new MemoryBackend(), new FakeTime()); + for (var i = 0; i < 20; i++) { + vault.add(StorageFixtures.totp("Entry " + i)); + } + ids = vault.ids(); + } + + // What the list does on start-up: every header. + function readAllHeaders() as Void { + for (var i = 0; i < ids.size(); i++) { + vault.header(ids[i]); + } + } + + // What showing one code does: decrypt one entry. + function openOne() as Void { + vault.open(ids[0]).wipeSecrets(); + } + + function addOne() as Void { + var e = StorageFixtures.totp("Bench"); + vault.add(e); + vault.remove(e.id); + } + } } (:test) @@ -68,3 +100,12 @@ function benchmarkPrimitives(logger as Test.Logger) as Boolean { Bench.measure(logger, "self_test", 3, c.method(:selfTest)); return true; } + +(:test) +function benchmarkVault(logger as Test.Logger) as Boolean { + var v = new Bench.VaultCases(); + Bench.measure(logger, "vault_20_headers", 5, v.method(:readAllHeaders)); + Bench.measure(logger, "vault_open_entry", 20, v.method(:openOne)); + Bench.measure(logger, "vault_add_remove", 10, v.method(:addOne)); + return true; +} -- cgit v1.2.3