OSDN Git Service

new repo
[bytom/vapor.git] / vendor / golang.org / x / sys / unix / dev_darwin_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 package unix_test
6
7 import (
8         "fmt"
9         "testing"
10
11         "golang.org/x/sys/unix"
12 )
13
14 func TestDevices(t *testing.T) {
15         testCases := []struct {
16                 path  string
17                 major uint32
18                 minor uint32
19         }{
20                 // Most of the device major/minor numbers on Darwin are
21                 // dynamically generated by devfs. These are some well-known
22                 // static numbers.
23                 {"/dev/ttyp0", 4, 0},
24                 {"/dev/ttys0", 4, 48},
25                 {"/dev/ptyp0", 5, 0},
26                 {"/dev/ptyr0", 5, 32},
27         }
28         for _, tc := range testCases {
29                 t.Run(fmt.Sprintf("%s %v:%v", tc.path, tc.major, tc.minor), func(t *testing.T) {
30                         var stat unix.Stat_t
31                         err := unix.Stat(tc.path, &stat)
32                         if err != nil {
33                                 t.Errorf("failed to stat device: %v", err)
34                                 return
35                         }
36
37                         dev := uint64(stat.Rdev)
38                         if unix.Major(dev) != tc.major {
39                                 t.Errorf("for %s Major(%#x) == %d, want %d", tc.path, dev, unix.Major(dev), tc.major)
40                         }
41                         if unix.Minor(dev) != tc.minor {
42                                 t.Errorf("for %s Minor(%#x) == %d, want %d", tc.path, dev, unix.Minor(dev), tc.minor)
43                         }
44                         if unix.Mkdev(tc.major, tc.minor) != dev {
45                                 t.Errorf("for %s Mkdev(%d, %d) == %#x, want %#x", tc.path, tc.major, tc.minor, unix.Mkdev(tc.major, tc.minor), dev)
46                         }
47                 })
48         }
49 }