aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / tests / fixtures / osh / gen-fixtures-h.sh
| 1 | #!/bin/bash |
| 2 | # gen-fixtures-h.sh: turn the fixture scripts into the C header core/osh_fixtures.h used by the kernel self-test |
| 3 | # (CK_OSH_TEST). od + sed only, no scripting language. Usage: gen-fixtures-h.sh TRACE_DIR OUT_H |
| 4 | # Each tNN.sh may have the optional sidecars of omega tests/osh/osh_trace.c: tNN.status (fake pipeline statuses) and |
| 5 | # tNN.args (positional parameters, one per line). They are embedded as raw bytes; a sidecar without its .sh is an error. |
| 6 | # QEMU (aarch64 virt), TEST signer, not physical. |
| 7 | set -eu |
| 8 | export LC_ALL=C |
| 9 | dir=${1:?TRACE_DIR} |
| 10 | out=${2:?OUT_H} |
| 11 | for f in "$dir"/*.status "$dir"/*.args; do |
| 12 | [[ -e "$f" ]] || continue |
| 13 | [[ -e "${f%.*}.sh" ]] || { echo "gen-fixtures-h.sh: $f has no ${f%.*}.sh" >&2; exit 1; } |
| 14 | done |
| 15 | bytes() { # NAME FILE |
| 16 | echo "static const unsigned char $1[] = {" |
| 17 | od -An -v -tu1 "$2" | sed 's/^ *//; s/ */,/g; s/$/,/' |
| 18 | echo "0};" |
| 19 | } |
| 20 | { |
| 21 | echo "/* GENERATED by tests/fixtures/osh/gen-fixtures-h.sh from the fixture scripts in tests/fixtures/osh/trace. Do not edit. */" |
| 22 | echo "#ifndef AIENOS_CK_OSH_FIXTURES_H" |
| 23 | echo "#define AIENOS_CK_OSH_FIXTURES_H" |
| 24 | i=0 |
| 25 | for f in "$dir"/*.sh; do |
| 26 | bytes "osh_fx_$i" "$f" |
| 27 | [[ -e "${f%.sh}.status" ]] && bytes "osh_fx_${i}_status" "${f%.sh}.status" |
| 28 | [[ -e "${f%.sh}.args" ]] && bytes "osh_fx_${i}_args" "${f%.sh}.args" |
| 29 | i=$((i + 1)) |
| 30 | done |
| 31 | echo "static const struct {" |
| 32 | echo " const char *name;" |
| 33 | echo " const unsigned char *text;" |
| 34 | echo " unsigned long len;" |
| 35 | echo " const unsigned char *status; /* NULL: no .status sidecar */" |
| 36 | echo " unsigned long status_len;" |
| 37 | echo " const unsigned char *args; /* NULL: no .args sidecar */" |
| 38 | echo " unsigned long args_len;" |
| 39 | echo "} osh_fx[] = {" |
| 40 | i=0 |
| 41 | for f in "$dir"/*.sh; do |
| 42 | st="0, 0" |
| 43 | ar="0, 0" |
| 44 | [[ -e "${f%.sh}.status" ]] && st="osh_fx_${i}_status, sizeof osh_fx_${i}_status - 1" |
| 45 | [[ -e "${f%.sh}.args" ]] && ar="osh_fx_${i}_args, sizeof osh_fx_${i}_args - 1" |
| 46 | echo " { \"$(basename "$f" .sh)\", osh_fx_$i, sizeof osh_fx_$i - 1, $st, $ar }," |
| 47 | i=$((i + 1)) |
| 48 | done |
| 49 | echo "};" |
| 50 | echo "#endif" |
| 51 | } >"$out" |