#!/bin/sh

#
# validate -- run all the test scripts
#
# Copyright (c) 1997 University of Southern California.
# All rights reserved.                                            
#                                                                
# Redistribution and use in source and binary forms are permitted
# provided that the above copyright notice and this paragraph are
# duplicated in all such forms and that any documentation, advertising
# materials, and other materials related to such distribution and use
# acknowledge that the software was developed by the University of
# Southern California, Information Sciences Institute.  The name of the
# University may not be used to endorse or promote products derived from
# this software without specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# $Header: /cvsroot/nsnam/ns-2/validate,v 1.147 2007/08/15 05:51:59 tom_henderson Exp $

try () {
        for excluding in $cygwin_exclude; do
                if [ "$excluding" = "$1" ]; then
                        echo "*** $1 skipped (Cygwin)";
                        return 0;
                fi;
        done;

	echo "*** $1"
	$1 quiet || {
		any_failed=true
		failed_list="$failed_list $1"
	}
	return $?
}


any_failed=false
failed_list=""

test_cygwin=`uname | tr [a-z] [A-Z] | sed -e 's|.*CYGWIN.*|true|'`;
if  [ "${test_cygwin}" = "true" ]; then
        echo "Cygwin detected";
        echo "Note: Cygwin validation is still considered EXPERIMENTAL";
        echo "";
        # cygwin_exclude="./test-all-pi";
	#echo "$cygwin_exclude will not be run.";
        #echo "";
        #
        # put PI back in the validation - nicolas, 1/15/04
        cygwin_exclude="";
else
        cygwin_exclude="";
fi;

echo "(Validation can take 1-30 hours to run.)"

cd tcl/test

# 
# First run portable tests
#
for i in \
simple tcp testReno newreno sack tcpOptions tcpReset \
simple-full full testReno-full testReno-bayfull sack-full \
tcp-init-win tcpVariants LimTransmit aimd greis rfc793edu rfc2581 rbp \
sctp  tcpHighspeed frto  friendly realaudio \
ecn ecn-ack ecn-full quickstart diffusion3 smac \
manual-routing lan \
red adaptive-red red-pd rio vq rem gk pi cbq schedule rr monitor jobs \
intserv diffserv webtraf \
mip links linkstate mpls oddBehaviors \
wireless-shadowing wireless-lan-aodv wireless-gridkeeper \
wireless-diffusion wireless-lan-newnode WLtutorial \
source-routing \
misc tagged-trace message rng xcp wpan \
energy snoop \
packmime delaybox \
# wireless-lan-gaf

# Validation tests that still use full packet headers:
# wireless-shadowing wireless-lan-aodv wireless-tdma wireless-gridkeeper
# wireless-diffusion wireless-lan-newnode satellite WLtutorial energy

# Deleted (old tests that were for compatibility with ns-1 scripts):
# v1 red-v1 cbq-v1 sack-v1 vegas-v1

do
	date
	try ./test-all-$i
	date
	sleep 2
done

#
# Repeat for non-portable test set
#
any_portable_failed=$any_failed
any_failed=false
portable_failed_list=$failed_list
failed_list=""

for i in \
srm smac-multihop hier-routing algo-routing mcast vc session mixmode \
simultaneous webcache mcache plm wireless-tdma satellite 

do
	date
	try ./test-all-$i
	date
	sleep 2
done

echo "These messages are NOT errors and can be ignored:"
echo "    warning: using backward compatibility mode"
echo "    This test is not implemented in backward compatibility mode"
echo

if $any_portable_failed
then
    	echo
	echo "validate overall report: some portable tests failed:"
	echo "    $portable_failed_list"
        if $any_failed
        then
	    echo "some non-portable tests also failed:"
	    echo "    $failed_list"
        fi
	echo "to re-run a specific test, cd tcl/test; ./test-all-TEST-NAME"
	exit 1
fi
        
if $any_failed
then
    	echo
	echo "validate overall report: all portable tests passed but"
	echo "some non-portable tests failed:"
	echo "    $failed_list"
	echo "to re-run a specific test, cd tcl/test; ./test-all-TEST-NAME"
        echo ""
	echo "Note that the non-portable test list includes files that"
        echo "are known to pass on Linux x86 machines but that are known"
        echo "to have some portability problems to other platforms or"
        echo "operating systems.   Failure of one of these tests does not"
        echo "necessarily mean that one will encounter a problem in your"
        echo "simulations, but that one must be careful of using that"
        echo "specific model on the system on which the validate was run."
        if  [ "${test_cygwin}" = "true" ]; then
                cmaj=` uname -r | sed -e 's/^\([0-9]*\)\.\([0-9]*\).\([0-9]*\).*/\1/'`;
                echo $cmaj | grep -v [0-9] >/dev/null 2>&1
                if [ "$?" -eq "0" ]; then
                        cmaj=0;
                fi;
                cmin=` uname -r | sed -e 's/^\([0-9]*\)\.\([0-9]*\).\([0-9]*\).*/\2/'`;
                echo $cmin | grep -v [0-9] >/dev/null 2>&1
                if [ "$?" -eq "0" ]; then
                        cmin=0;
                fi;
                cpat=` uname -r | sed -e 's/^\([0-9]*\)\.\([0-9]*\).\([0-9]*\).*/\3/'`;
                echo $cpat | grep -v [0-9] >/dev/null 2>&1
                if [ "$?" -eq "0" ]; then
                        cpat=0;
                fi;
                if ([ "$cmaj" -gt "1" ]) || ([ "$cmaj" -eq "1" ] && [ $cmin -gt "3" ]) || ([ "$cmaj" -eq 1 ] && [ $cmin -eq "3" ] && [ "$cpat" -ge "19" ]); then
                echo "";
                echo "Cygwin >= 1.3.19 detected ($cmaj.$cmin.$cpat), all tests should have passed.";
                        echo "Please see <http://www.isi.edu/nsnam/ns/ns-problems.html>";
                        echo "for potential solutions.";
                else
                        echo "";
                        echo "Cygwin < 1.3.19 detected. ($cmaj.$cmin.$cpat)";
                        echo "";
                        echo "Some tests are EXPECTED to  break. Please see"
                        echo "<http://www.isi.edu/nsnam/ns/ns-problems.html> for a list.";
                        echo "";
                        echo "You may want to upgrade to a more recent version of Cygwin.";
                fi;
        fi;
	exit 1
else
        echo ""
	echo "validate overall report: all tests passed"
	exit 0
fi



