xref: /freebsd/tests/sys/geom/class/eli/attach_test.sh (revision f397a004deeae195f8efdb4dc22a62204aa2c10d)
1# $FreeBSD$
2
3atf_test_case attach_d cleanup
4attach_d_head()
5{
6	atf_set "descr" "geli attach -d will cause the provider to detach on last close"
7	atf_set "require.user" "root"
8}
9attach_d_body()
10{
11	. $(atf_get_srcdir)/conf.sh
12
13	sectors=100
14	md=$(attach_md -t malloc -s `expr $sectors + 1`)
15
16	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
17
18	atf_check geli init -B none -P -K keyfile ${md}
19	atf_check geli attach -d -p -k keyfile ${md}
20
21	# Be sure it doesn't detach on read.
22	atf_check dd if=/dev/${md}.eli of=/dev/null status=none
23	sleep 1
24	if [ ! -c /dev/${md}.eli ]; then
25		atf_fail "Detached on last close of a reader"
26	fi
27
28	# It should detach on last close of a writer
29	true > /dev/${md}.eli
30	sleep 1
31	if [ -c /dev/${md}.eli ]; then
32		atf_fail "Did not detach on last close of a writer"
33	fi
34
35}
36attach_d_cleanup()
37{
38	. $(atf_get_srcdir)/conf.sh
39	geli_test_cleanup
40}
41
42atf_init_test_cases()
43{
44	atf_add_test_case attach_d
45}
46