1153184Spjd#!/bin/sh
2153184Spjd# $FreeBSD: releng/11.0/tests/sys/geom/class/geom_subr.sh 297183 2016-03-22 08:12:45Z ngie $
3153184Spjd
4153184Spjddevwait()
5153184Spjd{
6153184Spjd	while :; do
7153184Spjd		if [ -c /dev/${class}/${name} ]; then
8153184Spjd			return
9153184Spjd		fi
10153184Spjd		sleep 0.2
11153184Spjd	done
12153184Spjd}
13293029Sngie
14293029Sngieattach_md()
15293029Sngie{
16293029Sngie	local test_md
17293029Sngie
18293029Sngie	test_md=$(mdconfig -a "$@") || exit
19293029Sngie	echo $test_md >> $TEST_MDS_FILE || exit
20293029Sngie	echo $test_md
21293029Sngie}
22293029Sngie
23293029Sngiegeom_test_cleanup()
24293029Sngie{
25293029Sngie	local test_md
26293029Sngie
27293444Sngie	if [ -f "$TEST_MDS_FILE" ]; then
28293029Sngie		while read test_md; do
29293029Sngie			# The "#" tells the TAP parser this is a comment
30293029Sngie			echo "# Removing test memory disk: $test_md"
31293029Sngie			mdconfig -d -u $test_md
32293029Sngie		done < $TEST_MDS_FILE
33293029Sngie	fi
34293444Sngie	rm -f "$TEST_MDS_FILE"
35293029Sngie}
36293444Sngie
37293444Sngieif [ $(id -u) -ne 0 ]; then
38297183Sngie	echo '1..0 # SKIP tests must be run as root'
39297183Sngie	exit 0
40293444Sngiefi
41293444Sngie# If the geom class isn't already loaded, try loading it.
42293444Sngieif ! kldstat -q -m g_${class}; then
43293444Sngie	if ! geom ${class} load; then
44297183Sngie		echo "1..0 # SKIP could not load module for geom class=${class}"
45297183Sngie		exit 0
46293444Sngie	fi
47293444Sngiefi
48293444Sngie
49293444Sngie# Need to keep track of the test md devices to avoid the scenario where a test
50293444Sngie# failing will cause the other tests to bomb out, or a test failing will leave
51293444Sngie# a large number of md(4) devices lingering around
52293444Sngie: ${TMPDIR=/tmp}
53293444Sngieexport TMPDIR
54293444Sngieif ! TEST_MDS_FILE=$(mktemp ${TMPDIR}/test_mds.XXXXXX); then
55293444Sngie	echo 'Failed to create temporary file for tracking the test md(4) devices'
56293444Sngie	echo 'Bail out!'
57293444Sngie	exit 1
58293444Sngiefi
59