Black Lives Matter. Support the Equal Justice Initiative.

Source file src/syscall/syscall_bsd_test.go

Documentation: syscall

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

View as plain text