github.com/dolotech/hongbao@v0.0.0-20191130105438-fd59d7a5dda5/src/golang.org/x/sys/unix/dev_dragonfly_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 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 // Minor is a cookie instead of an index on DragonFlyBSD 21 {"/dev/null", 10, 0x00000002}, 22 {"/dev/random", 10, 0x00000003}, 23 {"/dev/urandom", 10, 0x00000004}, 24 {"/dev/zero", 10, 0x0000000c}, 25 {"/dev/bpf", 15, 0xffff00ff}, 26 } 27 for _, tc := range testCases { 28 t.Run(fmt.Sprintf("%s %v:%v", tc.path, tc.major, tc.minor), func(t *testing.T) { 29 var stat unix.Stat_t 30 err := unix.Stat(tc.path, &stat) 31 if err != nil { 32 t.Errorf("failed to stat device: %v", err) 33 return 34 } 35 36 dev := uint64(stat.Rdev) 37 if unix.Major(dev) != tc.major { 38 t.Errorf("for %s Major(%#x) == %d, want %d", tc.path, dev, unix.Major(dev), tc.major) 39 } 40 if unix.Minor(dev) != tc.minor { 41 t.Errorf("for %s Minor(%#x) == %d, want %d", tc.path, dev, unix.Minor(dev), tc.minor) 42 } 43 if unix.Mkdev(tc.major, tc.minor) != dev { 44 t.Errorf("for %s Mkdev(%d, %d) == %#x, want %#x", tc.path, tc.major, tc.minor, unix.Mkdev(tc.major, tc.minor), dev) 45 } 46 }) 47 } 48 }