Skip to content

Commit 99fd2a1

Browse files
committed
net/sendfile01.sh: Rewrite into new API
* reduce sleep to 1s (from 10s) * continue testing on size failure Reviewed-by: Alexey Kodanev <[email protected]> Signed-off-by: Petr Vorel <[email protected]>
1 parent 88e2f2b commit 99fd2a1

File tree

1 file changed

+28
-86
lines changed

1 file changed

+28
-86
lines changed
Lines changed: 28 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,53 @@
11
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0-or-later
3+
# Copyright (c) 2020 Petr Vorel <[email protected]>
24
# Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved.
5+
# Copyright (c) Linux Test Project, 2001-2013
6+
# Copyright (c) Manoj Iyer <[email protected]> 2003
7+
# Copyright (c) Robbie Williamson <[email protected]> 2002-2003
38
# 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 [email protected]
29-
# - Modified to use LTP APIs, and added check to if commands used in test
30-
# exists.
31-
# 03/01 Robbie Williamson ([email protected])
32-
# -Ported
33-
#
34-
#
35-
#***********************************************************************
369

37-
TST_TOTAL=1
38-
TCID="sendfile01"
10+
TST_SETUP=do_setup
3911
TST_CLEANUP=do_cleanup
12+
TST_TESTFUNC=do_test
13+
TST_NEEDS_TMPDIR=1
14+
TST_NEEDS_CMDS="diff stat"
15+
. tst_net.sh
4016

4117
do_setup()
4218
{
43-
TCdat=${TCdat:-$LTPROOT/testcases/bin/datafiles}
4419

45-
CLIENT="testsf_c${TST_IPV6}"
46-
SERVER="testsf_s${TST_IPV6}"
20+
tst_res TINFO "copy files from server to client using the sendfile() on IPv$TST_IPVER"
4721

48-
FILES=${FILES:-"ascii.sm ascii.med ascii.lg ascii.jmb"}
22+
client="testsf_c${TST_IPV6}"
23+
server="testsf_s${TST_IPV6}"
4924

50-
tst_require_cmds diff stat
25+
port=$(tst_rhost_run -s -c "tst_get_unused_port ipv$TST_IPVER stream")
26+
[ -z "$port" ] && tst_brk TBROK "failed to get unused port"
5127

52-
tst_tmpdir
28+
tst_rhost_run -s -b -c "$server $(tst_ipaddr rhost) $port"
29+
server_started=1
30+
tst_res TINFO "wait for the server to start"
31+
sleep 1
5332
}
5433

5534
do_test()
5635
{
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)
36+
local file lfile size
7137

72-
tst_resm TINFO \
73-
"$CLIENT ip '$ipaddr' port '$port' file '$clnt_fname'"
38+
for file in $(ls $TST_NET_DATAROOT/ascii.*); do
39+
lfile="$(basename $file)"
40+
size=$(stat -c '%s' $file)
41+
tst_res TINFO "test IP: $(tst_ipaddr rhost), port: $port, file: $lfile"
7442

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
43+
ROD $client $(tst_ipaddr rhost) $port $lfile $file $size \> /dev/null
44+
EXPECT_PASS diff $file $lfile
9545
done
96-
tst_resm TPASS "test finished successfully"
9746
}
9847

9948
do_cleanup()
10049
{
101-
[ -n "$server_started" ] && tst_rhost_run -c "pkill $SERVER"
102-
tst_rmdir
50+
[ -n "$server_started" ] && tst_rhost_run -c "pkill $server"
10351
}
10452

105-
TST_USE_LEGACY_API=1
106-
. tst_net.sh
107-
108-
do_setup
109-
do_test
110-
111-
tst_exit
53+
tst_run

0 commit comments

Comments
 (0)