#!/bin/sh

srcdir=`dirname $0`
srcdir=`cd $srcdir; pwd`
srcdir=`dirname $srcdir`

# set up MIBDIRS to refer to the src directory
if [ "x$MIBDIRS" = "x" ]; then
    MIBDIRS=${srcdir}/mibs
    export MIBDIRS
fi

# Make sure MinGW / MSYS users have the kill.exe program to stop the agent and
# snmptrapd
if [ "x$OSTYPE" = "xmsys" -a "x`type -p kill.exe`" = "x" ]; then
    echo Could not find kill.exe. Aborting tests.
    echo kill.exe can be installed as follows:
    echo - Download pskill.exe from http://technet.microsoft.com/en-us/sysinternals/default.aspx.
    echo - Copy pskill.exe to C:\Windows\kill.exe.
    exit 1
fi 

success_count=0
failed_count=0
rm -f failed_tests
if [ "x$1" = "x" ]; then
  testset="${srcdir}/testing/fulltests/default/T*"
else
  testset="${srcdir}/testing/fulltests/default/T`printf %03d $1`*"
fi
for i in $testset; do
    echo "RUNNING $i"
    ${srcdir}/testing/fulltests/support/simple_run $i
    if [ $? = 0 ]; then
        success_count=`expr $success_count + 1`
    else
        failed_count=`expr $failed_count + 1`
        echo "$i" >> failed_tests
    fi
done

if [ -e failed_tests ]; then
    echo
    echo Failed tests:
    cat failed_tests
fi
echo
echo Summary: $success_count / `expr $failed_count + $success_count` succeeded.

exit $failed_count
