You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

57 lines
1.7 KiB

#!/usr/bin/env python3
import os
import sys
import tempfile
from posix_parity import cleanup_paths
from posix_parity import compare_calls
from posix_parity import fail
from posix_parity import join
from posix_parity import touch
def main():
if len(sys.argv) != 2:
print("usage: TEST_posix_truncate_ftruncate <mountpoint>", file=sys.stderr)
return 1
mount = sys.argv[1]
with tempfile.TemporaryDirectory() as native:
merge_file = join(mount, "posix-truncate/file")
native_file = join(native, "posix-truncate/file")
merge_missing = join(mount, "posix-truncate/missing")
native_missing = join(native, "posix-truncate/missing")
cleanup_paths([merge_file])
touch(merge_file, b"1234567890")
touch(native_file, b"1234567890")
err = compare_calls("truncate shrink", lambda: os.truncate(merge_file, 3), lambda: os.truncate(native_file, 3))
if err:
return fail(err)
err = compare_calls("truncate ENOENT", lambda: os.truncate(merge_missing, 1), lambda: os.truncate(native_missing, 1))
if err:
return fail(err)
mfd = os.open(merge_file, os.O_RDWR)
nfd = os.open(native_file, os.O_RDWR)
try:
err = compare_calls("ftruncate grow", lambda: os.ftruncate(mfd, 16), lambda: os.ftruncate(nfd, 16))
if err:
return fail(err)
finally:
os.close(mfd)
os.close(nfd)
err = compare_calls("ftruncate EBADF", lambda: os.ftruncate(-1, 4), lambda: os.ftruncate(-1, 4))
if err:
return fail(err)
return 0
if __name__ == "__main__":
raise SystemExit(main())