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