Page MenuHomeFreeBSD

D41645.id126675.diff
No OneTemporary

D41645.id126675.diff

diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist
--- a/etc/mtree/BSD.tests.dist
+++ b/etc/mtree/BSD.tests.dist
@@ -794,6 +794,8 @@
..
stripe
..
+ union
+ ..
uzip
etalon
..
diff --git a/tests/sys/geom/class/Makefile b/tests/sys/geom/class/Makefile
--- a/tests/sys/geom/class/Makefile
+++ b/tests/sys/geom/class/Makefile
@@ -19,6 +19,7 @@
TESTS_SUBDIRS+= shsec
TESTS_SUBDIRS+= stripe
TESTS_SUBDIRS+= uzip
+TESTS_SUBDIRS+= union
${PACKAGE}FILES+= geom_subr.sh
diff --git a/tests/sys/geom/class/union/Makefile b/tests/sys/geom/class/union/Makefile
new file mode 100644
--- /dev/null
+++ b/tests/sys/geom/class/union/Makefile
@@ -0,0 +1,9 @@
+# $FreeBSD$
+
+PACKAGE= tests
+
+TESTSDIR= ${TESTSBASE}/sys/geom/class/${.CURDIR:T}
+
+ATF_TESTS_SH+= union_test
+
+.include <bsd.test.mk>
diff --git a/tests/sys/geom/class/union/union_test.sh b/tests/sys/geom/class/union/union_test.sh
new file mode 100644
--- /dev/null
+++ b/tests/sys/geom/class/union/union_test.sh
@@ -0,0 +1,242 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2023 The FreeBSD Foundation
+#
+# This software was developed1 by Yan-Hao Wang <bses30074@gmail.com>
+# under sponsorship from the FreeBSD Foundation.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE
+#
+# $FreeBSD$
+#
+writable_device_name=""
+readable_device_name=""
+gunion_device=""
+
+atf_test_case basic
+basic_head()
+{
+ atf_set "descr" "Test basic gunion command with no argument"
+}
+basic_body()
+{
+ atf_check gunion load
+ atf_check -o ignore sh -c 'kldstat | grep "geom_union.k"'
+
+ writable_device_name="$(mdconfig -s 1m)"
+ echo "$writable_device_name" > md_device_1
+ newfs -U "/dev/${writable_device_name}"
+
+ readable_device_name="$(mdconfig -s 1m)"
+ echo "$readable_device_name" > md_device_2
+ newfs -U "/dev/${readable_device_name}"
+ mkdir readable_device
+ mount "/dev/${readable_device_name}" readable_device
+ touch readable_device/readable_file
+ echo "I am readable file" | tee readable_device/readable_file
+ sync
+ umount readable_device
+
+ atf_check gunion create "$writable_device_name" "$readable_device_name"
+ gunion_device="${writable_device_name}-${readable_device_name}.union"
+ mkdir gunion
+ mount "/dev/${gunion_device}" gunion
+
+ atf_check -o inline:"gunion/readable_file\n" ls gunion/readable_file
+ atf_check -o inline:"I am readable file\n" cat gunion/readable_file
+
+ touch gunion/gunion_file
+ echo "I am gunion file" | tee gunion/gunion_file
+ sync
+ umount gunion
+ atf_check gunion commit "${gunion_device}"
+ atf_check gunion destroy "${gunion_device}"
+
+ mkdir writable_device
+ mount "/dev/${writable_device_name}" writable_device
+ atf_check -o inline:"writable_device/gunion_file\n" ls writable_device/gunion_file
+ atf_check -o inline:"I am gunion file\n" cat writable_device/gunion_file
+
+ mount "/dev/${readable_device_name}" readable_device
+ atf_check -o inline:"readable_device/gunion_file\n" ls readable_device/gunion_file
+ atf_check -o inline:"I am gunion file\n" cat readable_device/gunion_file
+
+ # cleanup and test gunino unload
+ umount readable_device
+ umount writable_device
+ mdconfig -d -u "$(cat md_device_1)"
+ mdconfig -d -u "$(cat md_device_2)"
+ atf_check gunion unload
+ atf_check -s not-exit:0 sh -c 'kldstat | grep "geom_union.k"'
+}
+
+atf_test_case size cleanup
+size_head()
+{
+ atf_set "descr" "Test gunion command with -s size argument"
+}
+size_body()
+{
+ gunion load
+ writable_device_name="$(mdconfig -s 2m)"
+ echo "$writable_device_name" > md_device_1
+ newfs -U "/dev/${writable_device_name}"
+
+ readable_device_name="$(mdconfig -s 1m)"
+ echo "$readable_device_name" > md_device_2
+ newfs -U "/dev/${readable_device_name}"
+
+ gunion create -s 2m "$writable_device_name" "$readable_device_name"
+ gunion_device="${writable_device_name}-${readable_device_name}.union"
+ echo "$gunion_device" > gunion_device_1
+ size="$(diskinfo "/dev/$gunion_device" | awk '{print $3}')"
+ atf_check_equal "2097152" "$size"
+}
+size_cleanup()
+{
+ gunion destroy "$(cat gunion_device_1)"
+ mdconfig -d -u "$(cat md_device_1)"
+ mdconfig -d -u "$(cat md_device_2)"
+ gunion unload
+}
+
+atf_test_case secsize cleanup
+secsize_head()
+{
+ atf_set "descr" "Test gunion command with -S secsize argument"
+}
+secsize_body()
+{
+ gunion load
+ writable_device_name="$(mdconfig -s 1m)"
+ echo "$writable_device_name" > md_device_1
+ newfs -U "/dev/${writable_device_name}"
+
+ readable_device_name="$(mdconfig -s 1m)"
+ echo "$readable_device_name" > md_device_2
+ newfs -U "/dev/${readable_device_name}"
+
+ gunion create -S 1024 "$writable_device_name" "$readable_device_name"
+ gunion_device="${writable_device_name}-${readable_device_name}.union"
+ echo "$gunion_device" > gunion_device_1
+ secsize="$(diskinfo "/dev/$gunion_device" | awk '{print $2}')"
+ atf_check_equal "1024" "$secsize"
+}
+secsize_cleanup()
+{
+ gunion destroy "$(cat gunion_device_1)"
+ mdconfig -d -u "$(cat md_device_1)"
+ mdconfig -d -u "$(cat md_device_2)"
+ gunion unload
+}
+
+atf_test_case gunionname cleanup
+gunionname_head()
+{
+ atf_set "descr" "Test gunion command with -Z gunionname argument"
+}
+gunionname_body()
+{
+ gunion load
+ writable_device_name="$(mdconfig -s 1m)"
+ echo "$writable_device_name" > md_device_1
+ newfs -U "/dev/${writable_device_name}"
+
+ readable_device_name="$(mdconfig -s 1m)"
+ echo "$readable_device_name" > md_device_2
+ newfs -U "/dev/${readable_device_name}"
+
+ gunion create -Z gunion1 "$writable_device_name" "$readable_device_name"
+ echo "gunion1.union" > gunion_device_1
+ atf_check -o inline:"/dev/gunion1.union\n" ls /dev/gunion1.union
+}
+gunionname_cleanup()
+{
+ gunion destroy "$(cat gunion_device_1)"
+ mdconfig -d -u "$(cat md_device_1)"
+ mdconfig -d -u "$(cat md_device_2)"
+ gunion unload
+}
+
+atf_test_case revert cleanup
+revert_head()
+{
+ atf_set "descr" "Test gunion revert"
+}
+revert_body()
+{
+ gunion load
+ writable_device_name="$(mdconfig -s 1m)"
+ echo "$writable_device_name" > md_device_1
+ newfs -U "/dev/${writable_device_name}"
+
+ readable_device_name="$(mdconfig -s 1m)"
+ echo "$readable_device_name" > md_device_2
+ newfs -U "/dev/${readable_device_name}"
+ mkdir readable_device
+ mount "/dev/${readable_device_name}" readable_device
+ touch readable_device/readable_file
+ echo "I am readable file" | tee readable_device/readable_file
+ sync
+ umount readable_device
+
+ atf_check gunion create "$writable_device_name" "$readable_device_name"
+ gunion_device="${writable_device_name}-${readable_device_name}.union"
+ mkdir gunion
+ mount "/dev/${gunion_device}" gunion
+
+ touch gunion/gunion_file
+ echo "I am gunion file" | tee gunion/gunion_file
+ rm gunion/readable_file
+ sync
+ umount gunion
+ atf_check gunion revert "${gunion_device}"
+ atf_check gunion destroy "${gunion_device}"
+
+ mkdir writable_device
+ mount "/dev/${writable_device_name}" writable_device
+ atf_check -o inline:"writable_device/gunion_file\n" ls writable_device/gunion_file
+ atf_check -o inline:"I am gunion file\n" cat writable_device/gunion_file
+
+
+ mount "/dev/${readable_device_name}" readable_device
+ atf_check -o inline:"readable_device/readable_file\n" ls readable_device/readable_file
+ atf_check -o inline:"I am readable file\n" cat readable_device/readable_file
+}
+revert_cleanup()
+{
+ umount readable_device
+ umount writable_device
+ mdconfig -d -u "$(cat md_device_1)"
+ mdconfig -d -u "$(cat md_device_2)"
+ gunion unload
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case basic
+ atf_add_test_case size
+ atf_add_test_case secsize
+ atf_add_test_case gunionname
+ atf_add_test_case revert
+}
\ No newline at end of file

File Metadata

Mime Type
text/plain
Expires
Fri, Jan 16, 5:50 AM (13 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27658584
Default Alt Text
D41645.id126675.diff (9 KB)

Event Timeline