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