#!/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 pskill.exe program to stop the agent and
# snmptrapd
if [ "x$OSTYPE" = "xmsys" ]; then
    for e in pskill.exe pslist.exe; do
	if [ "x`type $e 2>/dev/null`" = "x" ]; then
	    echo "Could not find $e. Aborting tests."
	    echo "$e can be installed as follows:"
	    echo "- Download PSTools.zip from http://technet.microsoft.com/en-us/sysinternals/default."
	    echo "- Copy $e to C:\\MinGW\\msys\\1.0\\bin."
	    exit 1
	fi
    done
fi

success_count=0
failed_count=0
rm -f failed_tests
for i in "${srcdir}"/testing/fulltests/default/T*$1*; 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 [ -f 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
