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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
#![allow(dead_code)]
// Simple tests to ensure macro generated fns compile
ioctl!(bad do_bad with 0x1234);
ioctl!(none do_none with 0, 0);
ioctl!(read read_test with 0, 0; u32);
ioctl!(write write_test with 0, 0; u64);
ioctl!(readwrite readwrite_test with 0, 0; u64);
ioctl!(read buf readbuf_test with 0, 0; u32);
ioctl!(write buf writebuf_test with 0, 0; u32);
ioctl!(readwrite buf readwritebuf_test with 0, 0; u32);
// See C code for source of values for op calculations (does NOT work for mips/powerpc):
// https://gist.github.com/posborne/83ea6880770a1aef332e
//
// TODO: Need a way to compute these constants at test time. Using precomputed
// values is fragile and needs to be maintained.
#[cfg(any(target_os = "linux", target_os = "android"))]
mod linux {
#[test]
fn test_op_none() {
if cfg!(any(target_arch = "mips", target_arch="powerpc", target_arch="powerpc64")){
assert_eq!(io!(b'q', 10), 0x2000710A);
assert_eq!(io!(b'a', 255), 0x200061FF);
} else {
assert_eq!(io!(b'q', 10), 0x0000710A);
assert_eq!(io!(b'a', 255), 0x000061FF);
}
}
#[test]
fn test_op_write() {
if cfg!(any(target_arch = "mips", target_arch="powerpc", target_arch="powerpc64")){
assert_eq!(iow!(b'z', 10, 1), 0x80017A0A);
assert_eq!(iow!(b'z', 10, 512), 0x82007A0A);
} else {
assert_eq!(iow!(b'z', 10, 1), 0x40017A0A);
assert_eq!(iow!(b'z', 10, 512), 0x42007A0A);
}
}
#[cfg(target_pointer_width = "64")]
#[test]
fn test_op_write_64() {
if cfg!(any(target_arch="powerpc64")){
assert_eq!(iow!(b'z', 10, (1 as u64) << 32), 0x80007A0A);
} else {
assert_eq!(iow!(b'z', 10, (1 as u64) << 32), 0x40007A0A);
}
}
#[test]
fn test_op_read() {
if cfg!(any(target_arch = "mips", target_arch="powerpc", target_arch="powerpc64")){
assert_eq!(ior!(b'z', 10, 1), 0x40017A0A);
assert_eq!(ior!(b'z', 10, 512), 0x42007A0A);
} else {
assert_eq!(ior!(b'z', 10, 1), 0x80017A0A);
assert_eq!(ior!(b'z', 10, 512), 0x82007A0A);
}
}
#[cfg(target_pointer_width = "64")]
#[test]
fn test_op_read_64() {
if cfg!(any(target_arch="powerpc64")){
assert_eq!(ior!(b'z', 10, (1 as u64) << 32), 0x40007A0A);
} else {
assert_eq!(ior!(b'z', 10, (1 as u64) << 32), 0x80007A0A);
}
}
#[test]
fn test_op_read_write() {
assert_eq!(iorw!(b'z', 10, 1), 0xC0017A0A);
assert_eq!(iorw!(b'z', 10, 512), 0xC2007A0A);
}
#[cfg(target_pointer_width = "64")]
#[test]
fn test_op_read_write_64() {
assert_eq!(iorw!(b'z', 10, (1 as u64) << 32), 0xC0007A0A);
}
}
#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "netbsd",
target_os = "openbsd",
target_os = "freebsd",
target_os = "dragonfly"))]
mod bsd {
#[test]
fn test_op_none() {
assert_eq!(io!(b'q', 10), 0x2000710A);
assert_eq!(io!(b'a', 255), 0x200061FF);
}
#[test]
fn test_op_write() {
assert_eq!(iow!(b'z', 10, 1), 0x80017A0A);
assert_eq!(iow!(b'z', 10, 512), 0x82007A0A);
}
#[cfg(target_pointer_width = "64")]
#[test]
fn test_op_write_64() {
assert_eq!(iow!(b'z', 10, (1 as u64) << 32), 0x80007A0A);
}
#[test]
fn test_op_read() {
assert_eq!(ior!(b'z', 10, 1), 0x40017A0A);
assert_eq!(ior!(b'z', 10, 512), 0x42007A0A);
}
#[cfg(target_pointer_width = "64")]
#[test]
fn test_op_read_64() {
assert_eq!(ior!(b'z', 10, (1 as u64) << 32), 0x40007A0A);
}
#[test]
fn test_op_read_write() {
assert_eq!(iorw!(b'z', 10, 1), 0xC0017A0A);
assert_eq!(iorw!(b'z', 10, 512), 0xC2007A0A);
}
#[cfg(target_pointer_width = "64")]
#[test]
fn test_op_read_write_64() {
assert_eq!(iorw!(b'z', 10, (1 as u64) << 32), 0xC0007A0A);
}
}
|