Source file src/syscall/syscall_bsd_test.go

     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  //go:build darwin || dragonfly || freebsd || openbsd
     6  
     7  package syscall_test
     8  
     9  import (
    10  	"os/exec"
    11  	"syscall"
    12  	"testing"
    13  )
    14  
    15  const MNT_WAIT = 1
    16  const MNT_NOWAIT = 2
    17  
    18  func TestGetfsstat(t *testing.T) {
    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)
    22  	if err != nil {
    23  		t.Fatal(err)
    24  	}
    25  
    26  	data := make([]syscall.Statfs_t, n)
    27  	n2, err := syscall.Getfsstat(data, flags)
    28  	t.Logf("Getfsstat([]syscall.Statfs_t, %d) = (%v, %v)", flags, n2, err)
    29  	if err != nil {
    30  		t.Fatal(err)
    31  	}
    32  	if n != n2 {
    33  		t.Errorf("Getfsstat(nil) = %d, but subsequent Getfsstat(slice) = %d", n, n2)
    34  	}
    35  	for i, stat := range data {
    36  		if stat == (syscall.Statfs_t{}) {
    37  			t.Errorf("index %v is an empty Statfs_t struct", i)
    38  		}
    39  	}
    40  	if t.Failed() {
    41  		for i, stat := range data[:n2] {
    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  	}
    51  }
    52  

View as plain text