github.com/alexis81/domosgo@v0.0.0-20191016125037-5aee90a434af/Domos/src/golang.org/x/sys/unix/dev_solaris_test.go (about) 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 go1.7 6 7 package unix_test 8 9 import ( 10 "fmt" 11 "testing" 12 13 "golang.org/x/sys/unix" 14 ) 15 16 func TestDevices(t *testing.T) { 17 testCases := []struct { 18 path string 19 major uint32 20 minor uint32 21 }{ 22 // Well-known major/minor numbers on OpenSolaris according to 23 // /etc/name_to_major 24 {"/dev/zero", 134, 12}, 25 {"/dev/null", 134, 2}, 26 {"/dev/ptyp0", 172, 0}, 27 {"/dev/ttyp0", 175, 0}, 28 {"/dev/ttyp1", 175, 1}, 29 } 30 for _, tc := range testCases { 31 t.Run(fmt.Sprintf("%s %v:%v", tc.path, tc.major, tc.minor), func(t *testing.T) { 32 var stat unix.Stat_t 33 err := unix.Stat(tc.path, &stat) 34 if err != nil { 35 t.Errorf("failed to stat device: %v", err) 36 return 37 } 38 39 dev := uint64(stat.Rdev) 40 if unix.Major(dev) != tc.major { 41 t.Errorf("for %s Major(%#x) == %d, want %d", tc.path, dev, unix.Major(dev), tc.major) 42 } 43 if unix.Minor(dev) != tc.minor { 44 t.Errorf("for %s Minor(%#x) == %d, want %d", tc.path, dev, unix.Minor(dev), tc.minor) 45 } 46 if unix.Mkdev(tc.major, tc.minor) != dev { 47 t.Errorf("for %s Mkdev(%d, %d) == %#x, want %#x", tc.path, tc.major, tc.minor, unix.Mkdev(tc.major, tc.minor), dev) 48 } 49 }) 50 } 51 }