Skip to content

Commit b238545

Browse files
authored
bpo-35772: Fix test_tarfile on ppc64 (GH-11606)
Fix sparse file tests of test_tarfile on ppc64le with the tmpfs filesystem. Fix the function testing if the filesystem supports sparse files: create a file which contains data and "holes", instead of creating a file which contains no data. tmpfs effective block size is a page size (tmpfs lives in the page cache). RHEL uses 64 KiB pages on aarch64, ppc64 and ppc64le, only s390x and x86_64 use 4 KiB pages, whereas the test punch holes of 4 KiB. test.pythoninfo: Add resource.getpagesize().
1 parent 222d303 commit b238545

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Lib/test/pythoninfo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@ def collect_resource(info_add):
529529
value = resource.getrlimit(key)
530530
info_add('resource.%s' % name, value)
531531

532+
call_func(info_add, 'resource.pagesize', resource, 'getpagesize')
533+
532534

533535
def collect_test_socket(info_add):
534536
try:

Lib/test/test_tarfile.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,16 +973,21 @@ def test_sparse_file_10(self):
973973
def _fs_supports_holes():
974974
# Return True if the platform knows the st_blocks stat attribute and
975975
# uses st_blocks units of 512 bytes, and if the filesystem is able to
976-
# store holes in files.
976+
# store holes of 4 KiB in files.
977+
#
978+
# The function returns False if page size is larger than 4 KiB.
979+
# For example, ppc64 uses pages of 64 KiB.
977980
if sys.platform.startswith("linux"):
978981
# Linux evidentially has 512 byte st_blocks units.
979982
name = os.path.join(TEMPDIR, "sparse-test")
980983
with open(name, "wb") as fobj:
984+
# Seek to "punch a hole" of 4 KiB
981985
fobj.seek(4096)
986+
fobj.write(b'x' * 4096)
982987
fobj.truncate()
983988
s = os.stat(name)
984989
support.unlink(name)
985-
return s.st_blocks == 0
990+
return (s.st_blocks * 512 < s.st_size)
986991
else:
987992
return False
988993

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Fix sparse file tests of test_tarfile on ppc64 with the tmpfs filesystem. Fix
2+
the function testing if the filesystem supports sparse files: create a file
3+
which contains data and "holes", instead of creating a file which contains no
4+
data. tmpfs effective block size is a page size (tmpfs lives in the page cache).
5+
RHEL uses 64 KiB pages on aarch64, ppc64, ppc64le, only s390x and x86_64 use 4
6+
KiB pages, whereas the test punch holes of 4 KiB.

0 commit comments

Comments
 (0)