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/omega-mv/blob/main/om/tls/test/wycheproof/ledger.sh # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / om / tls / test / wycheproof / ledger.sh` 170 lines ยท 7318 bytes Raw Blame History 1 #!/bin/sh 2 # SPDX-License-Identifier: Apache-2.0 3 # Wycheproof ledger for om/tls: accounts for every test of every testvectors_v1 file at the pinned 4 # C2SP/wycheproof commit, per file and per primitive, as pass, fail, na (not applicable, with the 5 # written reason), not_run (applicable, but the suite or its log is absent) or unexplained. 6 # Usage: sh om/tls/test/wycheproof/ledger.sh WYCHEPROOF_DIR LOGDIR 7 # WYCHEPROOF_DIR a C2SP/wycheproof clone at $pin 8 # LOGDIR holds SUITE.log, the stdout+stderr of `sh om/tls/test/SUITE/run.sh OMC`, for the 9 # suites named in ledger.tsv (aesgcm chacha sha2 x25519 ec rsa mlkem ecdh); the 10 # driver outputs those runs left in build/tls/SUITE/ are read for MISMATCH lines. 11 # Rows come from ledger.tsv (one per JSON file; tab separated): 12 # json primitive suite label vectors selector not_run_file reason 13 # A test counts as run when its record is in the committed conversion `vectors` (lines matching the 14 # awk regex `selector`, comments excluded; the conversion header must carry the JSON's sha256). It 15 # passes when the suite log holds "PASS label:", fails when it holds "FAIL label" (one failure per 16 # MISMATCH line on a selected record; every run record when the driver left none). Tests not run are 17 # na when not_run_file lists them (per-file "tests=N", per-flag ": N", or a whole-file line) or the 18 # row gives a reason; anything left is unexplained. 19 # A FAIL line for a label wins over a PASS line for it in the same log. 20 # Exit 0 PASS: every test is pass or na. Exit 1 FAIL: a failure, an unexplained test or a ledger 21 # error. Exit 3 NOT_RUN: no failure, but some applicable tests did not run here. 22 set -eu 23 pin=`d17cc89fa5c8f4f4d378b5385ebf75da5d0926c9` 24 wyc=${1:?usage: ledger.sh WYCHEPROOF_DIR LOGDIR} 25 logs=${2:?usage: ledger.sh WYCHEPROOF_DIR LOGDIR} 26 here=$(cd "$(dirname "$0")" && pwd) 27 tests=$(cd "$here/.." && pwd) 28 root=$(cd "$here/../../../.." && pwd) 29 build="$root/build/tls" 30 tsv="$here/ledger.tsv" 31 tv="$wyc/testvectors_v1" 32 33 got=$(git -C "$wyc" rev-parse HEAD 2> /dev/null || echo none) 34 if [ "$got" != "$pin" ]; then 35 echo "WYCHEPROOF-LEDGER NOT_RUN: $wyc is at $got, not $pin" 36 exit 3 37 fi 38 echo "wycheproof $pin" 39 echo "ledger.tsv sha256 $(sha256sum "$tsv" | cut -d' ' -f1)" 40 41 err=0 42 # every JSON file has exactly one row, every row names an existing file 43 ls "$tv" | grep '\.json$' | sort > "${TMPDIR:-/tmp}/ledger-files.$$" 44 grep -v '^#' "$tsv" | cut -f1 | sort > "${TMPDIR:-/tmp}/ledger-rows.$$" 45 missing=$(comm -23 "${TMPDIR:-/tmp}/ledger-files.$$" "${TMPDIR:-/tmp}/ledger-rows.$$") 46 extra=$(comm -13 "${TMPDIR:-/tmp}/ledger-files.$$" "${TMPDIR:-/tmp}/ledger-rows.$$" | sort | uniq) 47 dup=$(uniq -d "${TMPDIR:-/tmp}/ledger-rows.$$") 48 rm -f "${TMPDIR:-/tmp}/ledger-files.$$" "${TMPDIR:-/tmp}/ledger-rows.$$" 49 for f in $missing; do echo "ERROR no ledger row for $f"; err=1; done 50 for f in $extra; do echo "ERROR ledger row for absent file $f"; err=1; done 51 for f in $dup; do echo "ERROR duplicate ledger row $f"; err=1; done 52 53 # sum of the not-run counts a NOT_RUN file gives for one JSON (TOTAL when a line names the file 54 # without a count), or nothing when no line names it 55 nr_count() { 56 awk -v j="$1" -v t="$2" ' 57 /^#/ { next } 58 index($0, j) { 59 found = 1 60 if (match($0, /tests=[0-9]+/)) { n += substr($0, RSTART + 6, RLENGTH - 6); next } 61 if (match($0, /: [0-9]+$/)) { n += substr($0, RSTART + 2); next } 62 whole = 1 63 } 64 END { if (whole) print t; else if (found) print n }' "$3" 65 } 66 67 # failures among selected records: MISMATCH lines of OUT whose line number is a selected record 68 mismatches() { 69 awk -v sel="$1" 'FNR == NR { if ($0 !~ /^#/ && $0 ~ sel) ok[FNR] = 1; next } 70 $1 == "MISMATCH" && $2 == "line" && ($3 + 0) in ok { n++ } 71 END { print n + 0 }' "$2" "$3" 72 } 73 74 printf '%-52s %-20s %6s %6s %5s %6s %7s %5s %s\n' file primitive total pass fail na not_run unexp note 75 tab=$(printf '\t') 76 summary="${TMPDIR:-/tmp}/ledger-sum.$$" 77 : > "$summary" 78 grep -v '^#' "$tsv" | while IFS="$tab" read -r json prim suite label vec sel nrf reason; do 79 f="$tv/$json" 80 [ -f "$f" ] || continue 81 total=$(grep -o '"tcId"' "$f" | wc -l | tr -d ' ') 82 declared=$(grep -m 1 '"numberOfTests"' "$f" | tr -dc 0-9) 83 note="" 84 if [ "$total" != "$declared" ]; then 85 echo "ERROR $json: $total tcId entries, numberOfTests $declared" 86 echo "ERR" >> "$summary" 87 continue 88 fi 89 run=0 pass=0 fail=0 na=0 notrun=0 90 present=yes 91 if [ "$vec" != "-" ]; then 92 if [ ! -f "$tests/$vec" ]; then 93 present=no 94 note="suite $suite not in this tree ($vec)" 95 else 96 sum=$(sha256sum "$f" | cut -d' ' -f1) 97 if ! grep '^#' "$tests/$vec" | grep -q "$sum"; then 98 echo "ERROR $json: $vec header does not carry sha256 $sum" 99 echo "ERR" >> "$summary" 100 continue 101 fi 102 run=$(awk -v sel="$sel" '$0 !~ /^#/ && $0 ~ sel { n++ } END { print n + 0 }' "$tests/$vec") 103 fi 104 fi 105 if [ "$nrf" != "-" ] && [ -f "$tests/$nrf" ]; then 106 na=$(nr_count "$json" "$total" "$tests/$nrf") 107 na=${na:-0} 108 [ "$na" -gt 0 ] && note="${note:+$note; }na per $nrf" 109 elif [ "$nrf" != "-" ]; then 110 note="${note:+$note; }$nrf not in this tree" 111 elif [ "$reason" != "-" ]; then 112 na=$((total - run)) 113 note="${note:+$note; }$reason" 114 fi 115 if [ "$present" = no ]; then 116 # the conversion is absent: everything not listed na is applicable but not run here 117 notrun=$((total - na)) 118 [ "$notrun" -lt 0 ] && notrun=0 119 run=0 120 else 121 log="$logs/$suite.log" 122 if [ "$run" -eq 0 ]; then 123 : 124 elif [ ! -f "$log" ]; then 125 notrun=$run 126 note="${note:+$note; }no log $suite.log" 127 elif grep -q "^FAIL $label[ :]" "$log"; then 128 out="" 129 for c in "$build/$suite/$label.out" "$build/$suite/$label.log"; do [ -f "$c" ] && out=$c && break; done 130 m=0 131 [ -n "$out" ] && m=$(mismatches "$sel" "$tests/$vec" "$out") 132 [ "$m" -eq 0 ] && m=$run 133 fail=$m 134 pass=$((run - m)) 135 note="${note:+$note; }FAIL in $suite.log${out:+, see $out}" 136 elif grep -q "^PASS $label:" "$log"; then 137 pass=$run 138 else 139 notrun=$run 140 note="${note:+$note; }$suite.log has no PASS/FAIL line for $label" 141 fi 142 fi 143 unexp=$((total - pass - fail - na - notrun)) 144 if [ "$unexp" -lt 0 ]; then 145 echo "ERROR $json: run $run + na $na exceeds total $total" 146 echo "ERR" >> "$summary" 147 continue 148 fi 149 printf '%-52s %-20s %6d %6d %5d %6d %7d %5d %s\n' "$json" "$prim" "$total" "$pass" "$fail" "$na" "$notrun" "$unexp" "$note" 150 printf '%s %d %d %d %d %d %d\n' "$prim" "$total" "$pass" "$fail" "$na" "$notrun" "$unexp" >> "$summary" 151 done 152 153 echo 154 echo "per primitive:" 155 grep -v '^ERR$' "$summary" | awk '{ t[$1] += $2; p[$1] += $3; f[$1] += $4; a[$1] += $5; r[$1] += $6; u[$1] += $7; n[$1]++ } 156 END { for (k in t) printf " %-20s files=%-3d total=%-6d pass=%-6d fail=%-4d na=%-6d not_run=%-5d unexplained=%d\n", k, n[k], t[k], p[k], f[k], a[k], r[k], u[k] }' | sort 157 errs=$(grep -c '^ERR$' "$summary" || true) 158 set -- $(grep -v '^ERR$' "$summary" | awk '{ n++; t += $2; p += $3; f += $4; a += $5; r += $6; u += $7 } END { print n + 0, t + 0, p + 0, f + 0, a + 0, r + 0, u + 0 }') 159 rm -f "$summary" 160 [ "$errs" -eq 0 ] || err=1 161 line="files=$1 tests=$2 pass=$3 fail=$4 na=$5 not_run=$6 unexplained=$7 errors=$errs" 162 if [ "$err" -ne 0 ] || [ "$4" -ne 0 ] || [ "$7" -ne 0 ]; then 163 echo "WYCHEPROOF-LEDGER FAIL $line" 164 exit 1 165 fi 166 if [ "$6" -ne 0 ]; then 167 echo "WYCHEPROOF-LEDGER NOT_RUN $line" 168 exit 3 169 fi 170 echo "WYCHEPROOF-LEDGER PASS $line"