-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfileutils_test.go
68 lines (58 loc) · 1.29 KB
/
fileutils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package fileutils
import (
"os"
"syscall"
"testing"
)
type device struct {
device string
major uint64
minor uint64
}
func TestDeviceNumbers(t *testing.T) {
devices := []device{
{
device: "/dev/mem",
major: 1,
minor: 1,
},
{
device: "/dev/urandom",
major: 1,
minor: 9,
},
{
device: "/dev/tty0",
major: 4,
minor: 0,
},
{
device: "/dev/tty",
major: 5,
minor: 0,
},
}
for _, device := range devices {
si, err := os.Lstat(device.device)
if err != nil {
t.Errorf("not able to Lstat the device: %v", err)
}
st, ok := si.Sys().(*syscall.Stat_t)
if !ok {
t.Errorf("could not convert to syscall.Stat_t")
}
internalDevice := uint64(st.Rdev)
givenMajor := major(internalDevice)
if givenMajor != device.major {
t.Errorf("%s major not matching - expected: %d - given: %d", device.device, device.major, givenMajor)
}
givenMinor := minor(internalDevice)
if givenMinor != device.minor {
t.Errorf("%s minor not matching - expected: %d - given: %d", device.device, device.minor, givenMinor)
}
givenMkdev := mkdev(int64(device.major), int64(device.minor))
if givenMkdev != uint32(internalDevice) {
t.Errorf("%s mkdev not matching - expected: %d - given: %d", device.device, uint32(internalDevice), givenMkdev)
}
}
}