@@ -24,10 +24,7 @@ fn main() {
24
24
const EPOLL_IN_OUT_ET : u32 = ( libc:: EPOLLIN | libc:: EPOLLOUT | libc:: EPOLLET ) as _ ;
25
25
26
26
#[ track_caller]
27
- fn check_epoll_wait < const N : usize > (
28
- epfd : i32 ,
29
- mut expected_notifications : Vec < ( u32 , u64 ) > ,
30
- ) -> bool {
27
+ fn check_epoll_wait < const N : usize > ( epfd : i32 , expected_notifications : & [ ( u32 , u64 ) ] ) -> bool {
31
28
let epoll_event = libc:: epoll_event { events : 0 , u64 : 0 } ;
32
29
let mut array: [ libc:: epoll_event ; N ] = [ epoll_event; N ] ;
33
30
let maxsize = N ;
@@ -39,8 +36,9 @@ fn check_epoll_wait<const N: usize>(
39
36
assert_eq ! ( res, expected_notifications. len( ) . try_into( ) . unwrap( ) ) ;
40
37
let slice = unsafe { std:: slice:: from_raw_parts ( array_ptr, res. try_into ( ) . unwrap ( ) ) } ;
41
38
let mut return_events = slice. iter ( ) ;
39
+ let mut expected_notifications = expected_notifications. iter ( ) ;
42
40
while let Some ( return_event) = return_events. next ( ) {
43
- if let Some ( notification) = expected_notifications. pop ( ) {
41
+ if let Some ( notification) = expected_notifications. next ( ) {
44
42
let event = return_event. events ;
45
43
let data = return_event. u64 ;
46
44
assert_eq ! ( event, notification. 0 ) ;
@@ -49,10 +47,8 @@ fn check_epoll_wait<const N: usize>(
49
47
return false ;
50
48
}
51
49
}
52
- if !expected_notifications. is_empty ( ) {
53
- return false ;
54
- }
55
- return true ;
50
+ // There shouldn't be any more expected.
51
+ return expected_notifications. next ( ) . is_none ( ) ;
56
52
}
57
53
58
54
fn test_epoll_socketpair ( ) {
@@ -81,10 +77,10 @@ fn test_epoll_socketpair() {
81
77
// Check result from epoll_wait.
82
78
let expected_event = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) ;
83
79
let expected_value = u64:: try_from ( fds[ 1 ] ) . unwrap ( ) ;
84
- assert ! ( check_epoll_wait:: <8 >( epfd, vec! [ ( expected_event, expected_value) ] ) ) ;
80
+ assert ! ( check_epoll_wait:: <8 >( epfd, & [ ( expected_event, expected_value) ] ) ) ;
85
81
86
82
// Check that this is indeed using "ET" (edge-trigger) semantics: a second epoll should return nothing.
87
- assert ! ( check_epoll_wait:: <8 >( epfd, vec! [ ] ) ) ;
83
+ assert ! ( check_epoll_wait:: <8 >( epfd, & [ ] ) ) ;
88
84
89
85
// Write some more to fd[0].
90
86
let data = "abcde" . as_bytes ( ) . as_ptr ( ) ;
@@ -93,7 +89,7 @@ fn test_epoll_socketpair() {
93
89
94
90
// This did not change the readiness of fd[1]. And yet, we're seeing the event reported
95
91
// again by the kernel, so Miri does the same.
96
- assert ! ( check_epoll_wait:: <8 >( epfd, vec! [ ( expected_event, expected_value) ] ) ) ;
92
+ assert ! ( check_epoll_wait:: <8 >( epfd, & [ ( expected_event, expected_value) ] ) ) ;
97
93
98
94
// Close the peer socketpair.
99
95
let res = unsafe { libc:: close ( fds[ 0 ] ) } ;
@@ -102,7 +98,7 @@ fn test_epoll_socketpair() {
102
98
// Check result from epoll_wait.
103
99
let expected_event = u32:: try_from ( libc:: EPOLLRDHUP | libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) ;
104
100
let expected_value = u64:: try_from ( fds[ 1 ] ) . unwrap ( ) ;
105
- assert ! ( check_epoll_wait:: <8 >( epfd, vec! [ ( expected_event, expected_value) ] ) ) ;
101
+ assert ! ( check_epoll_wait:: <8 >( epfd, & [ ( expected_event, expected_value) ] ) ) ;
106
102
}
107
103
108
104
fn test_epoll_ctl_mod ( ) {
@@ -129,7 +125,7 @@ fn test_epoll_ctl_mod() {
129
125
// Check result from epoll_wait.
130
126
let expected_event = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) ;
131
127
let expected_value = u64:: try_from ( fds[ 1 ] ) . unwrap ( ) ;
132
- assert ! ( check_epoll_wait:: <8 >( epfd, vec! [ ( expected_event, expected_value) ] ) ) ;
128
+ assert ! ( check_epoll_wait:: <8 >( epfd, & [ ( expected_event, expected_value) ] ) ) ;
133
129
134
130
// Test EPOLLRDHUP.
135
131
let mut ev = libc:: epoll_event {
@@ -146,7 +142,7 @@ fn test_epoll_ctl_mod() {
146
142
// Check result from epoll_wait.
147
143
let expected_event = u32:: try_from ( libc:: EPOLLRDHUP | libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) ;
148
144
let expected_value = u64:: try_from ( fds[ 1 ] ) . unwrap ( ) ;
149
- assert ! ( check_epoll_wait:: <8 >( epfd, vec! [ ( expected_event, expected_value) ] ) ) ;
145
+ assert ! ( check_epoll_wait:: <8 >( epfd, & [ ( expected_event, expected_value) ] ) ) ;
150
146
}
151
147
152
148
fn test_epoll_ctl_del ( ) {
@@ -170,7 +166,7 @@ fn test_epoll_ctl_del() {
170
166
assert_ne ! ( res, -1 ) ;
171
167
172
168
// Test EPOLL_CTL_DEL.
173
- assert ! ( check_epoll_wait:: <0 >( epfd, vec! [ ] ) ) ;
169
+ assert ! ( check_epoll_wait:: <0 >( epfd, & [ ] ) ) ;
174
170
}
175
171
176
172
// This test is for one fd registered under two different epoll instance.
@@ -201,8 +197,8 @@ fn test_two_epoll_instance() {
201
197
// Notification should be received from both instance of epoll.
202
198
let expected_event = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) ;
203
199
let expected_value = u64:: try_from ( fds[ 1 ] ) . unwrap ( ) ;
204
- assert ! ( check_epoll_wait:: <8 >( epfd1, vec! [ ( expected_event, expected_value) ] ) ) ;
205
- assert ! ( check_epoll_wait:: <8 >( epfd2, vec! [ ( expected_event, expected_value) ] ) ) ;
200
+ assert ! ( check_epoll_wait:: <8 >( epfd1, & [ ( expected_event, expected_value) ] ) ) ;
201
+ assert ! ( check_epoll_wait:: <8 >( epfd2, & [ ( expected_event, expected_value) ] ) ) ;
206
202
}
207
203
208
204
// This test is for two same file description registered under the same epoll instance through dup.
@@ -238,7 +234,7 @@ fn test_two_same_fd_in_same_epoll_instance() {
238
234
let expected_value = 5 as u64 ;
239
235
assert ! ( check_epoll_wait:: <8 >(
240
236
epfd,
241
- vec! [ ( expected_event, expected_value) , ( expected_event, expected_value) ]
237
+ & [ ( expected_event, expected_value) , ( expected_event, expected_value) ]
242
238
) ) ;
243
239
}
244
240
@@ -264,7 +260,7 @@ fn test_epoll_eventfd() {
264
260
// Check result from epoll_wait.
265
261
let expected_event = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) ;
266
262
let expected_value = u64:: try_from ( fd) . unwrap ( ) ;
267
- assert ! ( check_epoll_wait:: <8 >( epfd, vec! [ ( expected_event, expected_value) ] ) ) ;
263
+ assert ! ( check_epoll_wait:: <8 >( epfd, & [ ( expected_event, expected_value) ] ) ) ;
268
264
}
269
265
270
266
fn test_pointer ( ) {
@@ -316,7 +312,7 @@ fn test_epoll_socketpair_both_sides() {
316
312
let expected_value1 = fds[ 1 ] as u64 ;
317
313
assert ! ( check_epoll_wait:: <8 >(
318
314
epfd,
319
- vec! [ ( expected_event1 , expected_value1 ) , ( expected_event0 , expected_value0 ) ]
315
+ & [ ( expected_event0 , expected_value0 ) , ( expected_event1 , expected_value1 ) ]
320
316
) ) ;
321
317
322
318
// Read from fds[0].
@@ -328,7 +324,7 @@ fn test_epoll_socketpair_both_sides() {
328
324
// Notification should be provided for fds[1].
329
325
let expected_event = u32:: try_from ( libc:: EPOLLOUT ) . unwrap ( ) ;
330
326
let expected_value = fds[ 1 ] as u64 ;
331
- assert ! ( check_epoll_wait:: <8 >( epfd, vec! [ ( expected_event, expected_value) ] ) ) ;
327
+ assert ! ( check_epoll_wait:: <8 >( epfd, & [ ( expected_event, expected_value) ] ) ) ;
332
328
}
333
329
334
330
// When file description is fully closed, epoll_wait should not provide any notification for
@@ -357,7 +353,7 @@ fn test_closed_fd() {
357
353
assert_eq ! ( res, 0 ) ;
358
354
359
355
// No notification should be provided because the file description is closed.
360
- assert ! ( check_epoll_wait:: <8 >( epfd, vec! [ ] ) ) ;
356
+ assert ! ( check_epoll_wait:: <8 >( epfd, & [ ] ) ) ;
361
357
}
362
358
363
359
// When a certain file descriptor registered with epoll is closed, but the underlying file description
@@ -391,7 +387,7 @@ fn test_not_fully_closed_fd() {
391
387
// Notification should still be provided because the file description is not closed.
392
388
let expected_event = u32:: try_from ( libc:: EPOLLOUT ) . unwrap ( ) ;
393
389
let expected_value = fd as u64 ;
394
- assert ! ( check_epoll_wait:: <1 >( epfd, vec! [ ( expected_event, expected_value) ] ) ) ;
390
+ assert ! ( check_epoll_wait:: <1 >( epfd, & [ ( expected_event, expected_value) ] ) ) ;
395
391
396
392
// Write to the eventfd instance to produce notification.
397
393
let sized_8_data: [ u8 ; 8 ] = 1_u64 . to_ne_bytes ( ) ;
@@ -403,7 +399,7 @@ fn test_not_fully_closed_fd() {
403
399
assert_eq ! ( res, 0 ) ;
404
400
405
401
// No notification should be provided.
406
- assert ! ( check_epoll_wait:: <1 >( epfd, vec! [ ] ) ) ;
402
+ assert ! ( check_epoll_wait:: <1 >( epfd, & [ ] ) ) ;
407
403
}
408
404
409
405
// Each time a notification is provided, it should reflect the file description's readiness
@@ -438,7 +434,7 @@ fn test_event_overwrite() {
438
434
// Check result from epoll_wait.
439
435
let expected_event = u32:: try_from ( libc:: EPOLLOUT ) . unwrap ( ) ;
440
436
let expected_value = u64:: try_from ( fd) . unwrap ( ) ;
441
- assert ! ( check_epoll_wait:: <8 >( epfd, vec! [ ( expected_event, expected_value) ] ) ) ;
437
+ assert ! ( check_epoll_wait:: <8 >( epfd, & [ ( expected_event, expected_value) ] ) ) ;
442
438
}
443
439
444
440
// An epoll notification will be provided for every succesful read in a socketpair.
@@ -479,7 +475,7 @@ fn test_socketpair_read() {
479
475
let expected_value1 = fds[ 1 ] as u64 ;
480
476
assert ! ( check_epoll_wait:: <8 >(
481
477
epfd,
482
- vec! [ ( expected_event1 , expected_value1 ) , ( expected_event0 , expected_value0 ) ]
478
+ & [ ( expected_event0 , expected_value0 ) , ( expected_event1 , expected_value1 ) ]
483
479
) ) ;
484
480
485
481
// Read 3 bytes from fds[0].
@@ -492,7 +488,7 @@ fn test_socketpair_read() {
492
488
// But in real system, no notification will be provided here.
493
489
let expected_event = u32:: try_from ( libc:: EPOLLOUT ) . unwrap ( ) ;
494
490
let expected_value = fds[ 1 ] as u64 ;
495
- assert ! ( check_epoll_wait:: <8 >( epfd, vec! [ ( expected_event, expected_value) ] ) ) ;
491
+ assert ! ( check_epoll_wait:: <8 >( epfd, & [ ( expected_event, expected_value) ] ) ) ;
496
492
497
493
// Read until the buffer is empty.
498
494
let mut buf: [ u8 ; 2 ] = [ 0 ; 2 ] ;
@@ -504,5 +500,5 @@ fn test_socketpair_read() {
504
500
// In real system, notification will be provided too.
505
501
let expected_event = u32:: try_from ( libc:: EPOLLOUT ) . unwrap ( ) ;
506
502
let expected_value = fds[ 1 ] as u64 ;
507
- assert ! ( check_epoll_wait:: <8 >( epfd, vec! [ ( expected_event, expected_value) ] ) ) ;
503
+ assert ! ( check_epoll_wait:: <8 >( epfd, & [ ( expected_event, expected_value) ] ) ) ;
508
504
}
0 commit comments