1239281Sgonzo#!/bin/sh
2239281Sgonzo# $FreeBSD: releng/10.3/sbin/sunlabel/runtest.sh 113897 2003-04-23 08:25:44Z phk $
3239281Sgonzo
4239281SgonzoTMP=/tmp/$$.
5239281Sgonzoset -e
6239281SgonzoMD=`mdconfig -a -t malloc -s 2m`
7239281Sgonzotrap "exec 7</dev/null; rm -f ${TMP}* ; mdconfig -d -u ${MD}" EXIT INT TERM
8239281Sgonzo
9239281Sgonzo./sunlabel -r -w $MD auto
10239281Sgonzo
11239281Sgonzodd if=/dev/$MD of=${TMP}i0 count=16 > /dev/null 2>&1
12239281Sgonzo./sunlabel $MD > ${TMP}l0
13239281Sgonzo
14239281Sgonzosed '
15239281Sgonzo/  c:/{
16239281Sgonzop
17239281Sgonzos/c:/a:/
18239281Sgonzos/3969/1024/
19239281Sgonzo}
20239281Sgonzo' ${TMP}l0 > ${TMP}l1
21239281Sgonzo
22239281Sgonzo./sunlabel -R $MD ${TMP}l1
23239281Sgonzoif [ -c /dev/${MD}a ] ; then
24239281Sgonzo	echo "PASS: Created a: partition" 1>&2
25239281Sgonzoelse
26239281Sgonzo	echo "FAIL: Did not create a: partition" 1>&2
27239281Sgonzo	exit 2
28239281Sgonzofi
29239281Sgonzo
30239281Sgonzo# Spoil and rediscover
31239281Sgonzo
32239281Sgonzotrue > /dev/${MD}
33239281Sgonzoif [ -c /dev/${MD}a ] ; then
34239281Sgonzo	echo "PASS: Recreated a: partition after spoilage" 1>&2
35239281Sgonzoelse
36239281Sgonzo	echo "FAIL: Did not recreate a: partition after spoilage" 1>&2
37239281Sgonzo	exit 2
38239281Sgonzofi
39239281Sgonzo
40239281Sgonzodd if=/dev/$MD of=${TMP}i1 count=16 > /dev/null 2>&1
41239281Sgonzosed '
42239281Sgonzo/  c:/{
43239281Sgonzop
44239281Sgonzos/c:/a:/
45239281Sgonzos/3969/2048/
46239281Sgonzo}
47239281Sgonzo' ${TMP}l0 > ${TMP}l2
48239281Sgonzo
49239281Sgonzo./sunlabel -R $MD ${TMP}l2
50239281Sgonzodd if=/dev/$MD of=${TMP}i2 count=16 > /dev/null 2>&1
51239281Sgonzo
52239281Sgonzoexec 7< /dev/${MD}a
53239281Sgonzo
54239281Sgonzofor t in a c
55239281Sgonzodo
56239281Sgonzo	if dd if=${TMP}i2 of=/dev/${MD}$t 2>/dev/null ; then
57239281Sgonzo		echo "PASS: Could rewrite same label to ...$t while ...a open" 1>&2
58239281Sgonzo	else
59239281Sgonzo		echo "FAIL: Could not rewrite same label to ...$t while ...a open" 1>&2
60239281Sgonzo		exit 2
61239281Sgonzo	fi
62239281Sgonzo
63239281Sgonzo	if dd if=${TMP}i1 of=/dev/${MD}$t 2>/dev/null ; then
64239281Sgonzo		echo "FAIL: Could label with smaller ...a to ...$t while ...a open" 1>&2
65239281Sgonzo		exit 2
66239281Sgonzo	else
67239281Sgonzo		echo "PASS: Could not label with smaller ...a to ...$t while ...a open" 1>&2
68239281Sgonzo	fi
69266148Sloos
70266148Sloos	if dd if=${TMP}i0 of=/dev/${MD}$t 2>/dev/null ; then
71266148Sloos		echo "FAIL: Could write label missing ...a to ...$t while ...a open" 1>&2
72239281Sgonzo		exit 2
73266148Sloos	else
74266148Sloos		echo "PASS: Could not write label missing ...a to ...$t while ...a open" 1>&2
75266148Sloos	fi
76266148Sloosdone
77266148Sloos
78266148Sloosexec 7< /dev/null
79266148Sloos
80266148Sloosif dd if=${TMP}i0 of=/dev/${MD}c 2>/dev/null ; then
81266148Sloos	echo "PASS: Could write missing ...a label to ...c" 1>&2
82266148Slooselse
83266148Sloos	echo "FAIL: Could not write missing ...a label to ...c" 1>&2
84266148Sloos	exit 2
85266148Sloosfi
86266148Sloos
87266148Sloosif dd if=${TMP}i2 of=/dev/${MD}c 2>/dev/null ; then
88266148Sloos	echo "PASS: Could write large ...a label to ...c" 1>&2
89266148Slooselse
90266148Sloos	echo "FAIL: Could not write large ...a label to ...c" 1>&2
91266148Sloos	exit 2
92266148Sloosfi
93266148Sloos
94266148Sloosif dd if=${TMP}i1 of=/dev/${MD}c 2>/dev/null ; then
95266148Sloos	echo "PASS: Could write small ...a label to ...c" 1>&2
96266148Slooselse
97239281Sgonzo	echo "FAIL: Could not write small ...a label to ...c" 1>&2
98266148Sloos	exit 2
99266148Sloosfi
100266148Sloos
101266148Sloosif dd if=${TMP}i2 of=/dev/${MD}a 2>/dev/null ; then
102266148Sloos	echo "PASS: Could increase size of ...a by writing to ...a" 1>&2
103266148Slooselse
104266148Sloos	echo "FAIL: Could not increase size of ...a by writing to ...a" 1>&2
105266148Sloos	exit 2
106266148Sloosfi
107266148Sloos
108266148Sloosif dd if=${TMP}i1 of=/dev/${MD}a 2>/dev/null ; then
109266148Sloos	echo "FAIL: Could decrease size of ...a by writing to ...a" 1>&2
110266148Sloos	exit 2
111266148Slooselse
112266148Sloos	echo "PASS: Could not decrease size of ...a by writing to ...a" 1>&2
113266148Sloosfi
114266148Sloos
115266148Sloosif dd if=${TMP}i0 of=/dev/${MD}a 2>/dev/null ; then
116266148Sloos	echo "FAIL: Could delete ...a by writing to ...a" 1>&2
117266148Sloos	exit 2
118266148Slooselse
119266148Sloos	echo "PASS: Could not delete ...a by writing to ...a" 1>&2
120266148Sloosfi
121266148Sloos
122266148Sloosif ./sunlabel -B -b ${TMP}i0 ${MD} ; then
123266148Sloos	if [ ! -c /dev/${MD}a ] ; then
124266148Sloos		echo "FAILED: Writing bootcode killed ...a" 1>&2
125266148Sloos		exit 2
126266148Sloos	else
127266148Sloos		echo "PASS: Could write bootcode while closed" 1>&2
128239281Sgonzo	fi
129239281Sgonzoelse
130239281Sgonzo	echo "FAILED: Could not write bootcode while closed" 1>&2
131239281Sgonzo	exit 2
132266148Sloosfi
133239281Sgonzo
134266148Sloosexec 7> /dev/${MD}c
135266148Sloosif ktrace ./sunlabel -B -b ${TMP}i0 ${MD} ; then
136266148Sloos	if [ ! -c /dev/${MD}a ] ; then
137266148Sloos		echo "FAILED: Writing bootcode killed ...a" 1>&2
138239281Sgonzo		exit 2
139266148Sloos	else
140266148Sloos		echo "PASS: Could write bootcode while open" 1>&2
141266148Sloos	fi
142266148Slooselse
143239281Sgonzo	echo "FAILED: Could not write bootcode while open" 1>&2
144266148Sloos	exit 2
145266148Sloosfi
146266148Sloosexec 7> /dev/null
147266148Sloos
148239281Sgonzoif dd if=${TMP}i0 of=/dev/${MD}c 2>/dev/null ; then
149266148Sloos	echo "PASS: Could delete ...a by writing to ...c" 1>&2
150266148Slooselse
151239281Sgonzo	echo "FAIL: Could not delete ...a by writing to ...c" 1>&2
152239281Sgonzo	exit 2
153239281Sgonzofi
154239281Sgonzo
155239281Sgonzo# XXX: need to add a 'b' partition and check for overlaps.
156239281Sgonzo
157239281Sgonzoexit 0
158266148Sloos