dev_dragonfly_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. package unix_test
  5. import (
  6. "fmt"
  7. "testing"
  8. "golang.org/x/sys/unix"
  9. )
  10. func TestDevices(t *testing.T) {
  11. testCases := []struct {
  12. path string
  13. major uint32
  14. minor uint32
  15. }{
  16. // Minor is a cookie instead of an index on DragonFlyBSD
  17. {"/dev/null", 10, 0x00000002},
  18. {"/dev/random", 10, 0x00000003},
  19. {"/dev/urandom", 10, 0x00000004},
  20. {"/dev/zero", 10, 0x0000000c},
  21. {"/dev/bpf", 15, 0xffff00ff},
  22. }
  23. for _, tc := range testCases {
  24. t.Run(fmt.Sprintf("%s %v:%v", tc.path, tc.major, tc.minor), func(t *testing.T) {
  25. var stat unix.Stat_t
  26. err := unix.Stat(tc.path, &stat)
  27. if err != nil {
  28. t.Errorf("failed to stat device: %v", err)
  29. return
  30. }
  31. dev := uint64(stat.Rdev)
  32. if unix.Major(dev) != tc.major {
  33. t.Errorf("for %s Major(%#x) == %d, want %d", tc.path, dev, unix.Major(dev), tc.major)
  34. }
  35. if unix.Minor(dev) != tc.minor {
  36. t.Errorf("for %s Minor(%#x) == %d, want %d", tc.path, dev, unix.Minor(dev), tc.minor)
  37. }
  38. if unix.Mkdev(tc.major, tc.minor) != dev {
  39. t.Errorf("for %s Mkdev(%d, %d) == %#x, want %#x", tc.path, tc.major, tc.minor, unix.Mkdev(tc.major, tc.minor), dev)
  40. }
  41. })
  42. }
  43. }