From 418715ba6fdda741706a46b875e1980f057c47a6 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 26 Oct 2020 14:10:26 +0100 Subject: [PATCH] unix: compare Stat_t members when checking Stat vs. Fstatat in TestFstatat TestFstatat regularly fails on the dragonfly-amd64 builder due to mismatching Stat_t info returned by the calls to Fstatat vs. Stat (most likely due to Atime changing). Fix the test by just comparing some well known members. This was already fixed for the Lstat call in CL 212417. Fixes golang/go#42208 Change-Id: I3e241470d373338b9716bb9ce0265a105db2720d Reviewed-on: https://go-review.googlesource.com/c/sys/+/265018 Trust: Tobias Klauser Run-TryBot: Tobias Klauser TryBot-Result: Go Bot Reviewed-by: Bryan C. Mills --- unix/syscall_unix_test.go | 44 ++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/unix/syscall_unix_test.go b/unix/syscall_unix_test.go index 54bce4e2..bebc1694 100644 --- a/unix/syscall_unix_test.go +++ b/unix/syscall_unix_test.go @@ -653,6 +653,27 @@ func TestGetwd(t *testing.T) { } } +func compareStat_t(t *testing.T, otherStat string, st1, st2 *unix.Stat_t) { + if st2.Dev != st1.Dev { + t.Errorf("%s/Fstatat: got dev %v, expected %v", otherStat, st2.Dev, st1.Dev) + } + if st2.Ino != st1.Ino { + t.Errorf("%s/Fstatat: got ino %v, expected %v", otherStat, st2.Ino, st1.Ino) + } + if st2.Mode != st1.Mode { + t.Errorf("%s/Fstatat: got mode %v, expected %v", otherStat, st2.Mode, st1.Mode) + } + if st2.Uid != st1.Uid { + t.Errorf("%s/Fstatat: got uid %v, expected %v", otherStat, st2.Uid, st1.Uid) + } + if st2.Gid != st1.Gid { + t.Errorf("%s/Fstatat: got gid %v, expected %v", otherStat, st2.Gid, st1.Gid) + } + if st2.Size != st1.Size { + t.Errorf("%s/Fstatat: got size %v, expected %v", otherStat, st2.Size, st1.Size) + } +} + func TestFstatat(t *testing.T) { defer chtmpdir(t)() @@ -670,9 +691,7 @@ func TestFstatat(t *testing.T) { t.Fatalf("Fstatat: %v", err) } - if st1 != st2 { - t.Errorf("Fstatat: returned stat does not match Stat") - } + compareStat_t(t, "Stat", &st1, &st2) err = os.Symlink("file1", "symlink1") if err != nil { @@ -689,24 +708,7 @@ func TestFstatat(t *testing.T) { t.Fatalf("Fstatat: %v", err) } - if st2.Dev != st1.Dev { - t.Errorf("Fstatat: got dev %v, expected %v", st2.Dev, st1.Dev) - } - if st2.Ino != st1.Ino { - t.Errorf("Fstatat: got ino %v, expected %v", st2.Ino, st1.Ino) - } - if st2.Mode != st1.Mode { - t.Errorf("Fstatat: got mode %v, expected %v", st2.Mode, st1.Mode) - } - if st2.Uid != st1.Uid { - t.Errorf("Fstatat: got uid %v, expected %v", st2.Uid, st1.Uid) - } - if st2.Gid != st1.Gid { - t.Errorf("Fstatat: got gid %v, expected %v", st2.Gid, st1.Gid) - } - if st2.Size != st1.Size { - t.Errorf("Fstatat: got size %v, expected %v", st2.Size, st1.Size) - } + compareStat_t(t, "Lstat", &st1, &st2) } func TestFchmodat(t *testing.T) {