diff options
| author | Ralf Jung <post@ralfj.de> | 2024-08-17 10:51:05 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-08-17 11:32:18 +0200 |
| commit | 5402be8f99ac9960ef0cf1cf83aef0857e180506 (patch) | |
| tree | e4d21282637debdc32774b19f78e70b5af0ce616 | |
| parent | 99d742e9b0b7191543567faa67a04c65a4d1bcaf (diff) | |
| download | rust-5402be8f99ac9960ef0cf1cf83aef0857e180506.tar.gz rust-5402be8f99ac9960ef0cf1cf83aef0857e180506.zip | |
socketpair: test behavior when one end got closed
| -rw-r--r-- | src/tools/miri/tests/pass-dep/libc/libc-socketpair.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/tools/miri/tests/pass-dep/libc/libc-socketpair.rs b/src/tools/miri/tests/pass-dep/libc/libc-socketpair.rs index 254be89d482..873c39a208e 100644 --- a/src/tools/miri/tests/pass-dep/libc/libc-socketpair.rs +++ b/src/tools/miri/tests/pass-dep/libc/libc-socketpair.rs @@ -58,6 +58,26 @@ fn test_socketpair() { }; assert_eq!(res, 3); assert_eq!(&buf4[0..3], "123".as_bytes()); + + // Test when happens when we close one end, with some data in the buffer. + res = unsafe { libc::write(fds[0], data as *const libc::c_void, 3).try_into().unwrap() }; + assert_eq!(res, 3); + unsafe { libc::close(fds[0]) }; + // Reading the other end should return that data, then EOF. + let mut buf: [u8; 5] = [0; 5]; + res = unsafe { + libc::read(fds[1], buf.as_mut_ptr().cast(), buf.len() as libc::size_t).try_into().unwrap() + }; + assert_eq!(res, 3); + assert_eq!(&buf[0..3], "123".as_bytes()); + res = unsafe { + libc::read(fds[1], buf.as_mut_ptr().cast(), buf.len() as libc::size_t).try_into().unwrap() + }; + assert_eq!(res, 0); // 0-sized read: EOF. + // Writing the other end should emit EPIPE. + res = unsafe { libc::write(fds[1], data as *const libc::c_void, 1).try_into().unwrap() }; + assert_eq!(res, -1); + assert_eq!(std::io::Error::last_os_error().raw_os_error(), Some(libc::EPIPE)); } fn test_socketpair_threaded() { |
