git: 822fa7ae1e3e - main - cp: Add tests involving sparse files.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 02 Feb 2023 14:46:39 UTC
The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=822fa7ae1e3e7ed277e47e6de355387e524c6ee4 commit 822fa7ae1e3e7ed277e47e6de355387e524c6ee4 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2023-02-01 20:06:24 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2023-02-02 14:45:55 +0000 cp: Add tests involving sparse files. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D38290 --- bin/cp/tests/cp_test.sh | 90 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/bin/cp/tests/cp_test.sh b/bin/cp/tests/cp_test.sh index 7362168d7303..932bd2221ba3 100755 --- a/bin/cp/tests/cp_test.sh +++ b/bin/cp/tests/cp_test.sh @@ -199,6 +199,91 @@ recursive_link_Lflag_body() '(' ! -L foo-mirror/foo/baz ')' } +file_is_sparse() +{ + atf_check test "$(stat -f "%b" "$1")" != "$(stat -f "%z" "$1")" +} + +files_are_equal() +{ + atf_check test "$(stat -f "%d %i" "$1")" != "$(stat -f "%d %i" "$2")" + atf_check cmp "$1" "$2" +} + +atf_test_case sparse_leading_hole +sparse_leading_hole_body() +{ + # A one-megabyte hole followed by one megabyte of data + truncate -s 1M foo + seq -f%015g 65536 >>foo + file_is_sparse foo + + atf_check cp foo bar + files_are_equal foo bar + file_is_sparse bar +} + +atf_test_case sparse_multiple_holes +sparse_multiple_holes_body() +{ + # Three one-megabyte blocks of data preceded, separated, and + # followed by one-megabyte holes + truncate -s 1M foo + seq -f%015g >>foo + truncate -s 3M foo + seq -f%015g >>foo + truncate -s 5M foo + seq -f%015g >>foo + truncate -s 7M foo + file_is_sparse foo + + atf_check cp foo bar + files_are_equal foo bar + file_is_sparse bar +} + +atf_test_case sparse_only_hole +sparse_only_hole_body() +{ + # A one-megabyte hole + truncate -s 1M foo + file_is_sparse foo + + atf_check cp foo bar + files_are_equal foo bar + file_is_sparse bar +} + +atf_test_case sparse_to_dev +sparse_to_dev_body() +{ + # Three one-megabyte blocks of data preceded, separated, and + # followed by one-megabyte holes + truncate -s 1M foo + seq -f%015g >>foo + truncate -s 3M foo + seq -f%015g >>foo + truncate -s 5M foo + seq -f%015g >>foo + truncate -s 7M foo + file_is_sparse foo + + atf_check -o file:foo cp foo /dev/stdout +} + +atf_test_case sparse_trailing_hole +sparse_trailing_hole_body() +{ + # One megabyte of data followed by a one-megabyte hole + seq -f%015g 65536 >foo + truncate -s 2M foo + file_is_sparse foo + + atf_check cp foo bar + files_are_equal foo bar + file_is_sparse bar +} + atf_test_case standalone_Pflag standalone_Pflag_body() { @@ -221,5 +306,10 @@ atf_init_test_cases() atf_add_test_case recursive_link_dflt atf_add_test_case recursive_link_Hflag atf_add_test_case recursive_link_Lflag + atf_add_test_case sparse_leading_hole + atf_add_test_case sparse_multiple_holes + atf_add_test_case sparse_only_hole + atf_add_test_case sparse_to_dev + atf_add_test_case sparse_trailing_hole atf_add_test_case standalone_Pflag }