#!/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: /nfs/jade/vint/CVSROOT/ns-2/validate,v 1.143 2005/06/20 16:29:09 sfloyd 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

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 srm realaudio \
ecn ecn-ack ecn-full quickstart \
diffusion3 smac smac-multihop \
manual-routing hier-routing algo-routing lan mcast vc session mixmode \
red adaptive-red red-pd rio vq rem gk pi cbq schedule rr monitor jobs \
intserv diffserv webcache mcache webtraf \
simultaneous mip links plm linkstate mpls oddBehaviors \
wireless-shadowing wireless-lan-aodv wireless-tdma wireless-gridkeeper \
wireless-diffusion wireless-lan-newnode satellite WLtutorial energy \
source-routing snoop \
misc tagged-trace message rng xcp wpan

# 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

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_failed
then
    	echo
	echo "validate overall report: some tests failed:"
	echo "    $failed_list"
	echo "to re-run a specific test, cd tcl/test; ./test-all-TEST-NAME"
	echo "Notice that some tests in webcache will fail on freebsd when -O is turned on."
	echo "This is due to some event reordering, which will disappear when -g is turned on."
        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 "validate overall report: all tests passed"
	exit 0
fi



