1#!/bin/sh 2# Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved. 3# Copyright (c) International Business Machines Corp., 2000 4# 5# This program is free software; you can redistribute it and/or 6# modify it under the terms of the GNU General Public License as 7# published by the Free Software Foundation; either version 2 of 8# the License, or (at your option) any later version. 9# 10# This program is distributed in the hope that it would be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# 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 the Free Software Foundation, 17# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18# 19# PURPOSE: Copy files from server to client using the sendfile() 20# function. 21# 22# 23# SETUP: The home directory of root on the machine exported as "RHOST" 24# MUST have a ".rhosts" file with the hostname of the client 25# machine, where the test is executed. 26# 27# HISTORY: 28# 06/09/2003 Manoj Iyer manjo@mail.utexas.edu 29# - Modified to use LTP APIs, and added check to if commands used in test 30# exists. 31# 03/01 Robbie Williamson (robbiew@us.ibm.com) 32# -Ported 33# 34# 35#*********************************************************************** 36 37TST_TOTAL=1 38TCID="sendfile01" 39TST_CLEANUP=do_cleanup 40 41do_setup() 42{ 43 TCdat=${TCdat:-$LTPROOT/testcases/bin/datafiles} 44 45 CLIENT="testsf_c${TST_IPV6}" 46 SERVER="testsf_s${TST_IPV6}" 47 48 FILES=${FILES:-"ascii.sm ascii.med ascii.lg ascii.jmb"} 49 50 tst_require_cmds diff stat 51 52 tst_tmpdir 53} 54 55do_test() 56{ 57 tst_resm TINFO "Doing $0." 58 59 local ipv="ipv${TST_IPV6:-"4"}" 60 local ipaddr=$(tst_ipaddr rhost) 61 local port=$(tst_rhost_run -s -c "tst_get_unused_port $ipv stream") 62 [ -z "$port" ] && tst_brkm TBROK "failed to get unused port" 63 64 tst_rhost_run -s -b -c "$SERVER $ipaddr $port" 65 server_started=1 66 sleep 10 67 68 for clnt_fname in $FILES; do 69 serv_fname=${TCdat}/$clnt_fname 70 local size=$(stat -c '%s' $serv_fname) 71 72 tst_resm TINFO \ 73 "$CLIENT ip '$ipaddr' port '$port' file '$clnt_fname'" 74 75 $CLIENT $ipaddr $port $clnt_fname $serv_fname $size >\ 76 /dev/null 2>&1 77 78 local ret=$? 79 if [ $ret -ne 0 ]; then 80 tst_resm TFAIL "$CLIENT returned error '$ret'" 81 return; 82 fi 83 84 diff $serv_fname $clnt_fname > /dev/null 2>&1 85 local diff_res=$? 86 if [ $diff_res -gt 1 ]; then 87 tst_resm TFAIL "ERROR: Cannot compare files" 88 return 89 fi 90 91 if [ $diff_res -eq 1 ]; then 92 tst_resm TFAIL "The file copied differs from the original" 93 return 94 fi 95 done 96 tst_resm TPASS "test finished successfully" 97} 98 99do_cleanup() 100{ 101 [ -n "$server_started" ] && tst_rhost_run -s -c "pkill $SERVER" 102 tst_rmdir 103} 104 105TST_USE_LEGACY_API=1 106. tst_net.sh 107 108do_setup 109do_test 110 111tst_exit 112