@@ -14,6 +14,8 @@ extern crate utest_cortex_m_qemu;
14
14
#[ macro_use]
15
15
extern crate utest_macros;
16
16
17
+ use core:: mem;
18
+
17
19
macro_rules! panic {
18
20
( $( $tt: tt) * ) => {
19
21
upanic!( $( $tt) * ) ;
@@ -24,199 +26,249 @@ extern "C" {
24
26
fn __aeabi_memset4 ( dest : * mut u8 , n : usize , c : u32 ) ;
25
27
}
26
28
29
+ struct Aligned {
30
+ array : [ u8 ; 8 ] ,
31
+ _alignment : [ u32 ; 0 ] ,
32
+ }
33
+
34
+ impl Aligned {
35
+ fn new ( array : [ u8 ; 8 ] ) -> Self {
36
+ Aligned {
37
+ array : array,
38
+ _alignment : [ ] ,
39
+ }
40
+ }
41
+ }
42
+
27
43
#[ test]
28
44
fn zero ( ) {
29
- let mut xs = [ 0u8 ; 8 ] ;
45
+ let mut aligned = Aligned :: new ( [ 0u8 ; 8 ] ) ; ;
46
+ assert_eq ! ( mem:: align_of_val( & aligned) , 4 ) ;
47
+ let xs = & mut aligned. array ;
30
48
let c = 0xdeadbeef ;
31
49
32
50
unsafe {
33
51
__aeabi_memset4 ( xs. as_mut_ptr ( ) , 0 , c)
34
52
}
35
53
36
- assert_eq ! ( xs, [ 0 ; 8 ] ) ;
54
+ assert_eq ! ( * xs, [ 0 ; 8 ] ) ;
37
55
38
- let mut xs = [ 1u8 ; 8 ] ;
56
+ let mut aligned = Aligned :: new ( [ 1u8 ; 8 ] ) ; ;
57
+ assert_eq ! ( mem:: align_of_val( & aligned) , 4 ) ;
58
+ let xs = & mut aligned. array ;
39
59
let c = 0xdeadbeef ;
40
60
41
61
unsafe {
42
62
__aeabi_memset4 ( xs. as_mut_ptr ( ) , 0 , c)
43
63
}
44
64
45
- assert_eq ! ( xs, [ 1 ; 8 ] ) ;
65
+ assert_eq ! ( * xs, [ 1 ; 8 ] ) ;
46
66
}
47
67
48
68
#[ test]
49
69
fn one ( ) {
50
- let mut xs = [ 0u8 ; 8 ] ;
70
+ let mut aligned = Aligned :: new ( [ 0u8 ; 8 ] ) ; ;
71
+ assert_eq ! ( mem:: align_of_val( & aligned) , 4 ) ;
72
+ let xs = & mut aligned. array ;
51
73
let n = 1 ;
52
74
let c = 0xdeadbeef ;
53
75
54
76
unsafe {
55
77
__aeabi_memset4 ( xs. as_mut_ptr ( ) , n, c)
56
78
}
57
79
58
- assert_eq ! ( xs, [ 0xef , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ;
80
+ assert_eq ! ( * xs, [ 0xef , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ;
59
81
60
- let mut xs = [ 1u8 ; 8 ] ;
82
+ let mut aligned = Aligned :: new ( [ 1u8 ; 8 ] ) ; ;
83
+ assert_eq ! ( mem:: align_of_val( & aligned) , 4 ) ;
84
+ let xs = & mut aligned. array ;
61
85
let c = 0xdeadbeef ;
62
86
63
87
unsafe {
64
88
__aeabi_memset4 ( xs. as_mut_ptr ( ) , n, c)
65
89
}
66
90
67
- assert_eq ! ( xs, [ 0xef , 1 , 1 , 1 , 1 , 1 , 1 , 1 ] ) ;
91
+ assert_eq ! ( * xs, [ 0xef , 1 , 1 , 1 , 1 , 1 , 1 , 1 ] ) ;
68
92
}
69
93
70
94
#[ test]
71
95
fn two ( ) {
72
- let mut xs = [ 0u8 ; 8 ] ;
96
+ let mut aligned = Aligned :: new ( [ 0u8 ; 8 ] ) ; ;
97
+ assert_eq ! ( mem:: align_of_val( & aligned) , 4 ) ;
98
+ let xs = & mut aligned. array ;
73
99
let n = 2 ;
74
100
let c = 0xdeadbeef ;
75
101
76
102
unsafe {
77
103
__aeabi_memset4 ( xs. as_mut_ptr ( ) , n, c)
78
104
}
79
105
80
- assert_eq ! ( xs, [ 0xef , 0xef , 0 , 0 , 0 , 0 , 0 , 0 ] ) ;
106
+ assert_eq ! ( * xs, [ 0xef , 0xef , 0 , 0 , 0 , 0 , 0 , 0 ] ) ;
81
107
82
- let mut xs = [ 1u8 ; 8 ] ;
108
+ let mut aligned = Aligned :: new ( [ 1u8 ; 8 ] ) ; ;
109
+ assert_eq ! ( mem:: align_of_val( & aligned) , 4 ) ;
110
+ let xs = & mut aligned. array ;
83
111
let c = 0xdeadbeef ;
84
112
85
113
unsafe {
86
114
__aeabi_memset4 ( xs. as_mut_ptr ( ) , n, c)
87
115
}
88
116
89
- assert_eq ! ( xs, [ 0xef , 0xef , 1 , 1 , 1 , 1 , 1 , 1 ] ) ;
117
+ assert_eq ! ( * xs, [ 0xef , 0xef , 1 , 1 , 1 , 1 , 1 , 1 ] ) ;
90
118
}
91
119
92
120
#[ test]
93
121
fn three ( ) {
94
- let mut xs = [ 0u8 ; 8 ] ;
122
+ let mut aligned = Aligned :: new ( [ 0u8 ; 8 ] ) ; ;
123
+ assert_eq ! ( mem:: align_of_val( & aligned) , 4 ) ;
124
+ let xs = & mut aligned. array ;
95
125
let n = 3 ;
96
126
let c = 0xdeadbeef ;
97
127
98
128
unsafe {
99
129
__aeabi_memset4 ( xs. as_mut_ptr ( ) , n, c)
100
130
}
101
131
102
- assert_eq ! ( xs, [ 0xef , 0xef , 0xef , 0 , 0 , 0 , 0 , 0 ] ) ;
132
+ assert_eq ! ( * xs, [ 0xef , 0xef , 0xef , 0 , 0 , 0 , 0 , 0 ] ) ;
103
133
104
- let mut xs = [ 1u8 ; 8 ] ;
134
+ let mut aligned = Aligned :: new ( [ 1u8 ; 8 ] ) ; ;
135
+ assert_eq ! ( mem:: align_of_val( & aligned) , 4 ) ;
136
+ let xs = & mut aligned. array ;
105
137
let c = 0xdeadbeef ;
106
138
107
139
unsafe {
108
140
__aeabi_memset4 ( xs. as_mut_ptr ( ) , n, c)
109
141
}
110
142
111
- assert_eq ! ( xs, [ 0xef , 0xef , 0xef , 1 , 1 , 1 , 1 , 1 ] ) ;
143
+ assert_eq ! ( * xs, [ 0xef , 0xef , 0xef , 1 , 1 , 1 , 1 , 1 ] ) ;
112
144
}
113
145
114
146
#[ test]
115
147
fn four ( ) {
116
- let mut xs = [ 0u8 ; 8 ] ;
148
+ let mut aligned = Aligned :: new ( [ 0u8 ; 8 ] ) ; ;
149
+ assert_eq ! ( mem:: align_of_val( & aligned) , 4 ) ;
150
+ let xs = & mut aligned. array ;
117
151
let n = 4 ;
118
152
let c = 0xdeadbeef ;
119
153
120
154
unsafe {
121
155
__aeabi_memset4 ( xs. as_mut_ptr ( ) , n, c)
122
156
}
123
157
124
- assert_eq ! ( xs, [ 0xef , 0xef , 0xef , 0xef , 0 , 0 , 0 , 0 ] ) ;
158
+ assert_eq ! ( * xs, [ 0xef , 0xef , 0xef , 0xef , 0 , 0 , 0 , 0 ] ) ;
125
159
126
- let mut xs = [ 1u8 ; 8 ] ;
160
+ let mut aligned = Aligned :: new ( [ 1u8 ; 8 ] ) ; ;
161
+ assert_eq ! ( mem:: align_of_val( & aligned) , 4 ) ;
162
+ let xs = & mut aligned. array ;
127
163
let c = 0xdeadbeef ;
128
164
129
165
unsafe {
130
166
__aeabi_memset4 ( xs. as_mut_ptr ( ) , n, c)
131
167
}
132
168
133
- assert_eq ! ( xs, [ 0xef , 0xef , 0xef , 0xef , 1 , 1 , 1 , 1 ] ) ;
169
+ assert_eq ! ( * xs, [ 0xef , 0xef , 0xef , 0xef , 1 , 1 , 1 , 1 ] ) ;
134
170
}
135
171
136
172
#[ test]
137
173
fn five ( ) {
138
- let mut xs = [ 0u8 ; 8 ] ;
174
+ let mut aligned = Aligned :: new ( [ 0u8 ; 8 ] ) ; ;
175
+ assert_eq ! ( mem:: align_of_val( & aligned) , 4 ) ;
176
+ let xs = & mut aligned. array ;
139
177
let n = 5 ;
140
178
let c = 0xdeadbeef ;
141
179
142
180
unsafe {
143
181
__aeabi_memset4 ( xs. as_mut_ptr ( ) , n, c)
144
182
}
145
183
146
- assert_eq ! ( xs, [ 0xef , 0xef , 0xef , 0xef , 0xef , 0 , 0 , 0 ] ) ;
184
+ assert_eq ! ( * xs, [ 0xef , 0xef , 0xef , 0xef , 0xef , 0 , 0 , 0 ] ) ;
147
185
148
- let mut xs = [ 1u8 ; 8 ] ;
186
+ let mut aligned = Aligned :: new ( [ 1u8 ; 8 ] ) ; ;
187
+ assert_eq ! ( mem:: align_of_val( & aligned) , 4 ) ;
188
+ let xs = & mut aligned. array ;
149
189
let c = 0xdeadbeef ;
150
190
151
191
unsafe {
152
192
__aeabi_memset4 ( xs. as_mut_ptr ( ) , n, c)
153
193
}
154
194
155
- assert_eq ! ( xs, [ 0xef , 0xef , 0xef , 0xef , 0xef , 1 , 1 , 1 ] ) ;
195
+ assert_eq ! ( * xs, [ 0xef , 0xef , 0xef , 0xef , 0xef , 1 , 1 , 1 ] ) ;
156
196
}
157
197
158
198
#[ test]
159
199
fn six ( ) {
160
- let mut xs = [ 0u8 ; 8 ] ;
200
+ let mut aligned = Aligned :: new ( [ 0u8 ; 8 ] ) ; ;
201
+ assert_eq ! ( mem:: align_of_val( & aligned) , 4 ) ;
202
+ let xs = & mut aligned. array ;
161
203
let n = 6 ;
162
204
let c = 0xdeadbeef ;
163
205
164
206
unsafe {
165
207
__aeabi_memset4 ( xs. as_mut_ptr ( ) , n, c)
166
208
}
167
209
168
- assert_eq ! ( xs, [ 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 0 , 0 ] ) ;
210
+ assert_eq ! ( * xs, [ 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 0 , 0 ] ) ;
169
211
170
- let mut xs = [ 1u8 ; 8 ] ;
212
+ let mut aligned = Aligned :: new ( [ 1u8 ; 8 ] ) ; ;
213
+ assert_eq ! ( mem:: align_of_val( & aligned) , 4 ) ;
214
+ let xs = & mut aligned. array ;
171
215
let c = 0xdeadbeef ;
172
216
173
217
unsafe {
174
218
__aeabi_memset4 ( xs. as_mut_ptr ( ) , n, c)
175
219
}
176
220
177
- assert_eq ! ( xs, [ 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 1 , 1 ] ) ;
221
+ assert_eq ! ( * xs, [ 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 1 , 1 ] ) ;
178
222
}
179
223
180
224
#[ test]
181
225
fn seven ( ) {
182
- let mut xs = [ 0u8 ; 8 ] ;
226
+ let mut aligned = Aligned :: new ( [ 0u8 ; 8 ] ) ; ;
227
+ assert_eq ! ( mem:: align_of_val( & aligned) , 4 ) ;
228
+ let xs = & mut aligned. array ;
183
229
let n = 7 ;
184
230
let c = 0xdeadbeef ;
185
231
186
232
unsafe {
187
233
__aeabi_memset4 ( xs. as_mut_ptr ( ) , n, c)
188
234
}
189
235
190
- assert_eq ! ( xs, [ 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 0 ] ) ;
236
+ assert_eq ! ( * xs, [ 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 0 ] ) ;
191
237
192
- let mut xs = [ 1u8 ; 8 ] ;
238
+ let mut aligned = Aligned :: new ( [ 1u8 ; 8 ] ) ; ;
239
+ assert_eq ! ( mem:: align_of_val( & aligned) , 4 ) ;
240
+ let xs = & mut aligned. array ;
193
241
let c = 0xdeadbeef ;
194
242
195
243
unsafe {
196
244
__aeabi_memset4 ( xs. as_mut_ptr ( ) , n, c)
197
245
}
198
246
199
- assert_eq ! ( xs, [ 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 1 ] ) ;
247
+ assert_eq ! ( * xs, [ 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 1 ] ) ;
200
248
}
201
249
202
250
#[ test]
203
251
fn eight ( ) {
204
- let mut xs = [ 0u8 ; 8 ] ;
252
+ let mut aligned = Aligned :: new ( [ 0u8 ; 8 ] ) ; ;
253
+ assert_eq ! ( mem:: align_of_val( & aligned) , 4 ) ;
254
+ let xs = & mut aligned. array ;
205
255
let n = 8 ;
206
256
let c = 0xdeadbeef ;
207
257
208
258
unsafe {
209
259
__aeabi_memset4 ( xs. as_mut_ptr ( ) , n, c)
210
260
}
211
261
212
- assert_eq ! ( xs, [ 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 0xef ] ) ;
262
+ assert_eq ! ( * xs, [ 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 0xef ] ) ;
213
263
214
- let mut xs = [ 1u8 ; 8 ] ;
264
+ let mut aligned = Aligned :: new ( [ 1u8 ; 8 ] ) ; ;
265
+ assert_eq ! ( mem:: align_of_val( & aligned) , 4 ) ;
266
+ let xs = & mut aligned. array ;
215
267
let c = 0xdeadbeef ;
216
268
217
269
unsafe {
218
270
__aeabi_memset4 ( xs. as_mut_ptr ( ) , n, c)
219
271
}
220
272
221
- assert_eq ! ( xs, [ 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 0xef ] ) ;
273
+ assert_eq ! ( * xs, [ 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 0xef , 0xef ] ) ;
222
274
}
0 commit comments