forked from openzfs/zfs
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I used this test when diagnosing #281 and think it would be a good addition. This tests file sizes when pre-allocating a file. Expected values have been confirmed on NTFS, ReFS and FAT32. This test currently does not work on a SMB share with the Samba server because it reports a fixed cluster size based on a configuration option instead of getting the correct value from the underlying file system. ksmbd does not have the same issue, it correctly gets the values from the file system. So far this is untested with Windows SMB shares. This also makes `tests.py` use some helpers from `utils.py`. Signed-off-by: Axel Gembe <[email protected]>
- Loading branch information
Showing
4 changed files
with
561 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import argparse | ||
import logging | ||
import os | ||
import pathlib | ||
import unittest | ||
|
||
from utils import ( | ||
ZfsContext, | ||
Size, | ||
setup_logging, | ||
argparse_as_abspath, | ||
argparse_as_zfs_abspath, | ||
created_zpool, | ||
preallocate_file_object, | ||
get_sizes_from_path, | ||
get_sizes_from_file, | ||
get_cluster_size_from_file, | ||
) | ||
|
||
|
||
args: argparse.Namespace | ||
ctx: ZfsContext | ||
|
||
|
||
logger = setup_logging("regression", logging.INFO) | ||
tc = unittest.TestCase() | ||
|
||
|
||
def parse_arguments() -> argparse.Namespace: | ||
parser = argparse.ArgumentParser(description="Process command line arguments.") | ||
|
||
parser.add_argument("--path", type=argparse_as_abspath, required=True) | ||
|
||
# TODO: We need to verify that the zfs path is actually usable because the default path is not | ||
# passed to `argparse_as_zfs_abspath`. | ||
program_files = pathlib.PureWindowsPath(os.getenv("ProgramFiles")) | ||
default_zfs_path = program_files / "OpenZFS On Windows" | ||
parser.add_argument( | ||
"--zfspath", | ||
type=argparse_as_zfs_abspath, | ||
default=default_zfs_path, | ||
help="Directory path of either an OpenZFS installation or build directory", | ||
) | ||
|
||
parser.add_argument( | ||
"-np", | ||
"--no_pool", | ||
action="store_true", | ||
default=False, | ||
help="Don't create a zpool, run tests in path", | ||
) | ||
|
||
return parser.parse_args() | ||
|
||
|
||
def test_preallocation(test_path: pathlib.Path): | ||
"""Tests file sizes when pre-allocating a file. | ||
Expected values have been confirmed on NTFS, ReFS and FAT32. | ||
This test currently does not work on a SMB share with the Samba server | ||
because it reports a fixed cluster size based on a configuration option | ||
instead of getting the correct value from the underlying file system. ksmbd | ||
does not have the same issue, it correctly gets the values from the file | ||
system. So far this is untested with Windows SMB shares. | ||
See https://github.com/openzfsonwindows/openzfs/issues/281 | ||
See https://bugzilla.samba.org/show_bug.cgi?id=7436 | ||
Args: | ||
test_path (pathlib.Path): The path where we want to run the test | ||
""" | ||
|
||
fpath = test_path / "testfile.bin" | ||
|
||
try: | ||
with open(fpath, "wb") as test_file: | ||
csize = get_cluster_size_from_file(test_file) | ||
tc.assertGreaterEqual(csize, 512, f"Bad cluster size for {fpath}') | ||
|
||
fsize = get_sizes_from_file(test_file) | ||
tc.assertEqual( | ||
fsize, | ||
{"AllocationSize": 0, "EndOfFile": 0}, | ||
f"Wrong file size after creation of {fpath}", | ||
) | ||
|
||
preallocate_file_object(test_file, 512) | ||
|
||
fsize = get_sizes_from_file(test_file) | ||
tc.assertEqual( | ||
fsize, | ||
{"AllocationSize": csize, "EndOfFile": 0}, | ||
f"Wrong file size after preallocation of {fpath}", | ||
) | ||
|
||
test_file.write(b"\x55" * 117) | ||
|
||
fsize = get_sizes_from_file(test_file) | ||
tc.assertEqual( | ||
fsize, | ||
{"AllocationSize": csize, "EndOfFile": 0}, | ||
f"Wrong file size after write to preallocated file {fpath}", | ||
) | ||
|
||
fsize = get_sizes_from_path(fpath) | ||
tc.assertEqual( | ||
fsize, | ||
{"AllocationSize": csize, "EndOfFile": 117}, | ||
f"Wrong file size after close of preallocated file {fpath}", | ||
) | ||
finally: | ||
if os.path.isfile(fpath): | ||
os.unlink(fpath) | ||
|
||
|
||
def run_tests(test_path: pathlib.Path): | ||
test_preallocation(test_path) | ||
|
||
|
||
def main(): | ||
global args | ||
global ctx | ||
|
||
args = parse_arguments() | ||
ctx = ZfsContext(args.zfspath) | ||
|
||
if args.no_pool: | ||
run_tests(args.path) | ||
else: | ||
test_backing_file = args.path / "test.dat" | ||
|
||
with created_zpool( | ||
ctx, "test", test_backing_file, 1 * Size.GIB | ||
) as test_pool_path: | ||
logger.info( | ||
f'Created zpool named "test", backed by {test_backing_file}, mounted in {test_pool_path}' | ||
) | ||
|
||
run_tests(test_pool_path) | ||
|
||
logger.info("PASSED") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.