.gitignore added
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / sys@v0.0.0-20210124154548-22da62e12c0c / unix / syscall_solaris_test.go
1 // Copyright 2017 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 // +build solaris
6
7 package unix_test
8
9 import (
10         "os/exec"
11         "testing"
12
13         "golang.org/x/sys/unix"
14 )
15
16 func TestPipe2(t *testing.T) {
17         const s = "hello"
18         var pipes [2]int
19         err := unix.Pipe2(pipes[:], 0)
20         if err != nil {
21                 t.Fatalf("pipe2: %v", err)
22         }
23         r := pipes[0]
24         w := pipes[1]
25         go func() {
26                 n, err := unix.Write(w, []byte(s))
27                 if err != nil {
28                         t.Errorf("bad write: %v", err)
29                         return
30                 }
31                 if n != len(s) {
32                         t.Errorf("bad write count: %d", n)
33                         return
34                 }
35                 err = unix.Close(w)
36                 if err != nil {
37                         t.Errorf("bad close: %v", err)
38                         return
39                 }
40         }()
41         var buf [10 + len(s)]byte
42         n, err := unix.Read(r, buf[:])
43         if err != nil {
44                 t.Fatalf("bad read: %v", err)
45         }
46         if n != len(s) {
47                 t.Fatalf("bad read count: %d", n)
48         }
49         if string(buf[:n]) != s {
50                 t.Fatalf("bad contents: %s", string(buf[:n]))
51         }
52         err = unix.Close(r)
53         if err != nil {
54                 t.Fatalf("bad close: %v", err)
55         }
56 }
57
58 func TestStatvfs(t *testing.T) {
59         if err := unix.Statvfs("", nil); err == nil {
60                 t.Fatal(`Statvfs("") expected failure`)
61         }
62
63         statvfs := unix.Statvfs_t{}
64         if err := unix.Statvfs("/", &statvfs); err != nil {
65                 t.Errorf(`Statvfs("/") failed: %v`, err)
66         }
67
68         if t.Failed() {
69                 mount, err := exec.Command("mount").CombinedOutput()
70                 if err != nil {
71                         t.Logf("mount: %v\n%s", err, mount)
72                 } else {
73                         t.Logf("mount: %s", mount)
74                 }
75         }
76 }