| 1 |
// Copyright 2023 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 |
//go:build netbsd |
| 6 |
|
| 7 |
package unix_test |
| 8 |
|
| 9 |
import ( |
| 10 |
"os/exec" |
| 11 |
"testing" |
| 12 |
|
| 13 |
"golang.org/x/sys/unix" |
| 14 |
) |
| 15 |
|
| 16 |
func TestGetvfsstat(t *testing.T) { |
| 17 |
n, err := unix.Getvfsstat(nil, unix.MNT_NOWAIT) |
| 18 |
if err != nil { |
| 19 |
t.Fatal(err) |
| 20 |
} |
| 21 |
|
| 22 |
data := make([]unix.Statvfs_t, n) |
| 23 |
n2, err := unix.Getvfsstat(data, unix.MNT_NOWAIT) |
| 24 |
if err != nil { |
| 25 |
t.Fatal(err) |
| 26 |
} |
| 27 |
if n != n2 { |
| 28 |
t.Errorf("Getvfsstat(nil) = %d, but subsequent Getvfsstat(slice) = %d", n, n2) |
| 29 |
} |
| 30 |
for i, stat := range data { |
| 31 |
if stat == (unix.Statvfs_t{}) { |
| 32 |
t.Errorf("index %v is an empty Statvfs_t struct", i) |
| 33 |
} |
| 34 |
t.Logf("%s on %s", unix.ByteSliceToString(stat.Mntfromname[:]), unix.ByteSliceToString(stat.Mntonname[:])) |
| 35 |
} |
| 36 |
if t.Failed() { |
| 37 |
for i, stat := range data[:n2] { |
| 38 |
t.Logf("data[%v] = %+v", i, stat) |
| 39 |
} |
| 40 |
mount, err := exec.Command("mount").CombinedOutput() |
| 41 |
if err != nil { |
| 42 |
t.Logf("mount: %v\n%s", err, mount) |
| 43 |
} else { |
| 44 |
t.Logf("mount: %s", mount) |
| 45 |
} |
| 46 |
} |
| 47 |
} |