Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/tests/sys/kern/sendfile_test.sh
39536 views
1
# SPDX-License-Identifier: BSD-2-Clause
2
#
3
# Copyright (c) 2020 Netflix, Inc.
4
#
5
# Redistribution and use in source and binary forms, with or without
6
# modification, are permitted provided that the following conditions
7
# are met:
8
# 1. Redistributions of source code must retain the above copyright
9
# notice, this list of conditions and the following disclaimer.
10
# 2. Redistributions in binary form must reproduce the above copyright
11
# notice, this list of conditions and the following disclaimer in the
12
# documentation and/or other materials provided with the distribution.
13
#
14
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
# SUCH DAMAGE.
25
#
26
27
#
28
# These tests exercise a few basic cases for the sendfile() syscall:
29
# - successful operation.
30
# - sendfile() starts an async disk read but that async I/O fails.
31
# - sendfile() fails to read an indirect block and thus cannot
32
# even start an async I/O.
33
#
34
# In all cases we request some read ahead in addition to
35
# the data to be sent to the socket.
36
#
37
38
MD_DEVS="md.devs"
39
MNT=mnt
40
FILE=$MNT/file
41
HELPER="$(atf_get_srcdir)/sendfile_helper"
42
BSIZE=4096
43
44
atf_test_case io_success cleanup
45
io_success_head()
46
{
47
atf_set "descr" "sendfile where all disk I/O succeeds"
48
atf_set "require.user" "root"
49
atf_set "timeout" 15
50
}
51
io_success_body()
52
{
53
if [ "$(atf_config_get qemu false)" = "true" ]; then
54
atf_skip "Sendfile(4) unimplemented. https://github.com/qemu-bsd-user/qemu-bsd-user/issues/25"
55
fi
56
57
alloc_md md
58
common_body_setup $md
59
60
atf_check $HELPER $FILE 0 0x10000 0x10000
61
}
62
io_success_cleanup()
63
{
64
common_cleanup
65
}
66
67
atf_test_case io_fail_sync cleanup
68
io_fail_sync_head()
69
{
70
atf_set "descr" "sendfile where we fail to start async I/O"
71
atf_set "require.user" "root"
72
atf_set "timeout" 15
73
}
74
io_fail_sync_body()
75
{
76
if [ "$(atf_config_get qemu false)" = "true" ]; then
77
atf_skip "Sendfile(4) unimplemented. https://github.com/qemu-bsd-user/qemu-bsd-user/issues/25"
78
fi
79
80
alloc_md md
81
common_body_setup $md
82
83
atf_check gnop configure -r 100 -e 5 ${md}.nop
84
atf_check -s exit:3 -e ignore $HELPER $FILE $((12 * $BSIZE)) $BSIZE 0x10000
85
}
86
io_fail_sync_cleanup()
87
{
88
common_cleanup
89
}
90
91
atf_test_case io_fail_async cleanup
92
io_fail_async_head()
93
{
94
atf_set "descr" "sendfile where an async I/O fails"
95
atf_set "require.user" "root"
96
atf_set "timeout" 15
97
}
98
io_fail_async_body()
99
{
100
if [ "$(atf_config_get qemu false)" = "true" ]; then
101
atf_skip "Sendfile(4) unimplemented. https://github.com/qemu-bsd-user/qemu-bsd-user/issues/25"
102
fi
103
104
alloc_md md
105
common_body_setup $md
106
107
atf_check gnop configure -r 100 -e 5 ${md}.nop
108
atf_check -s exit:2 -e ignore $HELPER $FILE 0 $BSIZE 0x10000
109
}
110
io_fail_async_cleanup()
111
{
112
common_cleanup
113
}
114
115
atf_test_case unix_success cleanup
116
unix_success_head()
117
{
118
atf_set "descr" "sendfile via unix(4) where all disk I/O succeeds"
119
atf_set "require.user" "root"
120
atf_set "timeout" 15
121
}
122
unix_success_body()
123
{
124
if [ "$(atf_config_get qemu false)" = "true" ]; then
125
atf_skip "Sendfile(4) unimplemented. https://github.com/qemu-bsd-user/qemu-bsd-user/issues/25"
126
fi
127
128
alloc_md md
129
common_body_setup $md
130
131
atf_check $HELPER -u $FILE 0 0x10000 0x10000
132
}
133
unix_success_cleanup()
134
{
135
common_cleanup
136
}
137
138
139
atf_init_test_cases()
140
{
141
atf_add_test_case io_success
142
atf_add_test_case io_fail_sync
143
atf_add_test_case io_fail_async
144
atf_add_test_case unix_success
145
}
146
147
alloc_md()
148
{
149
local _md
150
151
[ -c /dev/mdctl ] || atf_skip "no /dev/mdctl to create md devices"
152
_md=$(mdconfig -a -t swap -s 256M) || atf_fail "mdconfig -a failed"
153
echo ${_md} >> $MD_DEVS
154
eval "${1}='${_md}'"
155
}
156
157
common_body_setup()
158
{
159
us=$1
160
161
atf_check mkdir $MNT
162
atf_check -o ignore -e ignore newfs -b $BSIZE -U -j /dev/${us}
163
atf_check mount /dev/${us} $MNT
164
atf_check -e ignore dd if=/dev/zero of=$FILE bs=1m count=1
165
atf_check umount $MNT
166
167
load_gnop
168
atf_check gnop create /dev/${us}
169
atf_check mount /dev/${us}.nop $MNT
170
atf_check -o ignore ls -l $MNT/file
171
}
172
173
common_cleanup()
174
{
175
umount -f $MNT
176
if [ -f "$MD_DEVS" ]; then
177
while read test_md; do
178
gnop destroy -f ${test_md}.nop 2>/dev/null
179
mdconfig -d -u $test_md 2>/dev/null
180
done < $MD_DEVS
181
rm $MD_DEVS
182
fi
183
184
true
185
}
186
187
load_gnop()
188
{
189
if ! kldstat -q -m g_nop; then
190
geom nop load || atf_skip "could not load module for geom nop"
191
fi
192
}
193
194