Skip to content

Commit 931d4a1

Browse files
committed
tests: cover multi-offset rows in the hash-parity guard
The guard recognised only single-offset rows ("{0x<hash>, 0x<off>}, // <uname>") and silently skipped any table whose rows carry more than one offset (a pair, or a { ... } array). Loosen the auto-discovery regex and parse_row to key on the leading hash and the trailing "// <uname>" comment, ignoring whatever offset payload sits between, so every hashed table is checked regardless of its offset shape.
1 parent 8288df7 commit 931d4a1

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

tests/check-hash-parity

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ if ! "$cc" -O2 -Wall -Wextra -I"$src" "$root/tests/check_hash_parity.c" -o "$bin
2626
fi
2727

2828
if [ "$#" -eq 0 ]; then
29-
# Auto-discover components carrying a hashed offset table by the row signature.
29+
# Auto-discover components carrying a hashed offset table by the row signature:
30+
# a row opens "{0x<16-hex hash>," and carries a "// <uname>" comment, whatever
31+
# the offset payload between them (a single offset, or a { ... } array).
3032
# shellcheck disable=SC2046 # intended word-splitting of the discovered list
31-
set -- $(grep -lE '^[[:space:]]*\{0x[0-9a-f]{16}, 0x[0-9a-f]+\}, //' \
33+
set -- $(grep -lE '^[[:space:]]*\{0x[0-9a-f]{16},.*//' \
3234
"$src"/components/*.c 2>/dev/null)
3335
fi
3436

tests/check_hash_parity.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
//
66
// Components that key per-build offsets on a uname fingerprint store rows of
77
// the form
8-
// {0x<16-hex hash>, 0x<offset>}, // <release> <version>
9-
// where the hash was produced by the offline table generator. This harness
8+
// {0x<16-hex hash>, <offset(s)>}, // <release> <version>
9+
// where <offset(s)> is one offset or a { ... } array, and the hash was produced
10+
// by the offline table generator. This harness
1011
// recomputes kasld_fnv1a64() over each row's uname comment and asserts it
1112
// equals the stored hash, so the runtime hash and the generator's cannot
1213
// silently drift: a build whose row is present matches its own row exactly. It
@@ -68,21 +69,24 @@ static int cmp_row(const void *a, const void *b) {
6869
return (x > y) - (x < y);
6970
}
7071

71-
/* Parse one table row "{0x<hash>, 0x<off>}, // <uname>". Returns 1 and fills
72-
* *hash / *uname (into the caller's line buffer) on a match, else 0. */
72+
/* Parse one hashed table row "{0x<hash>, <...>}, // <uname>", where <...> is a
73+
* single offset (qemu) or a { ... } offset array (bpf). Only the hash and the
74+
* uname comment are checked, so whatever sits between them is ignored. Returns
75+
* 1 and fills *hash / *uname (into the caller's line buffer) on a match, else
76+
* 0. */
7377
static int parse_row(char *line, uint64_t *hash, char **uname) {
7478
char *p = line, *end;
7579
while (*p == ' ' || *p == '\t')
7680
p++;
7781
if (*p != '{' || p[1] != '0' || p[2] != 'x')
7882
return 0;
7983
*hash = strtoull(p + 1, &end, 16);
80-
if (strncmp(end, ", 0x", 4) != 0)
84+
if (*end != ',') /* a hashed row is "{0x<hash>, <offset(s)>}, // ..." */
8185
return 0;
82-
strtoull(end + 2, &end, 16); /* offset: advance past, value unused here */
83-
if (strncmp(end, "}, // ", 6) != 0)
86+
char *c = strstr(end, "// "); /* the uname comment, past any offset(s) */
87+
if (!c)
8488
return 0;
85-
char *u = end + 6;
89+
char *u = c + 3;
8690
size_t n = strlen(u);
8791
while (n > 0 && (u[n - 1] == '\n' || u[n - 1] == '\r'))
8892
u[--n] = '\0';

0 commit comments

Comments
 (0)