github.com/Kalvelign/golang-windows-sys-lib@v0.0.0-20221121121202-63da651435e1/unix/syscall_netbsd_test.go (about)

     1  // Copyright 2018 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  package unix_test
     6  
     7  import (
     8  	"os"
     9  	"testing"
    10  
    11  	"golang.org/x/sys/unix"
    12  )
    13  
    14  // stringsFromByteSlice converts a sequence of attributes to a []string.
    15  // On NetBSD, each entry consists of a single byte containing the length
    16  // of the attribute name, followed by the attribute name.
    17  // The name is _not_ NULL-terminated.
    18  func stringsFromByteSlice(buf []byte) []string {
    19  	var result []string
    20  	i := 0
    21  	for i < len(buf) {
    22  		next := i + 1 + int(buf[i])
    23  		result = append(result, string(buf[i+1:next]))
    24  		i = next
    25  	}
    26  	return result
    27  }
    28  
    29  func TestIoctlPtmget(t *testing.T) {
    30  	fd, err := unix.Open("/dev/ptmx", unix.O_NOCTTY|unix.O_RDWR, 0666)
    31  	if err != nil {
    32  		t.Skip("failed to open /dev/ptmx, skipping test")
    33  	}
    34  	defer unix.Close(fd)
    35  
    36  	ptm, err := unix.IoctlGetPtmget(fd, unix.TIOCPTSNAME)
    37  	if err != nil {
    38  		t.Fatalf("IoctlGetPtmget: %v\n", err)
    39  	}
    40  
    41  	t.Logf("sfd = %v, ptsname = %v", ptm.Sfd, unix.ByteSliceToString(ptm.Sn[:]))
    42  }
    43  
    44  func TestStatvfs(t *testing.T) {
    45  	defer chtmpdir(t)()
    46  	touch(t, "file1")
    47  
    48  	var statvfs1, statvfs2 unix.Statvfs_t
    49  	err := unix.Statvfs("file1", &statvfs1)
    50  	if err != nil {
    51  		t.Fatalf("Statvfs: %v", err)
    52  	}
    53  
    54  	f, err := os.Open("file1")
    55  	if err != nil {
    56  		t.Fatal(err)
    57  	}
    58  	defer f.Close()
    59  
    60  	err = unix.Fstatvfs(int(f.Fd()), &statvfs2)
    61  	if err != nil {
    62  		t.Fatalf("Fstatvfs: %v", err)
    63  	}
    64  
    65  	if statvfs2.Fsid != statvfs1.Fsid {
    66  		t.Errorf("Fstatvfs: got fsid %v, expected %v", statvfs2.Fsid, statvfs1.Fsid)
    67  	}
    68  	if statvfs2.Owner != statvfs1.Owner {
    69  		t.Errorf("Fstatvfs: got owner %v, expected %v", statvfs2.Owner, statvfs1.Owner)
    70  	}
    71  	if statvfs2.Fstypename != statvfs1.Fstypename {
    72  		t.Errorf("Fstatvfs: got fstypename %s, expected %s", statvfs2.Fstypename, statvfs1.Fstypename)
    73  	}
    74  }