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.
11 "golang.org/x/sys/unix"
14 func TestDevices(t *testing.T) {
15 testCases := []struct {
20 // well known major/minor numbers according to
21 // https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide/devices.txt
24 {"/dev/random", 1, 8},
26 {"/dev/urandom", 1, 9},
29 for _, tc := range testCases {
30 t.Run(fmt.Sprintf("%s %v:%v", tc.path, tc.major, tc.minor), func(t *testing.T) {
32 err := unix.Stat(tc.path, &stat)
34 t.Errorf("failed to stat device: %v", err)
38 dev := uint64(stat.Rdev)
39 if unix.Major(dev) != tc.major {
40 t.Errorf("for %s Major(%#x) == %d, want %d", tc.path, dev, unix.Major(dev), tc.major)
42 if unix.Minor(dev) != tc.minor {
43 t.Errorf("for %s Minor(%#x) == %d, want %d", tc.path, dev, unix.Minor(dev), tc.minor)
45 if unix.Mkdev(tc.major, tc.minor) != dev {
46 t.Errorf("for %s Mkdev(%d, %d) == %#x, want %#x", tc.path, tc.major, tc.minor, unix.Mkdev(tc.major, tc.minor), dev)