Preetam Jinka | 4abbd4a | 2014-04-10 13:58:03 +1000 | [diff] [blame] | 1 | // Copyright 2014 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | // +build darwin dragonfly freebsd openbsd |
| 6 | |
| 7 | package syscall_test |
| 8 | |
| 9 | import ( |
Brad Fitzpatrick | 6db13e0 | 2016-09-06 04:11:59 +0000 | [diff] [blame] | 10 | "os/exec" |
Preetam Jinka | 4abbd4a | 2014-04-10 13:58:03 +1000 | [diff] [blame] | 11 | "syscall" |
| 12 | "testing" |
| 13 | ) |
| 14 | |
| 15 | const MNT_WAIT = 1 |
Brad Fitzpatrick | a4bdd64 | 2016-09-06 17:02:19 +0000 | [diff] [blame] | 16 | const MNT_NOWAIT = 2 |
Preetam Jinka | 4abbd4a | 2014-04-10 13:58:03 +1000 | [diff] [blame] | 17 | |
| 18 | func TestGetfsstat(t *testing.T) { |
Brad Fitzpatrick | a4bdd64 | 2016-09-06 17:02:19 +0000 | [diff] [blame] | 19 | const flags = MNT_NOWAIT // see Issue 16937 |
| 20 | n, err := syscall.Getfsstat(nil, flags) |
| 21 | t.Logf("Getfsstat(nil, %d) = (%v, %v)", flags, n, err) |
Preetam Jinka | 4abbd4a | 2014-04-10 13:58:03 +1000 | [diff] [blame] | 22 | if err != nil { |
| 23 | t.Fatal(err) |
| 24 | } |
| 25 | |
| 26 | data := make([]syscall.Statfs_t, n) |
Brad Fitzpatrick | a4bdd64 | 2016-09-06 17:02:19 +0000 | [diff] [blame] | 27 | n2, err := syscall.Getfsstat(data, flags) |
| 28 | t.Logf("Getfsstat([]syscall.Statfs_t, %d) = (%v, %v)", flags, n2, err) |
Preetam Jinka | 4abbd4a | 2014-04-10 13:58:03 +1000 | [diff] [blame] | 29 | if err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
Brad Fitzpatrick | a4bdd64 | 2016-09-06 17:02:19 +0000 | [diff] [blame] | 32 | if n != n2 { |
| 33 | t.Errorf("Getfsstat(nil) = %d, but subsequent Getfsstat(slice) = %d", n, n2) |
| 34 | } |
Brad Fitzpatrick | b040bc9 | 2016-08-31 04:30:03 +0000 | [diff] [blame] | 35 | for i, stat := range data { |
Brad Fitzpatrick | a4bdd64 | 2016-09-06 17:02:19 +0000 | [diff] [blame] | 36 | if stat == (syscall.Statfs_t{}) { |
Brad Fitzpatrick | b040bc9 | 2016-08-31 04:30:03 +0000 | [diff] [blame] | 37 | t.Errorf("index %v is an empty Statfs_t struct", i) |
Preetam Jinka | 4abbd4a | 2014-04-10 13:58:03 +1000 | [diff] [blame] | 38 | } |
| 39 | } |
Brad Fitzpatrick | 6db13e0 | 2016-09-06 04:11:59 +0000 | [diff] [blame] | 40 | if t.Failed() { |
Brad Fitzpatrick | a4bdd64 | 2016-09-06 17:02:19 +0000 | [diff] [blame] | 41 | for i, stat := range data[:n2] { |
Brad Fitzpatrick | 6db13e0 | 2016-09-06 04:11:59 +0000 | [diff] [blame] | 42 | t.Logf("data[%v] = %+v", i, stat) |
| 43 | } |
| 44 | mount, err := exec.Command("mount").CombinedOutput() |
| 45 | if err != nil { |
| 46 | t.Logf("mount: %v\n%s", err, mount) |
| 47 | } else { |
| 48 | t.Logf("mount: %s", mount) |
| 49 | } |
| 50 | } |
Preetam Jinka | 4abbd4a | 2014-04-10 13:58:03 +1000 | [diff] [blame] | 51 | } |