Skip to content

Commit 9184eb5

Browse files
committed
more epoll test cleanup
1 parent edd1efb commit 9184eb5

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

src/tools/miri/tests/pass-dep/libc/libc-epoll.rs

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ fn main() {
2424
const EPOLL_IN_OUT_ET: u32 = (libc::EPOLLIN | libc::EPOLLOUT | libc::EPOLLET) as _;
2525

2626
#[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 {
3128
let epoll_event = libc::epoll_event { events: 0, u64: 0 };
3229
let mut array: [libc::epoll_event; N] = [epoll_event; N];
3330
let maxsize = N;
@@ -39,8 +36,9 @@ fn check_epoll_wait<const N: usize>(
3936
assert_eq!(res, expected_notifications.len().try_into().unwrap());
4037
let slice = unsafe { std::slice::from_raw_parts(array_ptr, res.try_into().unwrap()) };
4138
let mut return_events = slice.iter();
39+
let mut expected_notifications = expected_notifications.iter();
4240
while let Some(return_event) = return_events.next() {
43-
if let Some(notification) = expected_notifications.pop() {
41+
if let Some(notification) = expected_notifications.next() {
4442
let event = return_event.events;
4543
let data = return_event.u64;
4644
assert_eq!(event, notification.0);
@@ -49,10 +47,8 @@ fn check_epoll_wait<const N: usize>(
4947
return false;
5048
}
5149
}
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();
5652
}
5753

5854
fn test_epoll_socketpair() {
@@ -81,10 +77,10 @@ fn test_epoll_socketpair() {
8177
// Check result from epoll_wait.
8278
let expected_event = u32::try_from(libc::EPOLLIN | libc::EPOLLOUT).unwrap();
8379
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)]));
8581

8682
// 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, &[]));
8884

8985
// Write some more to fd[0].
9086
let data = "abcde".as_bytes().as_ptr();
@@ -93,7 +89,7 @@ fn test_epoll_socketpair() {
9389

9490
// This did not change the readiness of fd[1]. And yet, we're seeing the event reported
9591
// 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)]));
9793

9894
// Close the peer socketpair.
9995
let res = unsafe { libc::close(fds[0]) };
@@ -102,7 +98,7 @@ fn test_epoll_socketpair() {
10298
// Check result from epoll_wait.
10399
let expected_event = u32::try_from(libc::EPOLLRDHUP | libc::EPOLLIN | libc::EPOLLOUT).unwrap();
104100
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)]));
106102
}
107103

108104
fn test_epoll_ctl_mod() {
@@ -129,7 +125,7 @@ fn test_epoll_ctl_mod() {
129125
// Check result from epoll_wait.
130126
let expected_event = u32::try_from(libc::EPOLLIN | libc::EPOLLOUT).unwrap();
131127
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)]));
133129

134130
// Test EPOLLRDHUP.
135131
let mut ev = libc::epoll_event {
@@ -146,7 +142,7 @@ fn test_epoll_ctl_mod() {
146142
// Check result from epoll_wait.
147143
let expected_event = u32::try_from(libc::EPOLLRDHUP | libc::EPOLLIN | libc::EPOLLOUT).unwrap();
148144
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)]));
150146
}
151147

152148
fn test_epoll_ctl_del() {
@@ -170,7 +166,7 @@ fn test_epoll_ctl_del() {
170166
assert_ne!(res, -1);
171167

172168
// Test EPOLL_CTL_DEL.
173-
assert!(check_epoll_wait::<0>(epfd, vec![]));
169+
assert!(check_epoll_wait::<0>(epfd, &[]));
174170
}
175171

176172
// This test is for one fd registered under two different epoll instance.
@@ -201,8 +197,8 @@ fn test_two_epoll_instance() {
201197
// Notification should be received from both instance of epoll.
202198
let expected_event = u32::try_from(libc::EPOLLIN | libc::EPOLLOUT).unwrap();
203199
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)]));
206202
}
207203

208204
// 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() {
238234
let expected_value = 5 as u64;
239235
assert!(check_epoll_wait::<8>(
240236
epfd,
241-
vec![(expected_event, expected_value), (expected_event, expected_value)]
237+
&[(expected_event, expected_value), (expected_event, expected_value)]
242238
));
243239
}
244240

@@ -264,7 +260,7 @@ fn test_epoll_eventfd() {
264260
// Check result from epoll_wait.
265261
let expected_event = u32::try_from(libc::EPOLLIN | libc::EPOLLOUT).unwrap();
266262
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)]));
268264
}
269265

270266
fn test_pointer() {
@@ -316,7 +312,7 @@ fn test_epoll_socketpair_both_sides() {
316312
let expected_value1 = fds[1] as u64;
317313
assert!(check_epoll_wait::<8>(
318314
epfd,
319-
vec![(expected_event1, expected_value1), (expected_event0, expected_value0)]
315+
&[(expected_event0, expected_value0), (expected_event1, expected_value1)]
320316
));
321317

322318
// Read from fds[0].
@@ -328,7 +324,7 @@ fn test_epoll_socketpair_both_sides() {
328324
// Notification should be provided for fds[1].
329325
let expected_event = u32::try_from(libc::EPOLLOUT).unwrap();
330326
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)]));
332328
}
333329

334330
// When file description is fully closed, epoll_wait should not provide any notification for
@@ -357,7 +353,7 @@ fn test_closed_fd() {
357353
assert_eq!(res, 0);
358354

359355
// 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, &[]));
361357
}
362358

363359
// 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() {
391387
// Notification should still be provided because the file description is not closed.
392388
let expected_event = u32::try_from(libc::EPOLLOUT).unwrap();
393389
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)]));
395391

396392
// Write to the eventfd instance to produce notification.
397393
let sized_8_data: [u8; 8] = 1_u64.to_ne_bytes();
@@ -403,7 +399,7 @@ fn test_not_fully_closed_fd() {
403399
assert_eq!(res, 0);
404400

405401
// No notification should be provided.
406-
assert!(check_epoll_wait::<1>(epfd, vec![]));
402+
assert!(check_epoll_wait::<1>(epfd, &[]));
407403
}
408404

409405
// Each time a notification is provided, it should reflect the file description's readiness
@@ -438,7 +434,7 @@ fn test_event_overwrite() {
438434
// Check result from epoll_wait.
439435
let expected_event = u32::try_from(libc::EPOLLOUT).unwrap();
440436
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)]));
442438
}
443439

444440
// An epoll notification will be provided for every succesful read in a socketpair.
@@ -479,7 +475,7 @@ fn test_socketpair_read() {
479475
let expected_value1 = fds[1] as u64;
480476
assert!(check_epoll_wait::<8>(
481477
epfd,
482-
vec![(expected_event1, expected_value1), (expected_event0, expected_value0)]
478+
&[(expected_event0, expected_value0), (expected_event1, expected_value1)]
483479
));
484480

485481
// Read 3 bytes from fds[0].
@@ -492,7 +488,7 @@ fn test_socketpair_read() {
492488
// But in real system, no notification will be provided here.
493489
let expected_event = u32::try_from(libc::EPOLLOUT).unwrap();
494490
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)]));
496492

497493
// Read until the buffer is empty.
498494
let mut buf: [u8; 2] = [0; 2];
@@ -504,5 +500,5 @@ fn test_socketpair_read() {
504500
// In real system, notification will be provided too.
505501
let expected_event = u32::try_from(libc::EPOLLOUT).unwrap();
506502
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)]));
508504
}

0 commit comments

Comments
 (0)