]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/sys/geom/class/geom_subr.sh
zfs: merge openzfs/zfs@a03ebd9be
[FreeBSD/FreeBSD.git] / tests / sys / geom / class / geom_subr.sh
1 #!/bin/sh
2
3 TEST_MDS_FILE="${TMPDIR}/test_mds.$(basename $0)"
4
5 devwait()
6 {
7         while :; do
8                 if [ -c /dev/${class}/${name} ]; then
9                         return
10                 fi
11                 sleep 0.2
12         done
13 }
14
15 attach_md()
16 {
17         local _md
18         local rv=$1
19         shift
20
21         [ -c /dev/mdctl ] || atf_skip "no /dev/mdctl to create md devices"
22         _md=$(mdconfig -a "$@") || exit
23         echo $_md >> $TEST_MDS_FILE || exit
24         eval "${rv}='${_md}'"
25 }
26
27 detach_md()
28 {
29         local test_md unit
30
31         test_md=$1
32         unit=${test_md#md}
33         mdconfig -d -u $unit || exit
34         sed -i '' "/^${test_md}$/d" $TEST_MDS_FILE || exit
35 }
36
37 geom_test_cleanup()
38 {
39         local test_md
40
41         if [ -f "$TEST_MDS_FILE" ]; then
42                 while read test_md; do
43                         # The "#" tells the TAP parser this is a comment
44                         echo "# Removing test memory disk: $test_md"
45                         mdconfig -d -u $test_md
46                 done < $TEST_MDS_FILE
47                 rm -f "$TEST_MDS_FILE"
48         fi
49 }
50
51 geom_load_class_if_needed()
52 {
53         local class=$1
54
55         # If the geom class isn't already loaded, try loading it.
56         if ! kldstat -q -m g_${class}; then
57                 if ! geom ${class} load; then
58                         echo "could not load module for geom class=${class}"
59                         return 1
60                 fi
61         fi
62         return 0
63 }
64
65 geom_atf_test_setup()
66 {
67         if ! error_message=$(geom_load_class_if_needed $class); then
68                 atf_skip "$error_message"
69         fi
70 }
71
72 geom_tap_test_setup()
73 {
74         if ! error_message=$(geom_load_class_if_needed $class); then
75                 echo "1..0 # SKIP $error_message"
76                 exit 0
77         fi
78 }
79
80 : ${ATF_TEST=false}
81 if ! $ATF_TEST; then
82         geom_tap_test_setup
83 fi