#!/bin/bash
#
#
exec 2>/dev/null	
source ../get_test_values --group=base  # group base is only a dummy here
groups="$CHALLENGE_GROUPS"

function do_for_sigint() {
	echo "Tests stopped (group $group)"
	exit
}

trap 'do_for_sigint' 2

function run_all_tests()
{
    local group=$1
    tests="$(ls -1 $CHALLENGE_BIN/test_[A-Z]*)"
    for t in $tests; do
        # echo "calling $t"
        $t $group
        sleep 1
    done
    sleep 10
}

function loop_group_4ever()
{
    local g=$1
    while true; do
        run_all_tests $g
    done
}

for g in $groups; do
      echo "Start tests for group $g"
      loop_group_4ever $g &
      childs="${childs} $!"
done
echo "Use 'journalctl -af' to trace the test calls"
echo "Press ENTER to stop the tests"
read
kill $childs
echo "Tests stopped"
