]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - tests/sys/geom/class/gate/ggate_test.sh
MFC r311893, r313008, r313081
[FreeBSD/stable/10.git] / tests / sys / geom / class / gate / ggate_test.sh
1 # $FreeBSD$
2
3 PIDFILE=ggated.pid
4 PLAINFILES=plainfiles
5 PORT=33080
6 CONF=gg.exports
7
8 atf_test_case ggated cleanup
9 ggated_head()
10 {
11         atf_set "descr" "ggated can proxy geoms"
12         atf_set "require.progs" "ggatec ggated"
13         atf_set "require.user" "root"
14         atf_set "timeout" 60
15 }
16
17 ggated_body()
18 {
19         us=$(alloc_ggate_dev)
20         work=$(alloc_md)
21         src=$(alloc_md)
22
23         atf_check -e ignore -o ignore \
24             dd if=/dev/random of=/dev/$work bs=1m count=1 conv=notrunc
25         atf_check -e ignore -o ignore \
26             dd if=/dev/random of=/dev/$src bs=1m count=1 conv=notrunc
27
28         echo $CONF >> $PLAINFILES
29         echo "127.0.0.1 RW /dev/$work" > $CONF
30
31         atf_check ggated -p $PORT -F $PIDFILE $CONF
32         atf_check ggatec create -p $PORT -u $us 127.0.0.1 /dev/$work
33
34         ggate_dev=/dev/ggate${us}
35
36         wait_for_ggate_device ${ggate_dev}
37
38         atf_check -e ignore -o ignore \
39             dd if=/dev/${src} of=${ggate_dev} bs=1m count=1 conv=notrunc
40
41         checksum /dev/$src /dev/$work
42 }
43
44 ggated_cleanup()
45 {
46         common_cleanup
47 }
48
49 atf_test_case ggatel_file cleanup
50 ggatel_file_head()
51 {
52         atf_set "descr" "ggatel can proxy files"
53         atf_set "require.progs" "ggatel"
54         atf_set "require.user" "root"
55         atf_set "timeout" 15
56 }
57
58 ggatel_file_body()
59 {
60         us=$(alloc_ggate_dev)
61
62         echo src work >> ${PLAINFILES}
63         dd if=/dev/random of=work bs=1m count=1
64         dd if=/dev/random of=src bs=1m count=1
65
66         atf_check ggatel create -u $us work
67
68         ggate_dev=/dev/ggate${us}
69
70         wait_for_ggate_device ${ggate_dev}
71
72         atf_check -e ignore -o ignore \
73             dd if=src of=${ggate_dev} bs=1m count=1 conv=notrunc
74
75         checksum src work
76 }
77
78 ggatel_file_cleanup()
79 {
80         common_cleanup
81 }
82
83 atf_test_case ggatel_md cleanup
84 ggatel_md_head()
85 {
86         atf_set "descr" "ggatel can proxy files"
87         atf_set "require.progs" "ggatel"
88         atf_set "require.user" "root"
89         atf_set "timeout" 15
90 }
91
92 ggatel_md_body()
93 {
94         us=$(alloc_ggate_dev)
95         work=$(alloc_md)
96         src=$(alloc_md)
97
98         atf_check -e ignore -o ignore \
99             dd if=/dev/random of=$work bs=1m count=1 conv=notrunc
100         atf_check -e ignore -o ignore \
101             dd if=/dev/random of=$src bs=1m count=1 conv=notrunc
102
103         atf_check ggatel create -u $us /dev/$work
104
105         ggate_dev=/dev/ggate${us}
106
107         wait_for_ggate_device ${ggate_dev}
108
109         atf_check -e ignore -o ignore \
110             dd if=/dev/$src of=${ggate_dev} bs=1m count=1 conv=notrunc
111
112         checksum /dev/$src /dev/$work
113 }
114
115 ggatel_md_cleanup()
116 {
117         common_cleanup
118 }
119
120 atf_init_test_cases()
121 {
122         atf_add_test_case ggated
123         atf_add_test_case ggatel_file
124         atf_add_test_case ggatel_md
125 }
126
127 alloc_ggate_dev()
128 {
129         local us
130
131         us=0
132         while [ -c /dev/ggate${us} ]; do
133                 : $(( us += 1 ))
134         done
135         echo ${us} > ggate.devs
136         echo ${us}
137 }
138
139 alloc_md()
140 {
141         local md
142
143         md=$(mdconfig -a -t malloc -s 1M) || \
144                 atf_fail "failed to allocate md device"
145         echo ${md} >> md.devs
146         echo ${md}
147 }
148
149 checksum()
150 {
151         local src work
152         src=$1
153         work=$2
154
155         src_checksum=$(dd if=${src} bs=1m | md5 -q)
156         work_checksum=$(dd if=${work} bs=1m | md5 -q)
157
158         if [ "$work_checksum" != "$src_checksum" ]; then
159                 atf_fail "work md5 checksum didn't match"
160         fi
161
162         ggate_checksum=$(dd if=/dev/ggate${us} bs=1m | md5 -q)
163         if [ "$ggate_checksum" != "$src_checksum" ]; then
164                 atf_fail "ggate md5 checksum didn't match"
165         fi
166 }
167
168 common_cleanup()
169 {
170         if [ -f "ggate.devs" ]; then
171                 while read test_ggate; do
172                         ggatec destroy -f -u $test_ggate >/dev/null
173                 done < ggate.devs
174                 rm ggate.devs
175         fi
176
177         if [ -f "$PIDFILE" ]; then
178                 pkill -F "$PIDFILE"
179                 rm $PIDFILE
180         fi
181
182         if [ -f "PLAINFILES" ]; then
183                 while read f; do
184                         rm -f ${f}
185                 done < ${PLAINFILES}
186                 rm ${PLAINFILES}
187         fi
188
189         if [ -f "md.devs" ]; then
190                 while read test_md; do
191                         mdconfig -d -u $test_md 2>/dev/null
192                 done < md.devs
193                 rm md.devs
194         fi
195         true
196 }
197
198 # Bug 204616: ggatel(8) creates /dev/ggate* asynchronously if `ggatel create`
199 #             isn't called with `-v`.
200 wait_for_ggate_device()
201 {
202         ggate_device=$1
203
204         while [ ! -c $ggate_device ]; do
205                 sleep 0.5
206         done
207 }