浏览代码

unix: fix TestGetfsstat the same way as CL 28550 in pkg syscall

Same as https://golang.org/cl/28550 but for x/sys/unix.

Updates golang/go#16937

Change-Id: Ie93df8ff1c40a7f2d98f1fb3ecf6110330bf1cbc
Reviewed-on: https://go-review.googlesource.com/28585
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Brad Fitzpatrick 9 年之前
父节点
当前提交
30de6d19a3
共有 1 个文件被更改,包括 22 次插入7 次删除
  1. 22 7
      unix/syscall_bsd_test.go

+ 22 - 7
unix/syscall_bsd_test.go

@@ -7,6 +7,7 @@
 package unix_test
 
 import (
+	"os/exec"
 	"runtime"
 	"testing"
 
@@ -14,23 +15,37 @@ import (
 )
 
 const MNT_WAIT = 1
+const MNT_NOWAIT = 2
 
 func TestGetfsstat(t *testing.T) {
-	n, err := unix.Getfsstat(nil, MNT_WAIT)
+	const flags = MNT_NOWAIT // see golang.org/issue/16937
+	n, err := unix.Getfsstat(nil, flags)
 	if err != nil {
 		t.Fatal(err)
 	}
 
 	data := make([]unix.Statfs_t, n)
-	n, err = unix.Getfsstat(data, MNT_WAIT)
+	n2, err := unix.Getfsstat(data, flags)
 	if err != nil {
 		t.Fatal(err)
 	}
-
-	empty := unix.Statfs_t{}
-	for _, stat := range data {
-		if stat == empty {
-			t.Fatal("an empty Statfs_t struct was returned")
+	if n != n2 {
+		t.Errorf("Getfsstat(nil) = %d, but subsequent Getfsstat(slice) = %d", n, n2)
+	}
+	for i, stat := range data {
+		if stat == (unix.Statfs_t{}) {
+			t.Errorf("index %v is an empty Statfs_t struct", i)
+		}
+	}
+	if t.Failed() {
+		for i, stat := range data[:n2] {
+			t.Logf("data[%v] = %+v", i, stat)
+		}
+		mount, err := exec.Command("mount").CombinedOutput()
+		if err != nil {
+			t.Logf("mount: %v\n%s", err, mount)
+		} else {
+			t.Logf("mount: %s", mount)
 		}
 	}
 }