#!/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.155 2011/10/24 03:52:55 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 tcpLinux 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 \
WLtutorial wireless-infra wireless-infra-mobility \
wireless-shadowing wireless-lan-aodv wireless-gridkeeper \
wireless-diffusion wireless-lan-newnode wireless-lan-newnode-80211Ext \
source-routing satellite \
misc tagged-trace message rng xcp wpan \
energy snoop \
packmime delaybox tmix \
srm smac-multihop hier-routing algo-routing mcast vc session mixmode \
simultaneous webcache mcache plm wireless-tdma  \
# The below tests have output inconsistent with stored traces, and
# need to be re-validated
# pushback wireless-lan-gaf \

# 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 ""
        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



