Fix some paths in Debian
[ltp-debian.git] / testcases / network / tcp_cmds / sendfile / sendfile01
blob879a9398916a51f6f2d3ea40473efeb7c803b517
1 #!/bin/sh
3 # Copyright (c) International Business Machines Corp., 2000
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.
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.
15 # You should have received a copy of the GNU General Public License
16 # along with this pronram; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # FILE : sendfile
23 # PURPOSE: Copy files from server to client using the sendfile()
24 # function.
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.
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
39 #***********************************************************************
41 PATH=$PATH:$LTPTOOLS
43 #-----------------------------------------------------------------------
45 # FUNCTION: exists
47 # DESCRIPTION: Check if required commands exits.
49 #-----------------------------------------------------------------------
51 do_setup()
53 TC=sendfile01
54 RHOST=${RHOST:-`hostname`}
55 TCdat=${TCdat:-$LTPROOT/testcases/bin/datafiles}
56 TMPDIR=${TMPDIR:-/tmp}
57 TCtmp=${TCtmp:-$TMPDIR/$TC${EXEC_SUFFIX}$$}
58 CLIENT="testsf_c${EXEC_SUFFIX}"
59 SERVER="testsf_s${EXEC_SUFFIX}"
60 LTPROOT=${LTPROOT:-../../../..}
61 FILES=${FILES:-"ascii.sm ascii.med ascii.lg ascii.jmb"}
63 tst_setup
65 exists awk diff gethost grep rsh stat
67 IPADDR=$(gethost $RHOST | awk '/addresses:/ {print $2}')
72 #=============================================================================
73 # FUNCTION NAME: do_test
75 # FUNCTION DESCRIPTION: Perform the test
77 # PARAMETERS: None.
79 # RETURNS: None.
80 #=============================================================================
81 do_test()
83 tst_resm TINFO "Doing $0."
85 mkdir -p $TCtmp
86 PORT=$$
87 if ! rsh -l root $IPADDR "$LTPROOT/testcases/bin/SF_Server $IPADDR $PORT $LTPROOT/testcases/bin"; then
88 end_testcase "rsh failed to $IPADDR as root failed"
90 sleep 10
91 PID=$(rsh -l root $IPADDR "ps -ef" | awk "\$0 !~ /awk/ && /$SERVER/ && /$PORT/ {print \$1}")
92 [ -n "$PID" ] || end_testcase "Could not start server"
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 "
99 $CLIENT $IPADDR $PORT "$TCtmp/$clnt_fname" $serv_fname $SIZE
100 RetVal=$?
102 [ $RetVal -eq 0 ] || end_testcase "$CLIENT returned error $RetVal"
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
112 #=============================================================================
113 # FUNCTION NAME: do_cleanup
115 # FUNCTION DESCRIPTION: Clean up
117 # PARAMETERS: None.
119 # RETURNS: None.
120 #=============================================================================
122 do_cleanup()
124 PID=$(rsh -n -l root $RHOST "ps -ef" | awk "\$0 !~ /awk/ && /$SERVER/ && /$PORT/ {print \$1}")
125 [ -n "$PID" ] && rsh -n -l root $RHOST kill -9 $PID
126 tst_cleanup
129 #=============================================================================
130 # MAIN PROCEDURE
131 #=============================================================================
132 . net_cmdlib.sh
134 read_opts $*
135 do_setup
136 do_test
137 end_testcase