lib/std/posix/test.zig: don't compare blksize in "fstatat"

In trying to reproduce the race in #24380, my system tripped over the stat
"blocks" field changing in this test.  The value was almost always 8
(effectively 4k) or very infrequently 0 (I saw the 0 from both `fstat` and
`fstatat`).  I believe the underlying filesystem is free to asynchronously
change this value. For example, if it migrates a file between some
"inline" or maybe journal storage, and actual on-disk blocks.  So it seems
plausible that its allowed to change between stat calls.

Breaking up the struct comparison this way means we also don't compare any
of the padding or "reserved" fields, too.  And we can narrow down the
s390x-linux work-around.
This commit is contained in:
Pat Tullmann 2025-07-19 09:34:04 -07:00
parent caf80e90b8
commit cf47d283d1

View File

@ -395,11 +395,27 @@ test "fstatat" {
// now repeat but using `fstatat` instead
const statat = try posix.fstatat(tmp.dir.fd, "file.txt", posix.AT.SYMLINK_NOFOLLOW);
// s390x-linux does not have nanosecond precision for fstat(), but it does for fstatat(). As a
// result, comparing the two structures is doomed to fail.
if (builtin.cpu.arch == .s390x and builtin.os.tag == .linux) return error.SkipZigTest;
try expectEqual(stat.dev, statat.dev);
try expectEqual(stat.ino, statat.ino);
try expectEqual(stat.nlink, statat.nlink);
try expectEqual(stat.mode, statat.mode);
try expectEqual(stat.uid, statat.uid);
try expectEqual(stat.gid, statat.gid);
try expectEqual(stat.rdev, statat.rdev);
try expectEqual(stat.size, statat.size);
try expectEqual(stat.blksize, statat.blksize);
try expectEqual(stat, statat);
// The stat.blocks/statat.blocks count is managed by the filesystem and may
// change if the file is stored in a journal or "inline".
// try expectEqual(stat.blocks, statat.blocks);
// s390x-linux does not have nanosecond precision for fstat(), but it does for
// fstatat(). As a result, comparing the timestamps isn't worth the effort
if (!(builtin.cpu.arch == .s390x and builtin.os.tag == .linux)) {
try expectEqual(stat.atime(), statat.atime());
try expectEqual(stat.mtime(), statat.mtime());
try expectEqual(stat.ctime(), statat.ctime());
}
}
test "readlinkat" {