lib misc+ww tests: hand-main plumbing -> assert (@test conversion B7)
toktest documents the per-row signalled pinpoint loss.
This commit is contained in:
@@ -4,9 +4,9 @@
|
||||
//
|
||||
// The digest is the cgen-correctness oracle for u32 wrapping arithmetic
|
||||
// + the hash-vtable dispatch: any u32-overflow / rotate miscompile shows
|
||||
// up as a byte mismatch. Same signalled-then-fail()-with-+10 pattern as
|
||||
// the rest of the 9xx stdlib tests; the non-zero exit pinpoints the
|
||||
// failing case. Expected digests come through the (separately tested)
|
||||
// up as a byte mismatch. A failing row aborts via the assert/abort
|
||||
// builtin (task #5 @test conversion). Expected digests come through the
|
||||
// (separately tested)
|
||||
// hex.decodestr so the vectors stay readable.
|
||||
package sha256_test;
|
||||
|
||||
@@ -16,10 +16,7 @@ import errors;
|
||||
import hash;
|
||||
import encoding.hex;
|
||||
import strings;
|
||||
import os;
|
||||
|
||||
let signalled: i32 = 0;
|
||||
fn fail() void = { os.exit(signalled + 10); };
|
||||
|
||||
// dohash — one-shot hash of `msg` into the caller's `out` (>= 32 bytes).
|
||||
// Mirrors the sum()-writes-into-a-buffer API (no array-by-value return).
|
||||
@@ -33,9 +30,9 @@ fn dohash(msg: []u8, out: []u8) void = {
|
||||
fn checkbytes(got: []u8, want: str) void = {
|
||||
match (hex.decodestr(want)) {
|
||||
case let w: []u8 => {
|
||||
if (!bytes.equal(got, w)) { fail(); };
|
||||
assert(!(!bytes.equal(got, w)));
|
||||
};
|
||||
case let e: errors.invalid => fail();
|
||||
case let e: errors.invalid => abort();
|
||||
};
|
||||
};
|
||||
|
||||
@@ -105,7 +102,7 @@ fn check(msg: []u8, want: str) void = {
|
||||
let out2: [32]u8;
|
||||
hash.sum(h, out1[0:32]);
|
||||
hash.sum(h, out2[0:32]);
|
||||
if (!bytes.equal(out1[0:32], out2[0:32])) { fail(); };
|
||||
assert(!(!bytes.equal(out1[0:32], out2[0:32])));
|
||||
checkbytes(out1[0:32],
|
||||
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
|
||||
|
||||
@@ -116,23 +113,23 @@ fn check(msg: []u8, want: str) void = {
|
||||
hash.sum(h, out3[0:32]);
|
||||
let want: [32]u8;
|
||||
dohash(strings.toutf8("abcdef"), want[0:32]);
|
||||
if (!bytes.equal(out3[0:32], want[0:32])) { fail(); };
|
||||
assert(!(!bytes.equal(out3[0:32], want[0:32])));
|
||||
};
|
||||
|
||||
// sz()/bsz() report the SHA-256 constants regardless of state.
|
||||
@test fn sizes() void = {
|
||||
let st: sha256.state = sha256.sha256();
|
||||
let h: *hash.hash = (&st): *hash.hash;
|
||||
if (hash.sz(h) != 32: size) { fail(); };
|
||||
if (hash.bsz(h) != 64: size) { fail(); };
|
||||
assert(!(hash.sz(h) != 32: size));
|
||||
assert(!(hash.bsz(h) != 64: size));
|
||||
};
|
||||
|
||||
export fn main() i32 = {
|
||||
signalled = 1; empty();
|
||||
signalled = 2; abc();
|
||||
signalled = 3; twoblockpad();
|
||||
signalled = 4; millionas();
|
||||
signalled = 5; reentrant();
|
||||
signalled = 6; sizes();
|
||||
empty();
|
||||
abc();
|
||||
twoblockpad();
|
||||
millionas();
|
||||
reentrant();
|
||||
sizes();
|
||||
return 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user