#!/bin/sh
set -eu

if [ "$#" -ne 1 ]; then
    echo "usage: $0 <serial.log>" >&2
    exit 2
fi

LOG=$1

if [ ! -f "$LOG" ]; then
    echo "FAIL: log not found: $LOG" >&2
    exit 1
fi

check() {
    label=$1
    pattern=$2
    if grep -Fq "$pattern" "$LOG"; then
        echo "PASS: $label"
    else
        echo "FAIL: $label (missing: $pattern)" >&2
        return 1
    fi
}

failed=0
check "linux workloads started" "[PASS] linux apps started" || failed=1
check "app-a heartbeat" "[app-a] heartbeat=" || failed=1
check "app-b heartbeat" "[app-b] heartbeat=" || failed=1
check "rtos task 1" "[rtos-task-1]" || failed=1
check "rtos task 2" "[rtos-task-2]" || failed=1

if [ "$failed" -ne 0 ]; then
    echo "RESULT: FAIL" >&2
    exit 1
fi

echo "RESULT: PASS"
