|
1 | 1 | #!/bin/sh |
| 2 | +# SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | +# Copyright (c) 2020 Petr Vorel <pvorel@suse.cz> |
2 | 4 | # Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved. |
| 5 | +# Copyright (c) Linux Test Project, 2001-2013 |
| 6 | +# Copyright (c) Manoj Iyer <manjo@mail.utexas.edu> 2003 |
| 7 | +# Copyright (c) Robbie Williamson <robbiew@us.ibm.com> 2002-2003 |
3 | 8 | # 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 | 9 |
|
37 | | -TST_TOTAL=1 |
38 | | -TCID="sendfile01" |
| 10 | +TST_SETUP=do_setup |
39 | 11 | TST_CLEANUP=do_cleanup |
| 12 | +TST_TESTFUNC=do_test |
| 13 | +TST_NEEDS_TMPDIR=1 |
| 14 | +TST_NEEDS_CMDS="diff stat" |
| 15 | +. tst_net.sh |
40 | 16 |
|
41 | 17 | do_setup() |
42 | 18 | { |
43 | | - TCdat=${TCdat:-$LTPROOT/testcases/bin/datafiles} |
44 | 19 |
|
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" |
47 | 21 |
|
48 | | - FILES=${FILES:-"ascii.sm ascii.med ascii.lg ascii.jmb"} |
| 22 | + client="testsf_c${TST_IPV6}" |
| 23 | + server="testsf_s${TST_IPV6}" |
49 | 24 |
|
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" |
51 | 27 |
|
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 |
53 | 32 | } |
54 | 33 |
|
55 | 34 | do_test() |
56 | 35 | { |
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 |
71 | 37 |
|
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" |
74 | 42 |
|
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 |
95 | 45 | done |
96 | | - tst_resm TPASS "test finished successfully" |
97 | 46 | } |
98 | 47 |
|
99 | 48 | do_cleanup() |
100 | 49 | { |
101 | | - [ -n "$server_started" ] && tst_rhost_run -c "pkill $SERVER" |
102 | | - tst_rmdir |
| 50 | + [ -n "$server_started" ] && tst_rhost_run -c "pkill $server" |
103 | 51 | } |
104 | 52 |
|
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