#!/bin/bash

# Run smoketest script on every build/system-image-* architecture.

# If $FORK is set, run them in parallel.

test -z $FORK || setvar TIMEOUT = ${TIMEOUT:-180}

source sources/utility_functions.sh || exit 1

proc dotest {
  test -z $FORK && echo -n "Testing $1:"
  test ! -z $VERBOSE && setvar VERBOSITY = ""tee >(cat >&2) |""
  setvar RESULT = "$(more/smoketest.sh "$1" 2>&1 | eval "$VERBOSITY grep 'Hello world!'")"
  test -z $RESULT && setvar RESULT = ""FAIL"" || setvar RESULT = ""PASS""
  test -z $FORK && echo $RESULT || echo "Testing $1:$RESULT"
  rm -f build/system-image-"$1"/hdb.img 2>/dev/null
}

# Test all non-hw targets to see whether or not they can compile and run
# the included "hello world" program.

for i in $(ls -d sources/targets/* | sed 's@.*/@@' | grep -v "^hw-")
{
  if test -e "build/system-image-$i"
  {
    maybe_fork "dotest $i"
  } else {
    echo "Testing $i:NONE"
  }
}

wait