xref: /src/sbin/tunefs/tests/tunefs_test.sh (revision 6630c3a73688ae3c33df892f6802bea5b8460e17)
1#
2# Copyright (c) 2026 Dag-Erling Smørgrav <des@FreeBSD.org>
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6
7# Create a small file system to experiment on
8tunefs_setup()
9{
10	atf_check -o save:dev mdconfig -t malloc -s 16M
11	tunefs_dev=/dev/$(cat dev)
12	atf_check -o ignore newfs "$@" $tunefs_dev
13}
14
15# Verify that the changes we ask tunefs to perform are applied to the
16# test file system
17tunefs_test()
18{
19	local opt=$1		# tunefs option
20	local name=$2		# what tunefs(8) calls it
21	local descr=${3:-$name}	# what file(1) calls it, if different
22
23	# Verify that the optin is not enabled
24	atf_check -o not-match:"$name" \
25	    file -s $tunefs_dev
26
27	# Enable the option and verify that it is enabled
28	atf_check -e match:"$name set" -o ignore \
29	    tunefs $opt enable $tunefs_dev
30	atf_check -o match:"$descr" \
31	    file -s $tunefs_dev
32
33	# Enable it again and verify that it is still enabled
34	atf_check -e match:"$name remains unchanged as enabled" \
35	    tunefs $opt enable $tunefs_dev
36	atf_check -o match:"$descr" \
37	    file -s $tunefs_dev
38
39	# Disable the option and verify that it is disabled
40	atf_check -e match:"$name cleared" -o ignore \
41	    tunefs $opt disable $tunefs_dev
42	atf_check -o not-match:"$descr" \
43	    file -s $tunefs_dev
44
45	# Disable it again and verify that it is still disabled
46	atf_check -e match:"$name remains unchanged as disabled" \
47	    tunefs $opt disable $tunefs_dev
48	atf_check -o not-match:"$descr" \
49	    file -s $tunefs_dev
50}
51
52# Clean up after ourselves
53tunefs_cleanup()
54{
55	# Destroy the test file system
56	if [ -f dev ]; then
57		mdconfig -d -u $(cat dev) || true
58	fi
59}
60
61# POSIX.1e ACLs
62atf_test_case posixacl cleanup
63posixacl_head()
64{
65	atf_set descr "Turn POSIX.1e ACLs on and off"
66	atf_set require.user "root"
67}
68posixacl_body()
69{
70	tunefs_setup
71	tunefs_test -a "POSIX.1e ACLs"
72}
73posixacl_cleanup()
74{
75	tunefs_cleanup
76}
77
78# NFSv4 ACLs
79atf_test_case nfs4acl cleanup
80nfs4acl_head()
81{
82	atf_set descr "Turn NFSv4 ACLs on and off"
83	atf_set require.user "root"
84}
85nfs4acl_body()
86{
87	tunefs_setup
88	tunefs_test -N "NFSv4 ACLs"
89}
90nfs4acl_cleanup()
91{
92	tunefs_cleanup
93}
94
95# Soft Updates (no journaling)
96atf_test_case sunoj cleanup
97sunoj_head()
98{
99	atf_set descr "Turn Soft Updates on and off"
100	atf_set require.user "root"
101}
102sunoj_body()
103{
104	tunefs_setup -u
105	tunefs_test -n "soft updates"
106}
107sunoj_cleanup()
108{
109	tunefs_cleanup
110}
111
112# Soft Updates journaling
113atf_test_case suj cleanup
114suj_head()
115{
116	atf_set descr "Turn Soft Updates journaling on and off"
117	atf_set require.user "root"
118}
119suj_body()
120{
121	tunefs_setup
122	tunefs_test -j "soft updates journaling"
123}
124suj_cleanup()
125{
126	tunefs_cleanup
127}
128
129# GEOM journaling
130atf_test_case gjournal cleanup
131gjournal_head()
132{
133	atf_set descr "Turn GEOM journaling on and off"
134	atf_set require.user "root"
135}
136gjournal_body()
137{
138	tunefs_setup -u
139	tunefs_test -J "gjournal" "GEOM journaling"
140}
141gjournal_cleanup()
142{
143	tunefs_cleanup
144}
145
146# Try combining Soft Updates with GEOM journaling
147atf_test_case conflict cleanup
148conflict_head()
149{
150	atf_set descr "Soft Updates and GEOM journaling are mutually exclusive"
151	atf_set require.user "root"
152}
153conflict_body()
154{
155	tunefs_setup -U
156
157	# Verify that SU is enabled
158	atf_check -o match:"soft updates" \
159	    file -s $tunefs_dev
160	# Verify that enabling gjournal fails
161	atf_check -e match:"cannot be enabled" \
162	    tunefs -J enable $tunefs_dev
163	# Now turn SU off
164	atf_check -e match:"soft updates cleared" \
165	    tunefs -n disable $tunefs_dev
166	# Enable gjournal
167	atf_check -e match:"gjournal set" \
168	    tunefs -J enable $tunefs_dev
169	# Verify that enabling SU+J fails
170	atf_check -e match:"cannot be enabled" \
171	    tunefs -j enable $tunefs_dev
172	# Verify that enabling SU alone fails
173	atf_check -e match:"cannot be enabled" \
174	    tunefs -n enable $tunefs_dev
175}
176conflict_cleanup()
177{
178	tunefs_cleanup
179}
180
181atf_init_test_cases()
182{
183	atf_add_test_case posixacl
184	atf_add_test_case nfs4acl
185	atf_add_test_case sunoj
186	atf_add_test_case suj
187	atf_add_test_case gjournal
188	atf_add_test_case conflict
189}
190