File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
src/tools/miri/tests/pass-dep/libc Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,26 @@ fn test_socketpair() {
58
58
} ;
59
59
assert_eq ! ( res, 3 ) ;
60
60
assert_eq ! ( & buf4[ 0 ..3 ] , "123" . as_bytes( ) ) ;
61
+
62
+ // Test when happens when we close one end, with some data in the buffer.
63
+ res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 3 ) . try_into ( ) . unwrap ( ) } ;
64
+ assert_eq ! ( res, 3 ) ;
65
+ unsafe { libc:: close ( fds[ 0 ] ) } ;
66
+ // Reading the other end should return that data, then EOF.
67
+ let mut buf: [ u8 ; 5 ] = [ 0 ; 5 ] ;
68
+ res = unsafe {
69
+ libc:: read ( fds[ 1 ] , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) as libc:: size_t ) . try_into ( ) . unwrap ( )
70
+ } ;
71
+ assert_eq ! ( res, 3 ) ;
72
+ assert_eq ! ( & buf[ 0 ..3 ] , "123" . as_bytes( ) ) ;
73
+ res = unsafe {
74
+ libc:: read ( fds[ 1 ] , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) as libc:: size_t ) . try_into ( ) . unwrap ( )
75
+ } ;
76
+ assert_eq ! ( res, 0 ) ; // 0-sized read: EOF.
77
+ // Writing the other end should emit EPIPE.
78
+ res = unsafe { libc:: write ( fds[ 1 ] , data as * const libc:: c_void , 1 ) . try_into ( ) . unwrap ( ) } ;
79
+ assert_eq ! ( res, -1 ) ;
80
+ assert_eq ! ( std:: io:: Error :: last_os_error( ) . raw_os_error( ) , Some ( libc:: EPIPE ) ) ;
61
81
}
62
82
63
83
fn test_socketpair_threaded ( ) {
You can’t perform that action at this time.
0 commit comments