geom_subr.sh revision 293444
1153184Spjd#!/bin/sh 2153184Spjd# $FreeBSD: head/tools/regression/geom_subr.sh 293444 2016-01-08 21:47:41Z 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 38293444Sngie echo 'Tests must be run as root' 39293444Sngie echo 'Bail out!' 40293444Sngie exit 1 41293444Sngiefi 42293444Sngie# If the geom class isn't already loaded, try loading it. 43293444Sngieif ! kldstat -q -m g_${class}; then 44293444Sngie if ! geom ${class} load; then 45293444Sngie echo "Could not load module for geom class=${class}" 46293444Sngie echo 'Bail out!' 47293444Sngie exit 1 48293444Sngie fi 49293444Sngiefi 50293444Sngie 51293444Sngie# Need to keep track of the test md devices to avoid the scenario where a test 52293444Sngie# failing will cause the other tests to bomb out, or a test failing will leave 53293444Sngie# a large number of md(4) devices lingering around 54293444Sngie: ${TMPDIR=/tmp} 55293444Sngieexport TMPDIR 56293444Sngieif ! TEST_MDS_FILE=$(mktemp ${TMPDIR}/test_mds.XXXXXX); then 57293444Sngie echo 'Failed to create temporary file for tracking the test md(4) devices' 58293444Sngie echo 'Bail out!' 59293444Sngie exit 1 60293444Sngiefi 61