kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

run-kitchen.sh (4642B)


      1 #!/usr/bin/env bash
      2 set -u
      3 
      4 usage() {
      5   printf 'usage: %s all|pp|c|parse|toy|wasm\n' "$0" >&2
      6 }
      7 
      8 if [ "$#" -gt 1 ]; then
      9   usage
     10   exit 2
     11 fi
     12 
     13 suite="${1:-all}"
     14 script_dir=$(cd "$(dirname "$0")" && pwd)
     15 root=$(cd "$script_dir/../../.." && pwd)
     16 fixture_root="$root/test/tier1/kitchen/frontend"
     17 log_root="${KIT_TIER1_LOG_DIR:-$root/build/test/tier1/frontend}"
     18 KIT="${KIT:-$root/build/kit}"
     19 
     20 expected_rc() {
     21   tr -d '[:space:]' < "$1"
     22 }
     23 
     24 check_rc() {
     25   local label="$1"
     26   local got="$2"
     27   local want="$3"
     28   want=$((want & 255))
     29   if [ "$got" -ne "$want" ]; then
     30     printf '%s: expected rc %d, got %d\n' "$label" "$want" "$got" >&2
     31     return 1
     32   fi
     33 }
     34 
     35 run_expect_rc() {
     36   local label="$1"
     37   local want="$2"
     38   shift 2
     39   "$@" >/dev/null 2>&1
     40   local got=$?
     41   check_rc "$label" "$got" "$want"
     42 }
     43 
     44 normalize_tokens() {
     45   tr '\n' ' ' < "$1" | tr -s '[:space:]' ' ' | sed -e 's/^ //' -e 's/ $//'
     46 }
     47 
     48 run_pp() {
     49   local src="$fixture_root/pp_kitchen.c"
     50   local expected="$fixture_root/pp_kitchen.expected"
     51   local actual="$1/pp_kitchen.actual"
     52   local exp_norm="$1/pp_kitchen.expected.norm"
     53   local act_norm="$1/pp_kitchen.actual.norm"
     54 
     55   [ -x "$KIT" ] || { printf 'missing kit binary: %s\n' "$KIT" >&2; return 2; }
     56   "$KIT" cc -E -I "$fixture_root" "$src" -o "$actual"
     57   normalize_tokens "$expected" > "$exp_norm"
     58   normalize_tokens "$actual" > "$act_norm"
     59   diff -u "$exp_norm" "$act_norm"
     60 }
     61 
     62 run_c() {
     63   local src="$fixture_root/c_kitchen.c"
     64   local expected
     65   local obj="$1/c_kitchen.o" dump="$1/c_kitchen.dump"
     66   local exe="$1/c_kitchen.exe"
     67   local emit_c="$1/c_kitchen.emit.c" emit_exe="$1/c_kitchen.emit.exe"
     68   local asm="$1/c_kitchen.s" asm_obj="$1/c_kitchen.s.o" asm_exe="$1/c_kitchen.s.exe"
     69   expected=$(expected_rc "$fixture_root/c_kitchen.expected")
     70 
     71   [ -x "$KIT" ] || { printf 'missing kit binary: %s\n' "$KIT" >&2; return 2; }
     72   "$KIT" cc -O0 -c "$src" -o "$obj"
     73   "$KIT" objdump -h -t "$obj" > "$dump"
     74   grep -Eq '(^|[[:space:]])main($|[[:space:]])' "$dump"
     75 
     76   "$KIT" cc -O0 "$src" -lc -o "$exe"
     77   run_expect_rc "c/kitchen-link-exec" "$expected" "$exe"
     78 
     79   "$KIT" cc --emit=c -O0 "$src" -o "$emit_c"
     80   "${CC:-cc}" "$emit_c" -o "$emit_exe"
     81   run_expect_rc "c/kitchen-emit-c-exec" "$expected" "$emit_exe"
     82 
     83   "$KIT" cc -S -O0 "$src" -o "$asm"
     84   "$KIT" as "$asm" -o "$asm_obj"
     85   "$KIT" cc "$asm_obj" -lc -o "$asm_exe"
     86   run_expect_rc "c/kitchen-emit-s-exec" "$expected" "$asm_exe"
     87 
     88   run_expect_rc "c/kitchen-jit" "$expected" "$KIT" run "$src"
     89 }
     90 
     91 run_toy() {
     92   local src="$fixture_root/toy_kitchen.toy"
     93   local expected
     94   local exe="$1/toy_kitchen.exe"
     95   local emit_c="$1/toy_kitchen.emit.c" emit_exe="$1/toy_kitchen.emit.exe"
     96   local asm="$1/toy_kitchen.s" asm_obj="$1/toy_kitchen.s.o" asm_exe="$1/toy_kitchen.s.exe"
     97   expected=$(expected_rc "$fixture_root/toy_kitchen.expected")
     98 
     99   [ -x "$KIT" ] || { printf 'missing kit binary: %s\n' "$KIT" >&2; return 2; }
    100 
    101   "$KIT" cc -O0 "$src" -lc -o "$exe"
    102   run_expect_rc "toy/kitchen-link-exec" "$expected" "$exe"
    103 
    104   "$KIT" cc --emit=c -O0 "$src" -o "$emit_c"
    105   "${CC:-cc}" "$emit_c" -o "$emit_exe"
    106   run_expect_rc "toy/kitchen-emit-c-exec" "$expected" "$emit_exe"
    107 
    108   "$KIT" cc -S -O0 "$src" -o "$asm"
    109   "$KIT" as "$asm" -o "$asm_obj"
    110   "$KIT" cc "$asm_obj" -lc -o "$asm_exe"
    111   run_expect_rc "toy/kitchen-emit-s-exec" "$expected" "$asm_exe"
    112 
    113   run_expect_rc "toy/kitchen-jit" "$expected" "$KIT" run "$src"
    114   run_expect_rc "toy/kitchen-interp" "$expected" "$KIT" run --no-jit "$src"
    115 }
    116 
    117 run_wasm() {
    118   local src="$fixture_root/wasm_kitchen.wat"
    119   local wasm="$1/wasm_emit.wasm"
    120   local expected
    121   local run_rc
    122   expected=$(expected_rc "$fixture_root/wasm_kitchen.expected")
    123 
    124   [ -x "$KIT" ] || { printf 'missing kit binary: %s\n' "$KIT" >&2; return 2; }
    125   "$KIT" run -e test_main "$src"
    126   run_rc=$?
    127   check_rc "wasm/kitchen-jit" "$run_rc" "$expected"
    128 
    129   "$KIT" build-exe -target wasm32-none \
    130     "$fixture_root/wasm_emit_main.c" "$fixture_root/wasm_emit_helper.c" \
    131     -e test_main -o "$wasm"
    132   "$KIT" run -e test_main "$wasm"
    133   run_rc=$?
    134   check_rc "wasm/compiled-wasm-jit" "$run_rc" 0
    135 }
    136 
    137 run_suite() {
    138   local name="$1"
    139   local log_dir="$log_root/$name"
    140   local log="$log_dir/kitchen.log"
    141   local suite_rc
    142   mkdir -p "$log_dir"
    143 
    144   if "run_$name" "$log_dir" > "$log" 2>&1; then
    145     printf 'PASS tier1-frontend/%s  %s\n' "$name" "$log"
    146     return 0
    147   else
    148     suite_rc=$?
    149   fi
    150 
    151   printf 'FAIL tier1-frontend/%s  %s\n' "$name" "$log" >&2
    152   tail -n 80 "$log" >&2 || true
    153   return "$suite_rc"
    154 }
    155 
    156 case "$suite" in
    157   all) suites="pp c toy wasm" ;;
    158   pp|c|toy|wasm) suites="$suite" ;;
    159   parse) suites="c" ;;
    160   *) usage; exit 2 ;;
    161 esac
    162 
    163 rc=0
    164 for s in $suites; do
    165   run_suite "$s" || rc=1
    166 done
    167 
    168 exit "$rc"