Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F133365380
D41645.id126771.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
9 KB
Referenced Files
None
Subscribers
None
D41645.id126771.diff
View Options
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
@@ -18,6 +18,7 @@
TESTS_SUBDIRS+= raid3
TESTS_SUBDIRS+= shsec
TESTS_SUBDIRS+= stripe
+TESTS_SUBDIRS+= union
TESTS_SUBDIRS+= uzip
${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,8 @@
+
+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,300 @@
+#
+# 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 load
+load_head()
+{
+ atf_set "descr" "Test gunion load and unload"
+}
+load_body()
+{
+ atf_check gunion load
+ atf_check -o ignore sh -c 'kldstat | grep "geom_union.k"'
+ atf_check gunion unload
+ atf_check -s not-exit:0 sh -c 'kldstat | grep "geom_union.k"'
+}
+
+atf_test_case create cleanup
+create_head()
+{
+ atf_set "descr" "Test gunion create and destroy"
+}
+create_body()
+{
+ gunion load
+ writable_device_name="$(mdconfig -s 1m)"
+ readable_device_name="$(mdconfig -s 1m)"
+ echo "$writable_device_name" > md_device_1
+ echo "$readable_device_name" > md_device_2
+ newfs -U "/dev/${writable_device_name}"
+ newfs -U "/dev/${readable_device_name}"
+
+ atf_check gunion create "$writable_device_name" "$readable_device_name"
+ gunion_device="${writable_device_name}-${readable_device_name}.union"
+ atf_check -o inline:"/dev/${gunion_device}\n" ls "/dev/${gunion_device}"
+
+ atf_check gunion destroy "${gunion_device}"
+ atf_check -e ignore -o ignore -s not-exit:0 ls "/dev/${gunion_device}"
+}
+create_cleanup()
+{
+ cleanup_
+}
+
+atf_test_case commit cleanup
+commit_head()
+{
+ atf_set "descr" "Test basic gunion commit with no argument"
+}
+commit_body()
+{
+ gunion load
+ writable_device_name="$(mdconfig -s 1m)"
+ readable_device_name="$(mdconfig -s 1m)"
+ echo "$writable_device_name" > md_device_1
+ echo "$readable_device_name" > md_device_2
+ newfs -U "/dev/${writable_device_name}"
+ newfs -U "/dev/${readable_device_name}"
+ mkdir readable_device
+ mkdir writable_device
+ mkdir gunion
+
+ mount "/dev/${readable_device_name}" readable_device
+ echo "I am readable file" > readable_file
+ cp readable_file readable_device/readable_file
+ sync
+ umount readable_device
+
+ gunion create "$writable_device_name" "$readable_device_name"
+ gunion_device="${writable_device_name}-${readable_device_name}.union"
+ mount "/dev/${gunion_device}" gunion
+ checksum gunion/readable_file readable_file
+
+ echo "I am gunion file" > gunion_file
+ cp gunion_file gunion/gunion_file
+ sync
+ umount gunion
+ atf_check gunion commit "${gunion_device}"
+ gunion destroy "${gunion_device}"
+
+ mount "/dev/${writable_device_name}" writable_device
+ mount "/dev/${readable_device_name}" readable_device
+ checksum readable_device/readable_file readable_file
+ checksum writable_device/gunion_file gunion_file
+ checksum readable_device/gunion_file gunion_file
+}
+commit_cleanup()
+{
+ cleanup_
+}
+
+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)"
+ readable_device_name="$(mdconfig -s 1m)"
+ echo "$writable_device_name" > md_device_1
+ echo "$readable_device_name" > md_device_2
+ newfs -U "/dev/${writable_device_name}"
+ 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()
+{
+ cleanup_
+}
+
+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)"
+ readable_device_name="$(mdconfig -s 1m)"
+ echo "$writable_device_name" > md_device_1
+ echo "$readable_device_name" > md_device_2
+ newfs -U "/dev/${writable_device_name}"
+ 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()
+{
+ cleanup_
+}
+
+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)"
+ readable_device_name="$(mdconfig -s 1m)"
+ echo "$writable_device_name" > md_device_1
+ echo "$readable_device_name" > md_device_2
+ newfs -U "/dev/${writable_device_name}"
+ 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()
+{
+ cleanup_
+}
+
+atf_test_case revert cleanup
+revert_head()
+{
+ atf_set "descr" "Test gunion revert"
+}
+revert_body()
+{
+ gunion load
+ writable_device_name="$(mdconfig -s 1m)"
+ readable_device_name="$(mdconfig -s 1m)"
+ echo "$writable_device_name" > md_device_1
+ echo "$readable_device_name" > md_device_2
+ newfs -U "/dev/${writable_device_name}"
+ newfs -U "/dev/${readable_device_name}"
+ mkdir readable_device
+ mkdir writable_device
+ mkdir gunion
+
+ mount "/dev/${readable_device_name}" readable_device
+ echo "I am readable file" > readable_file
+ cp readable_file 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"
+ mount "/dev/${gunion_device}" gunion
+
+ echo "I am gunion file" > gunion_file
+ cp gunion_file gunion/gunion_file
+ sync
+ umount gunion
+ atf_check gunion revert "${gunion_device}"
+ gunion destroy "${gunion_device}"
+
+ mount "/dev/${writable_device_name}" writable_device
+ mount "/dev/${readable_device_name}" readable_device
+ checksum writable_device/gunion_file gunion_file
+ checksum readable_device/readable_file readable_file
+}
+revert_cleanup()
+{
+ cleanup_
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case load
+ atf_add_test_case create
+ atf_add_test_case commit
+ atf_add_test_case size
+ atf_add_test_case secsize
+ atf_add_test_case gunionname
+ atf_add_test_case revert
+}
+
+cleanup_()
+{
+ if mount | grep -q "/writable_device"; then
+ umount writable_device
+ fi
+ if mount | grep -q "/readable_device"; then
+ umount readable_device
+ fi
+ if mount | grep -q "/gunion"; then
+ umount gunion
+ fi
+
+ if [ -e "gunion_device_1" ]; then
+ gunion destroy "$(cat gunion_device_1)"
+ fi
+ if [ -e "md_device_1" ]; then
+ mdconfig -d -u "$(cat md_device_1)"
+ fi
+ if [ -e "md_device_2" ]; then
+ mdconfig -d -u "$(cat md_device_2)"
+ fi
+
+ gunion unload
+}
+
+checksum()
+{
+ src=$1
+ work=$2
+
+ if [ ! -e "$src" ]; then
+ atf_fail "file not exist"
+ fi
+ if [ ! -e "$work" ]; then
+ atf_fail "file not exist"
+ fi
+
+ src_checksum=$(md5 -q "$src")
+ work_checksum=$(md5 -q "$work")
+
+ if [ "$work_checksum" != "$src_checksum" ]; then
+ atf_fail "md5 checksum didn't match with ${src} and ${work}"
+ fi
+}
\ No newline at end of file
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Oct 26, 5:34 AM (1 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
24215359
Default Alt Text
D41645.id126771.diff (9 KB)
Attached To
Mode
D41645: geom_union: Add test for geom_union.
Attached
Detach File
Event Timeline
Log In to Comment