xref: /freebsd/contrib/netbsd-tests/fs/ffs/ffs_common.sh (revision fed1ca4b719c56c930f2259d80663cd34be812bb)
1# $NetBSD: ffs_common.sh,v 1.2 2013/07/29 13:15:24 skrll Exp $
2
3create_ffs()
4{
5	local endian=$1; shift
6	local vers=$1; shift
7	local type=$1; shift
8	local op;
9	if [ ${type} = "both" ]; then
10		op="-q user -q group"
11	else
12		op="-q ${type}"
13	fi
14	atf_check -o ignore -e ignore newfs ${op} \
15		-B ${endian} -O ${vers} -s 4000 -F ${IMG}
16}
17
18create_ffs_server()
19{
20	local sarg=$1; shift
21	create_ffs $*
22	atf_check -o ignore -e ignore $(atf_get_srcdir)/h_ffs_server \
23		${sarg} ${IMG} ${RUMP_SERVER}
24}
25
26rump_shutdown()
27{
28	for s in ${RUMP_SOCKETS_LIST}; do
29		atf_check -s exit:0 env RUMP_SERVER=unix://${s} rump.halt;
30	done
31# check that the quota inode creation didn't corrupt the filesystem
32	atf_check -s exit:0 -o "match:already clean" \
33		-o "match:Phase 6 - Check Quotas" \
34		fsck_ffs -nf -F ${IMG}
35}
36
37# from tests/ipf/h_common.sh via tests/sbin/resize_ffs
38test_case()
39{
40	local name="${1}"; shift
41	local check_function="${1}"; shift
42	local descr="${1}"; shift
43
44	atf_test_case "${name}" cleanup
45
46	eval "${name}_head() { \
47		atf_set "descr" "${descr}"
48		atf_set "timeout" "60"
49	}"
50	eval "${name}_body() { \
51		RUMP_SOCKETS_LIST=\${RUMP_SOCKET}; \
52		export RUMP_SERVER=unix://\${RUMP_SOCKET}; \
53		${check_function} " "${@}" "; \
54	}"
55	eval "${name}_cleanup() { \
56		for s in \${RUMP_SOCKETS_LIST}; do \
57			export RUMP_SERVER=unix://\${s}; \
58			atf_check -s exit:1 -o ignore -e ignore rump.halt; \
59		done; \
60	}"
61	tests="${tests} ${name}"
62}
63
64test_case_root()
65{
66	local name="${1}"; shift
67	local check_function="${1}"; shift
68	local descr="${1}"; shift
69
70	atf_test_case "${name}" cleanup
71
72	eval "${name}_head() { \
73		atf_set "descr" "${descr}"
74		atf_set "require.user" "root"
75		atf_set "timeout" "360"
76	}"
77	eval "${name}_body() { \
78		RUMP_SOCKETS_LIST=\${RUMP_SOCKET}; \
79		export RUMP_SERVER=unix://\${RUMP_SOCKET}; \
80		${check_function} " "${@}" "; \
81	}"
82	eval "${name}_cleanup() { \
83		for s in \${RUMP_SOCKETS_LIST}; do \
84			export RUMP_SERVER=unix://\${s}; \
85			atf_check -s exit:1 -o ignore -e ignore rump.halt; \
86		done; \
87	}"
88	tests="${tests} ${name}"
89}
90
91atf_init_test_cases()
92{
93	IMG=fsimage
94	DIR=target
95	RUMP_SOCKET=test;
96	for i in ${tests}; do
97		atf_add_test_case $i
98	done
99}
100