Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/tests/sys/geom/class/gate/ggate_test.sh
39638 views
1
PIDFILE=ggated.pid
2
PLAINFILES=plainfiles
3
CONF=gg.exports
4
5
atf_test_case ggatec_trim cleanup
6
ggatec_trim_head()
7
{
8
atf_set "descr" "ggatec survives a trim"
9
atf_set "require.progs" "ggatec"
10
atf_set "require.user" "root"
11
atf_set "timeout" 60
12
}
13
14
ggatec_trim_body()
15
{
16
load_ggate
17
18
port=33080
19
us=$(alloc_ggate_dev)
20
work=$(alloc_md)
21
atf_check -e ignore -o ignore dd if=/dev/random of=/dev/$work bs=1m count=1 conv=notrunc
22
echo $CONF >> $PLAINFILES
23
echo "localhost RW /dev/$work" > $CONF
24
atf_check ggated -p $port -F $PIDFILE $CONF
25
atf_check ggatec create -p $port -u $us localhost /dev/$work
26
ggate_dev=/dev/ggate${us}
27
wait_for_ggate_device ${ggate_dev}
28
29
# ggatec only supports read or write.
30
atf_check -s not-exit:0 -e ignore -o ignore trim -q -f ${ggate_dev}
31
}
32
33
ggatec_trim_cleanup()
34
{
35
common_cleanup
36
}
37
38
39
atf_test_case ggated cleanup
40
ggated_head()
41
{
42
atf_set "descr" "ggated can proxy geoms"
43
atf_set "require.progs" "ggatec ggated"
44
atf_set "require.user" "root"
45
atf_set "timeout" 60
46
}
47
48
ggated_body()
49
{
50
if [ "$(atf_config_get ci false)" = "true" ] && \
51
[ "$(uname -p)" = "i386" ]; then
52
atf_skip "https://bugs.freebsd.org/244737"
53
fi
54
55
load_ggate
56
57
port=33081
58
us=$(alloc_ggate_dev)
59
work=$(alloc_md)
60
src=$(alloc_md)
61
62
atf_check -e ignore -o ignore \
63
dd if=/dev/random of=/dev/$work bs=1m count=1 conv=notrunc
64
atf_check -e ignore -o ignore \
65
dd if=/dev/random of=/dev/$src bs=1m count=1 conv=notrunc
66
67
echo $CONF >> $PLAINFILES
68
echo "127.0.0.1 RW /dev/$work" > $CONF
69
70
atf_check ggated -p $port -F $PIDFILE $CONF
71
atf_check ggatec create -p $port -u $us 127.0.0.1 /dev/$work
72
73
ggate_dev=/dev/ggate${us}
74
75
wait_for_ggate_device ${ggate_dev}
76
77
atf_check -e ignore -o ignore \
78
dd if=/dev/${src} of=${ggate_dev} bs=1m count=1 conv=notrunc
79
80
checksum /dev/$src /dev/$work
81
}
82
83
ggated_cleanup()
84
{
85
common_cleanup
86
}
87
88
atf_test_case ggatel_file cleanup
89
ggatel_file_head()
90
{
91
atf_set "descr" "ggatel can proxy files"
92
atf_set "require.progs" "ggatel"
93
atf_set "require.user" "root"
94
atf_set "timeout" 15
95
}
96
97
ggatel_file_body()
98
{
99
load_ggate
100
101
us=$(alloc_ggate_dev)
102
103
echo src work >> ${PLAINFILES}
104
dd if=/dev/random of=work bs=1m count=1
105
dd if=/dev/random of=src bs=1m count=1
106
107
atf_check ggatel create -u $us work
108
109
ggate_dev=/dev/ggate${us}
110
111
wait_for_ggate_device ${ggate_dev}
112
113
atf_check -e ignore -o ignore \
114
dd if=src of=${ggate_dev} bs=1m count=1 conv=notrunc
115
116
checksum src work
117
}
118
119
ggatel_file_cleanup()
120
{
121
common_cleanup
122
}
123
124
atf_test_case ggatel_md cleanup
125
ggatel_md_head()
126
{
127
atf_set "descr" "ggatel can proxy files"
128
atf_set "require.progs" "ggatel"
129
atf_set "require.user" "root"
130
atf_set "timeout" 15
131
}
132
133
ggatel_md_body()
134
{
135
load_ggate
136
137
us=$(alloc_ggate_dev)
138
work=$(alloc_md)
139
src=$(alloc_md)
140
141
atf_check -e ignore -o ignore \
142
dd if=/dev/random of=$work bs=1m count=1 conv=notrunc
143
atf_check -e ignore -o ignore \
144
dd if=/dev/random of=$src bs=1m count=1 conv=notrunc
145
146
atf_check ggatel create -u $us /dev/$work
147
148
ggate_dev=/dev/ggate${us}
149
150
wait_for_ggate_device ${ggate_dev}
151
152
atf_check -e ignore -o ignore \
153
dd if=/dev/$src of=${ggate_dev} bs=1m count=1 conv=notrunc
154
155
checksum /dev/$src /dev/$work
156
}
157
158
ggatel_md_cleanup()
159
{
160
common_cleanup
161
}
162
163
atf_init_test_cases()
164
{
165
atf_add_test_case ggated
166
atf_add_test_case ggatel_file
167
atf_add_test_case ggatel_md
168
atf_add_test_case ggatec_trim
169
}
170
171
alloc_ggate_dev()
172
{
173
local us
174
175
us=0
176
while [ -c /dev/ggate${us} ]; do
177
: $(( us += 1 ))
178
done
179
echo ${us} > ggate.devs
180
echo ${us}
181
}
182
183
alloc_md()
184
{
185
local md
186
187
md=$(mdconfig -a -t malloc -s 1M) || \
188
atf_fail "failed to allocate md device"
189
echo ${md} >> md.devs
190
echo ${md}
191
}
192
193
checksum()
194
{
195
local src work
196
src=$1
197
work=$2
198
199
src_checksum=$(md5 -q $src)
200
work_checksum=$(md5 -q $work)
201
202
if [ "$work_checksum" != "$src_checksum" ]; then
203
atf_fail "work md5 checksum didn't match"
204
fi
205
206
ggate_checksum=$(md5 -q /dev/ggate${us})
207
if [ "$ggate_checksum" != "$src_checksum" ]; then
208
atf_fail "ggate md5 checksum didn't match"
209
fi
210
}
211
212
common_cleanup()
213
{
214
if [ -f "ggate.devs" ]; then
215
while read test_ggate; do
216
ggatec destroy -f -u $test_ggate >/dev/null
217
done < ggate.devs
218
rm ggate.devs
219
fi
220
221
if [ -f "$PIDFILE" ]; then
222
pkill -F "$PIDFILE"
223
rm $PIDFILE
224
fi
225
226
if [ -f "PLAINFILES" ]; then
227
while read f; do
228
rm -f ${f}
229
done < ${PLAINFILES}
230
rm ${PLAINFILES}
231
fi
232
233
if [ -f "md.devs" ]; then
234
while read test_md; do
235
# ggatec destroy doesn't release the provider
236
# synchronously, so we may need to retry destroying it.
237
while ! mdconfig -d -u $test_md; do
238
sleep 0.1
239
done
240
done < md.devs
241
rm md.devs
242
fi
243
true
244
}
245
246
load_ggate()
247
{
248
local class=gate
249
250
# If the geom class isn't already loaded, try loading it.
251
if ! kldstat -q -m g_${class}; then
252
if ! geom ${class} load; then
253
atf_skip "could not load module for geom class=${class}"
254
fi
255
fi
256
}
257
258
# Bug 204616: ggatel(8) creates /dev/ggate* asynchronously if `ggatel create`
259
# isn't called with `-v`.
260
wait_for_ggate_device()
261
{
262
ggate_device=$1
263
264
while [ ! -c $ggate_device ]; do
265
sleep 0.5
266
done
267
}
268
269