head     1.1;
branch   1.1.1;
access   ;
symbols  LTP_20031204:1.1.1.1 LINUX_TEST_PROJECT:1.1.1;
locks    ; strict;
comment  @# @;


1.1
date     2003.12.31.09.00.21;  author mtm;  state Exp;
branches 1.1.1.1;
next     ;

1.1.1.1
date     2003.12.31.09.00.21;  author mtm;  state Exp;
branches ;
next     ;


desc
@@



1.1
log
@Initial revision
@
text
@#! /bin/sh
#
#   Copyright (c) International Business Machines  Corp., 2003
#
#   This program is free software;  you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY;  without even the implie; warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
#   the GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program;  if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
#
#  FILE   : nfs04.sh
#
#  PURPOSE: Creates a text file of specified size locally and copies
#	    the file to an NFS mountpoint.  The two files are compared
#	    and checked for differences.  If the files differ, then 
#	    the test fails.  By default, this test creates a 10Mb file
#	    and runs for one loop.
#	               
#
#  SETUP: The home directory of root on the machine exported as "RHOST"
#         MUST have a ".rhosts" file with the hostname of the machine
#         where the test is executed.
#
#
#  HISTORY:
#    10/17/03 Robbie Williamson (robbiew@@us.ibm.com)
#      -Written
#
#***********************************************************************

#Uncomment line below for debug output.
#trace_logic=${trace_logic:-"set -x"}

$trace_logic

#-----------------------------------------------------------------------
# Initialize local variables
#-----------------------------------------------------------------------
TC=${TC:=nfs04}
TCbin=${TCbin:=`pwd`}
TCtmp=${TCtmp:=/tmp/$TC$$}
export TCID=$TC
export TST_TOTAL=1

# If CLEANUP is not set; set it to "ON"
CLEANUP=${CLEANUP:="ON"}

#=============================================================================
# FUNCTION NAME:        setup_testcase
#
# FUNCTION DESCRIPTION: Perform the setup function for the testcase.
#
# PARAMETERS:   	None.
#
# RETURNS:      	None.
#=============================================================================

setup_testcase()
{
$trace_logic
   
    VERSION=${VERSION:=2}
    RHOST=${RHOST:=`hostname`}
    FILESIZE=${FILESIZE:=10}
    SOCKET_TYPE=${SOCKET_TYPE:=udp}
    LOOPS=${LOOPS:=1}
    export TST_COUNT=$LOOPS

    echo ""
    echo "Test Options:"
    echo " VERSION: $VERSION"
    echo " RHOST: $RHOST"
    echo " FILESIZE: $FILESIZE"
    echo " SOCKET_TYPE: $SOCKET_TYPE"
    echo " LOOPS: $LOOPS"
    sleep 5

    OPTS=${OPTS:=",vers=$VERSION "}
    PID=$$
    REMOTE_DIR=${RHOST}:/mnt/nfs04$PID.testdir
    LUSER=${LUSER:=root}
    mkdir -p $TCtmp || end_testcase "Could not create $TCtmp"
    chmod 777 $TCtmp

    tst_resm TINFO "Setting up remote machine: $RHOST"
    rsh -n $RHOST "mkdir -p /mnt/nfs04$PID.testdir"
    [ $? = 0 ] || end_testcase "Could not create remote directory"
    rsh -n $RHOST "touch /mnt/nfs04$PID.testdir/testfile"
    [ $? = 0 ] || end_testcase "Could not create testfile in remote directory"
    rsh -n $RHOST "/usr/sbin/exportfs -i -o no_root_squash,rw *:/mnt/nfs04$PID.testdir"
    [ $? = 0 ] || end_testcase "Could export remote directory"

    tst_resm TINFO "Mounting NFS filesystem"
    mount -o proto=$SOCKET_TYPE$OPTS $REMOTE_DIR $TCtmp || end_testcase "Cannot mount $TCtmp" 
    [ $? = 0 ] || end_testcase "Could not mount $REMOTE_DIR"
}


#=============================================================================
# FUNCTION NAME:        do_test
#
# FUNCTION DESCRIPTION: Perform the test
#
# PARAMETERS:   	None.
#
# RETURNS:      	None.
#=============================================================================
do_test()
{
$trace_logic
  loopcount=0
  create_file $FILESIZE /tmp/nfs04$PID.testfile >/dev/null
  if [ $? != 0 ]; then
	end_testcase "Could not create testfile"
  fi
  tst_resm TINFO "Test Started"
  while [ $loopcount -lt $LOOPS ]
    do
	cp /tmp/nfs04$PID.testfile $TCtmp/nfs04$PID.testfile$loopcount	
	diff /tmp/nfs04$PID.testfile $TCtmp/nfs04$PID.testfile$loopcount
	retval=$?
	if [ "$retval" != 0 ]; then
		end_testcase "Error in loop $loopcount: First Diff FAILED"
	fi
	cp $TCtmp/nfs04$PID.testfile$loopcount /tmp/nfs04$PID.testfile_compare	
	diff /tmp/nfs04$PID.testfile /tmp/nfs04$PID.testfile_compare
	retval=$?
	if [ "$retval" != 0 ]; then
		end_testcase "Error in loop $loopcount: Second Diff FAILED"
	fi
	rm -f /tmp/nfs04$PID.testfile_compare
	loopcount=$(( $loopcount + 1 ))
	tst_resm TINFO "Completed Loop $loopcount"
    done
}


#=============================================================================
# FUNCTION NAME:        end_testcase
#
# FUNCTION DESCRIPTION: Clean up
#
# PARAMETERS:   	None.
#
# RETURNS:      	None.
#=============================================================================
end_testcase()
{
$trace_logic
    if [ "$CLEANUP" = "ON" ]; then
	sleep 2
        umount $TCtmp || tst_resm TBROK "Cannot umount $TCtmp"
	rm -rf $TCtmp || tst_resm TBROK "Cannot remove $TCtmp"
        rsh -n $RHOST "/usr/sbin/exportfs -u *:/mnt/nfs04$PID.testdir"
	rsh -n $RHOST "rm -rf /mnt/nfs04$PID.testdir"
	rm -f /tmp/nfs04$PID.testfile*
    fi

    [ $# = 0 ] && { tst_resm TPASS "Test Successful"; exit 0; }
    tst_resm TFAIL "Test Failed: $@@"
    exit 1
}

#=============================================================================
# MAIN PROCEDURE
#=============================================================================

setup_testcase
do_test
end_testcase
@


1.1.1.1
log
@Initial import of the Linux Test Project (http://ltp.sourceforge.net).

This import is minus the Posix test suite, which will be imported separately,
and the HPI suite, which doesn't concern us.
@
text
@@
