From a50acf3fe0733bded7ea14a23f6a9349baacbb28 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 25 Feb 2021 10:34:28 +0100 Subject: [PATCH] unix: fix IoctlFileDedupeRange test The test introduced in CL 284352 breaks on several builders, either with IoctlFileDedupeRange returning ENOTTY (as already seen for android in the TryBot run) or returning EINVAL in the FileDedupeRange.Status field. Both seem to indicate that the underlying filesystem doesn't support deduplication, so skip the test in these cases. Also rename the test to indicate the func it is testing. Change-Id: I29553a5fc95f98335cb233f05d4c2dfb5640dc4c Reviewed-on: https://go-review.googlesource.com/c/sys/+/295911 Trust: Tobias Klauser Run-TryBot: Tobias Klauser TryBot-Result: Go Bot Reviewed-by: Matt Layher --- unix/syscall_linux_test.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/unix/syscall_linux_test.go b/unix/syscall_linux_test.go index 699e56f2..ccc6f199 100644 --- a/unix/syscall_linux_test.go +++ b/unix/syscall_linux_test.go @@ -797,13 +797,7 @@ func TestOpenat2(t *testing.T) { } } -func TestFideduperange(t *testing.T) { - if runtime.GOOS == "android" { - // The ioctl in the build robot android-amd64 returned ENOTTY, - // an error not documented for that syscall. - t.Skip("FIDEDUPERANGE ioctl doesn't work on android, skipping test") - } - +func TestIoctlFileDedupeRange(t *testing.T) { f1, err := ioutil.TempFile("", t.Name()) if err != nil { t.Fatal(err) @@ -855,7 +849,7 @@ func TestFideduperange(t *testing.T) { }} err = unix.IoctlFileDedupeRange(int(f1.Fd()), &dedupe) - if err == unix.EOPNOTSUPP || err == unix.EINVAL { + if err == unix.EOPNOTSUPP || err == unix.EINVAL || err == unix.ENOTTY { t.Skip("deduplication not supported on this filesystem") } else if err != nil { t.Fatal(err) @@ -863,9 +857,11 @@ func TestFideduperange(t *testing.T) { // The first Info should be equal if dedupe.Info[0].Status < 0 { - // We expect status to be a negated errno - t.Errorf("Unexpected error in FileDedupeRange: %s", - unix.ErrnoName(unix.Errno(-dedupe.Info[0].Status))) + errno := unix.Errno(-dedupe.Info[0].Status) + if errno == unix.EINVAL { + t.Skip("deduplication not supported on this filesystem") + } + t.Errorf("Unexpected error in FileDedupeRange: %s", unix.ErrnoName(errno)) } else if dedupe.Info[0].Status == unix.FILE_DEDUPE_RANGE_DIFFERS { t.Errorf("Unexpected different bytes in FileDedupeRange") } @@ -876,9 +872,11 @@ func TestFideduperange(t *testing.T) { // The second Info should be different if dedupe.Info[1].Status < 0 { - // We expect status to be a negated errno - t.Errorf("Unexpected error in FileDedupeRange: %s", - unix.ErrnoName(unix.Errno(-dedupe.Info[1].Status))) + errno := unix.Errno(-dedupe.Info[1].Status) + if errno == unix.EINVAL { + t.Skip("deduplication not supported on this filesystem") + } + t.Errorf("Unexpected error in FileDedupeRange: %s", unix.ErrnoName(errno)) } else if dedupe.Info[1].Status == unix.FILE_DEDUPE_RANGE_SAME { t.Errorf("Unexpected equal bytes in FileDedupeRange") }