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