dev_openbsd_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. // +build go1.7
  5. package unix_test
  6. import (
  7. "fmt"
  8. "testing"
  9. "golang.org/x/sys/unix"
  10. )
  11. func TestDevices(t *testing.T) {
  12. testCases := []struct {
  13. path string
  14. major uint32
  15. minor uint32
  16. }{
  17. // well known major/minor numbers according to /dev/MAKEDEV on
  18. // OpenBSD 6.0
  19. {"/dev/null", 2, 2},
  20. {"/dev/zero", 2, 12},
  21. {"/dev/ttyp0", 5, 0},
  22. {"/dev/ttyp1", 5, 1},
  23. {"/dev/random", 45, 0},
  24. {"/dev/srandom", 45, 1},
  25. {"/dev/urandom", 45, 2},
  26. {"/dev/arandom", 45, 3},
  27. }
  28. for _, tc := range testCases {
  29. t.Run(fmt.Sprintf("%s %v:%v", tc.path, tc.major, tc.minor), func(t *testing.T) {
  30. var stat unix.Stat_t
  31. err := unix.Stat(tc.path, &stat)
  32. if err != nil {
  33. t.Errorf("failed to stat device: %v", err)
  34. return
  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. }