sendfile01 revision 4716af77488c50bb0bf929d68e105a0b619c541d
1#!/bin/sh 2# 3# Copyright (c) International Business Machines Corp., 2000 4# 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation; either version 2 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13# the GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program; if not, write to the Free Software 17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18# 19# 20# 21# FILE : sendfile 22# 23# PURPOSE: Copy files from server to client using the sendfile() 24# function. 25# 26# 27# SETUP: The home directory of root on the machine exported as "RHOST" 28# MUST have a ".rhosts" file with the hostname of the client 29# machine, where the test is executed. 30# 31# HISTORY: 32# 06/09/2003 Manoj Iyer manjo@mail.utexas.edu 33# - Modified to use LTP APIs, and added check to if commands used in test 34# exists. 35# 03/01 Robbie Williamson (robbiew@us.ibm.com) 36# -Ported 37# 38# 39#*********************************************************************** 40 41#----------------------------------------------------------------------- 42# 43# FUNCTION: exists 44# 45# DESCRIPTION: Check if required commands exits. 46# 47#----------------------------------------------------------------------- 48 49do_setup() 50{ 51 TC=sendfile01 52 RHOST=${RHOST:-`hostname`} 53 TCdat=${TCdat:-$LTPROOT/testcases/bin/datafiles} 54 TCtmp=${TCtmp:-$LTPROOT/testcases/bin/$TC${EXEC_SUFFIX}$$} 55 CLIENT="testsf_c${EXEC_SUFFIX}" 56 SERVER="testsf_s${EXEC_SUFFIX}" 57 LTPROOT=${LTPROOT:-../../../..} 58 FILES=${FILES:-"ascii.sm ascii.med ascii.lg ascii.jmb"} 59 60 tst_setup 61 62 exists awk diff gethost grep rsh stat 63 64 if ! IPADDR=$(gethost ${EXEC_SUFFIX:+6} $RHOST | awk 'BEGIN { ec=1 } /addresses:/ {print $2; ec=0 } END { exit ec }'); then 65 # XXX (garrcoop): || exit 1 is there to prevent the test from hanging in the event of an install error. 66 end_testcase "Failed to determine the appropriate IP address for the machine." || exit 1 67 fi 68 69} 70 71 72#============================================================================= 73# FUNCTION NAME: do_test 74# 75# FUNCTION DESCRIPTION: Perform the test 76# 77# PARAMETERS: None. 78# 79# RETURNS: None. 80#============================================================================= 81do_test() 82{ 83 tst_resm TINFO "Doing $0." 84 85 mkdir -p $TCtmp 86 PORT=$$ 87 if ! rsh -l root $IPADDR "$LTPROOT/testcases/bin/sendfile01_server $IPADDR $PORT $LTPROOT/testcases/bin $SERVER"; then 88 end_testcase "rsh failed to $IPADDR as root failed" 89 fi 90 sleep 10 91 PID=$(rsh -l root $IPADDR "ps -ef" | awk "\$0 !~ /awk/ && /$SERVER/ && /$PORT/ {print \$2}") 92 [ -n "$PID" ] || end_testcase "Could not start server" 93 94 for clnt_fname in $FILES; do 95 serv_fname=$TCdat/$clnt_fname 96 SIZE=`stat -c '%s' $serv_fname` 97 tst_resm TINFO "Starting $SERVER $IPADDR Client_filename Server_filename Size " 98 99 $CLIENT $IPADDR $PORT "$TCtmp/$clnt_fname" $serv_fname $SIZE 100 RetVal=$? 101 102 [ $RetVal -eq 0 ] || end_testcase "$CLIENT returned error $RetVal" 103 104 diff $serv_fname $TCtmp/$clnt_fname 105 DiffVal=$? 106 [ $DiffVal -gt 1 ] && end_testcase "ERROR: Cannot compare files" 107 [ $DiffVal -eq 1 ] && end_testcase "The file copied differs from the original" 108 done 109 110} 111 112#============================================================================= 113# FUNCTION NAME: do_cleanup 114# 115# FUNCTION DESCRIPTION: Clean up 116# 117# PARAMETERS: None. 118# 119# RETURNS: None. 120#============================================================================= 121 122do_cleanup() 123{ 124 PID=$(rsh -n -l root $RHOST "ps -eopid,cmd" | awk "\$0 !~ /awk/ && /$SERVER/ && /$PORT/ {print \$1}") 125 [ -n "$PID" ] && rsh -n -l root $RHOST kill -9 $PID 126 tst_cleanup 127} 128 129#============================================================================= 130# MAIN PROCEDURE 131#============================================================================= 132. net_cmdlib.sh 133 134read_opts $* 135do_setup 136do_test 137end_testcase 138