tools.sh (2810B)
1 #!/bin/sh 2 # Tier 1 system sentinel for cheap driver utility tools. 3 4 set -u 5 6 script_dir=$(cd "$(dirname "$0")" && pwd) 7 repo_root=$(cd "$script_dir/../../.." && pwd) 8 manifest="$repo_root/test/tier1/manifests/system/tools.txt" 9 log_dir="${KIT_TIER1_LOG_DIR:-$repo_root/build/test/tier1/logs/system/tools}" 10 11 mkdir -p "$log_dir" 12 . "$script_dir/../timing.sh" 13 14 run_step() { 15 name=$1 16 shift 17 log="$log_dir/$name.log" 18 start_ms=$(t1_now_ms) 19 printf 'tier1/tools: %s\n' "$name" 20 "$@" > "$log" 2>&1 21 rc=$? 22 if [ "$rc" -eq 0 ]; then 23 if t1_slow_timing_enabled; then 24 printf ' ok: %s (%sms)\n' "$log" "$(t1_elapsed_ms "$start_ms" "$(t1_now_ms)")" 25 else 26 printf ' ok: %s\n' "$log" 27 fi 28 return 0 29 fi 30 if t1_slow_timing_enabled; then 31 printf ' FAIL: %s (exit %s, %sms)\n' "$log" "$rc" \ 32 "$(t1_elapsed_ms "$start_ms" "$(t1_now_ms)")" >&2 33 else 34 printf ' FAIL: %s (exit %s)\n' "$log" "$rc" >&2 35 fi 36 tail -n 80 "$log" >&2 37 return "$rc" 38 } 39 40 if [ ! -f "$manifest" ]; then 41 printf 'tier1/tools: manifest missing: %s\n' "$manifest" >&2 42 exit 2 43 fi 44 45 count=0 46 order="$log_dir/.order.$$" 47 : > "$order" 48 jobs=$(t1_parallel_jobs) || exit $? 49 50 start_step() { 51 target=$1 52 id=$(t1_step_id "$target") 53 out="$log_dir/.step-$id.out" 54 status="$log_dir/.step-$id.status" 55 printf '%s\t%s\t%s\n' "$id" "$out" "$status" >> "$order" 56 t1_parallel_wait_for_slot "$jobs" 57 ( 58 case "$target" in 59 tier1:tools-kitchen) 60 if run_step tools-kitchen env KIT="$repo_root/build/kit" \ 61 sh "$repo_root/test/tier1/system/tools-kitchen.sh" \ 62 > "$out" 2>&1; then 63 printf '0\n' > "$status" 64 else 65 printf '%s\n' "$?" > "$status" 66 fi ;; 67 *) 68 if run_step "$target" make -C "$repo_root" "$target" \ 69 > "$out" 2>&1; then 70 printf '0\n' > "$status" 71 else 72 printf '%s\n' "$?" > "$status" 73 fi ;; 74 esac 75 ) & 76 } 77 78 while IFS= read -r target || [ -n "$target" ]; do 79 target=${target%%#*} 80 target=$(printf '%s' "$target" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') 81 [ -n "$target" ] || continue 82 count=$((count + 1)) 83 start_step "$target" 84 done < "$manifest" 85 86 wait || true 87 88 if [ "$count" -eq 0 ]; then 89 printf 'tier1/tools: manifest has no runnable targets: %s\n' "$manifest" >&2 90 exit 2 91 fi 92 93 rc=0 94 while IFS="$(printf '\t')" read -r id out status; do 95 [ -n "$id" ] || continue 96 cat "$out" 97 step_rc=$(cat "$status" 2>/dev/null || printf '1\n') 98 if [ "$step_rc" -ne 0 ] && [ "$rc" -eq 0 ]; then 99 rc=$step_rc 100 fi 101 done < "$order" 102 exit "$rc"