Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/native/store/tests/gen_golden.sh # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / store / tests / gen_golden.sh` 48 lines ยท 1907 bytes Raw Blame History 1 #!/bin/sh 2 # Flatten docs/adr/0015-golden-vectors.json into a C table of 3 # (section, key, value) rows, so the C test can check every field the frozen 4 # file carries (the same "every key asserted" rule as the Rust test). 5 # The JSON is the repo's own fixed file: one "key": value per line, nesting 6 # at most two levels (section -> unit_map). Anything else is refused. 7 # Usage: gen_golden.sh IN.json OUT.h 8 set -eu 9 in=$1 10 out=$2 11 awk ' 12 function fail(m) { print "gen_golden: " m " at line " NR > "/dev/stderr"; bad = 1; exit 1 } 13 BEGIN { depth = 0; n = 0 } 14 { 15 line = $0 16 sub(/^[ \t]+/, "", line); sub(/[ \t]+$/, "", line) 17 if (line == "{") { if (depth != 0) fail("unexpected {"); depth = 1; next } 18 if (line ~ /^}[,]?$/) { depth--; next } 19 if (line !~ /^"[^"]*": /) fail("unparsed line") 20 key = line; sub(/^"/, "", key); sub(/": .*$/, "", key) 21 val = line; sub(/^"[^"]*": /, "", val); sub(/,$/, "", val) 22 if (val == "{") { 23 depth++ 24 if (depth == 2) section = key 25 else if (depth == 3) sub_key = key 26 else fail("too deep") 27 next 28 } 29 if (depth == 1) { sec = ""; k = key } 30 else if (depth == 2) { sec = section; k = key } 31 else { sec = section; k = sub_key "." key } 32 if (val ~ /^"/) { isnum = 0; sub(/^"/, "", val); sub(/"$/, "", val); if (val ~ /["\\]/) fail("escape") } 33 else if (val ~ /^[0-9]+$/) isnum = 1 34 else fail("unsupported value") 35 printf " {\"%s\", \"%s\", \"%s\", %d},\n", sec, k, val, isnum 36 n++ 37 } 38 END { if (bad) exit 1; if (depth != 0) { print "gen_golden: unbalanced" > "/dev/stderr"; exit 1 } } 39 ' "$in" > "$out.rows" 40 { 41 echo "/* Generated by tests/gen_golden.sh from docs/adr/0015-golden-vectors.json. */" 42 echo "typedef struct { const char *section, *key, *value; int is_number; } golden_row;" 43 echo "static const golden_row GOLDEN[] = {" 44 cat "$out.rows" 45 echo "};" 46 echo "#define GOLDEN_ROWS (sizeof GOLDEN / sizeof GOLDEN[0])" 47 } > "$out" 48 rm -f "$out.rows"