github.com/aayushi-bansal/sys@v0.0.0-20180118120756-90d962a959d8/unix/dev_linux_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 according to 23 // https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide/devices.txt 24 {"/dev/null", 1, 3}, 25 {"/dev/zero", 1, 5}, 26 {"/dev/random", 1, 8}, 27 {"/dev/full", 1, 7}, 28 {"/dev/urandom", 1, 9}, 29 {"/dev/tty", 5, 0}, 30 } 31 for _, tc := range testCases { 32 t.Run(fmt.Sprintf("%s %v:%v", tc.path, tc.major, tc.minor), func(t *testing.T) { 33 var stat unix.Stat_t 34 err := unix.Stat(tc.path, &stat) 35 if err != nil { 36 t.Errorf("failed to stat device: %v", err) 37 return 38 } 39 40 dev := uint64(stat.Rdev) 41 if unix.Major(dev) != tc.major { 42 t.Errorf("for %s Major(%#x) == %d, want %d", tc.path, dev, unix.Major(dev), tc.major) 43 } 44 if unix.Minor(dev) != tc.minor { 45 t.Errorf("for %s Minor(%#x) == %d, want %d", tc.path, dev, unix.Minor(dev), tc.minor) 46 } 47 if unix.Mkdev(tc.major, tc.minor) != dev { 48 t.Errorf("for %s Mkdev(%d, %d) == %#x, want %#x", tc.path, tc.major, tc.minor, unix.Mkdev(tc.major, tc.minor), dev) 49 } 50 }) 51 52 } 53 }