@@ -24,7 +24,7 @@ fn main() {
2424const EPOLL_IN_OUT_ET : u32 = ( libc:: EPOLLIN | libc:: EPOLLOUT | libc:: EPOLLET ) as _ ;
2525
2626#[ 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 ) ] ) {
2828 let epoll_event = libc:: epoll_event { events : 0 , u64 : 0 } ;
2929 let mut array: [ libc:: epoll_event ; N ] = [ epoll_event; N ] ;
3030 let maxsize = N ;
@@ -33,22 +33,18 @@ fn check_epoll_wait<const N: usize>(epfd: i32, expected_notifications: &[(u32, u
3333 if res < 0 {
3434 panic ! ( "epoll_wait failed: {}" , std:: io:: Error :: last_os_error( ) ) ;
3535 }
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+ ) ;
3741 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" ) ;
4947 }
50- // There shouldn't be any more expected.
51- return expected_notifications. next ( ) . is_none ( ) ;
5248}
5349
5450fn test_epoll_socketpair ( ) {
@@ -77,10 +73,10 @@ fn test_epoll_socketpair() {
7773 // Check result from epoll_wait.
7874 let expected_event = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) ;
7975 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) ] ) ;
8177
8278 // 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, & [ ] ) ;
8480
8581 // Write some more to fd[0].
8682 let data = "abcde" . as_bytes ( ) . as_ptr ( ) ;
@@ -89,7 +85,7 @@ fn test_epoll_socketpair() {
8985
9086 // This did not change the readiness of fd[1]. And yet, we're seeing the event reported
9187 // 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) ] ) ;
9389
9490 // Close the peer socketpair.
9591 let res = unsafe { libc:: close ( fds[ 0 ] ) } ;
@@ -100,7 +96,7 @@ fn test_epoll_socketpair() {
10096 let expected_event =
10197 u32:: try_from ( libc:: EPOLLRDHUP | libc:: EPOLLIN | libc:: EPOLLOUT | libc:: EPOLLHUP ) . unwrap ( ) ;
10298 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) ] ) ;
104100}
105101
106102fn test_epoll_ctl_mod ( ) {
@@ -127,7 +123,7 @@ fn test_epoll_ctl_mod() {
127123 // Check result from epoll_wait.
128124 let expected_event = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) ;
129125 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) ] ) ;
131127
132128 // Test EPOLLRDHUP.
133129 let mut ev = libc:: epoll_event {
@@ -145,7 +141,7 @@ fn test_epoll_ctl_mod() {
145141 let expected_event =
146142 u32:: try_from ( libc:: EPOLLRDHUP | libc:: EPOLLIN | libc:: EPOLLOUT | libc:: EPOLLHUP ) . unwrap ( ) ;
147143 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) ] ) ;
149145}
150146
151147fn test_epoll_ctl_del ( ) {
@@ -169,7 +165,7 @@ fn test_epoll_ctl_del() {
169165 assert_ne ! ( res, -1 ) ;
170166
171167 // Test EPOLL_CTL_DEL.
172- assert ! ( check_epoll_wait:: <0 >( epfd, & [ ] ) ) ;
168+ check_epoll_wait :: < 0 > ( epfd, & [ ] ) ;
173169}
174170
175171// This test is for one fd registered under two different epoll instance.
@@ -200,8 +196,8 @@ fn test_two_epoll_instance() {
200196 // Notification should be received from both instance of epoll.
201197 let expected_event = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) ;
202198 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) ] ) ;
205201}
206202
207203// 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() {
235231 //Two notification should be received.
236232 let expected_event = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) ;
237233 let expected_value = 5 as u64 ;
238- assert ! ( check_epoll_wait:: <8 >(
234+ check_epoll_wait :: < 8 > (
239235 epfd,
240- & [ ( expected_event, expected_value) , ( expected_event, expected_value) ]
241- ) ) ;
236+ & [ ( expected_event, expected_value) , ( expected_event, expected_value) ] ,
237+ ) ;
242238}
243239
244240fn test_epoll_eventfd ( ) {
@@ -263,7 +259,7 @@ fn test_epoll_eventfd() {
263259 // Check result from epoll_wait.
264260 let expected_event = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) ;
265261 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) ] ) ;
267263}
268264
269265fn test_pointer ( ) {
@@ -313,10 +309,10 @@ fn test_epoll_socketpair_both_sides() {
313309 let expected_value0 = fds[ 0 ] as u64 ;
314310 let expected_event1 = u32:: try_from ( libc:: EPOLLOUT ) . unwrap ( ) ;
315311 let expected_value1 = fds[ 1 ] as u64 ;
316- assert ! ( check_epoll_wait:: <8 >(
312+ check_epoll_wait :: < 8 > (
317313 epfd,
318- & [ ( expected_event0, expected_value0) , ( expected_event1, expected_value1) ]
319- ) ) ;
314+ & [ ( expected_event0, expected_value0) , ( expected_event1, expected_value1) ] ,
315+ ) ;
320316
321317 // Read from fds[0].
322318 let mut buf: [ u8 ; 5 ] = [ 0 ; 5 ] ;
@@ -327,7 +323,7 @@ fn test_epoll_socketpair_both_sides() {
327323 // Notification should be provided for fds[1].
328324 let expected_event = u32:: try_from ( libc:: EPOLLOUT ) . unwrap ( ) ;
329325 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) ] ) ;
331327}
332328
333329// When file description is fully closed, epoll_wait should not provide any notification for
@@ -356,7 +352,7 @@ fn test_closed_fd() {
356352 assert_eq ! ( res, 0 ) ;
357353
358354 // No notification should be provided because the file description is closed.
359- assert ! ( check_epoll_wait:: <8 >( epfd, & [ ] ) ) ;
355+ check_epoll_wait :: < 8 > ( epfd, & [ ] ) ;
360356}
361357
362358// 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() {
390386 // Notification should still be provided because the file description is not closed.
391387 let expected_event = u32:: try_from ( libc:: EPOLLOUT ) . unwrap ( ) ;
392388 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) ] ) ;
394390
395391 // Write to the eventfd instance to produce notification.
396392 let sized_8_data: [ u8 ; 8 ] = 1_u64 . to_ne_bytes ( ) ;
@@ -402,7 +398,7 @@ fn test_not_fully_closed_fd() {
402398 assert_eq ! ( res, 0 ) ;
403399
404400 // No notification should be provided.
405- assert ! ( check_epoll_wait:: <1 >( epfd, & [ ] ) ) ;
401+ check_epoll_wait :: < 1 > ( epfd, & [ ] ) ;
406402}
407403
408404// Each time a notification is provided, it should reflect the file description's readiness
@@ -437,7 +433,7 @@ fn test_event_overwrite() {
437433 // Check result from epoll_wait.
438434 let expected_event = u32:: try_from ( libc:: EPOLLOUT ) . unwrap ( ) ;
439435 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) ] ) ;
441437}
442438
443439// An epoll notification will be provided for every succesful read in a socketpair.
@@ -476,10 +472,10 @@ fn test_socketpair_read() {
476472 let expected_value0 = fds[ 0 ] as u64 ;
477473 let expected_event1 = u32:: try_from ( libc:: EPOLLOUT ) . unwrap ( ) ;
478474 let expected_value1 = fds[ 1 ] as u64 ;
479- assert ! ( check_epoll_wait:: <8 >(
475+ check_epoll_wait :: < 8 > (
480476 epfd,
481- & [ ( expected_event0, expected_value0) , ( expected_event1, expected_value1) ]
482- ) ) ;
477+ & [ ( expected_event0, expected_value0) , ( expected_event1, expected_value1) ] ,
478+ ) ;
483479
484480 // Read 3 bytes from fds[0].
485481 let mut buf: [ u8 ; 3 ] = [ 0 ; 3 ] ;
@@ -491,7 +487,7 @@ fn test_socketpair_read() {
491487 // But in real system, no notification will be provided here.
492488 let expected_event = u32:: try_from ( libc:: EPOLLOUT ) . unwrap ( ) ;
493489 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) ] ) ;
495491
496492 // Read until the buffer is empty.
497493 let mut buf: [ u8 ; 2 ] = [ 0 ; 2 ] ;
@@ -503,5 +499,5 @@ fn test_socketpair_read() {
503499 // In real system, notification will be provided too.
504500 let expected_event = u32:: try_from ( libc:: EPOLLOUT ) . unwrap ( ) ;
505501 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) ] ) ;
507503}
0 commit comments