File tree Expand file tree Collapse file tree 2 files changed +25
-25
lines changed Expand file tree Collapse file tree 2 files changed +25
-25
lines changed Original file line number Diff line number Diff line change @@ -911,28 +911,3 @@ fn min_stack_size(_: *const libc::pthread_attr_t) -> usize {
911911fn min_stack_size ( _: * const libc:: pthread_attr_t ) -> usize {
912912 2048 // just a guess
913913}
914-
915- #[ test]
916- #[ cfg( any( target_os = "linux" , target_os = "macos" , target_os = "ios" , target_os = "watchos" ) ) ]
917- fn test_named_thread_truncation ( ) {
918- use crate :: thread:: { self , Builder } ;
919-
920- let long_name = crate :: iter:: once ( "test_named_thread_truncation" )
921- . chain ( crate :: iter:: repeat ( " yada" ) . take ( 100 ) )
922- . collect :: < String > ( ) ;
923-
924- let result = Builder :: new ( ) . name ( long_name. clone ( ) ) . spawn ( move || {
925- // Rust remembers the full thread name itself.
926- assert_eq ! ( thread:: current( ) . name( ) , Some ( long_name. as_str( ) ) ) ;
927-
928- // But the kernel is limited -- make sure we successfully set a truncation.
929- let mut buf = vec ! [ 0u8 ; long_name. len( ) + 1 ] ;
930- unsafe {
931- libc:: pthread_getname_np ( libc:: pthread_self ( ) , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) ) ;
932- }
933- let cstr = CStr :: from_bytes_until_nul ( & buf) . unwrap ( ) ;
934- assert ! ( cstr. to_bytes( ) . len( ) > 0 ) ;
935- assert ! ( long_name. as_bytes( ) . starts_with( cstr. to_bytes( ) ) ) ;
936- } ) ;
937- result. unwrap ( ) . join ( ) . unwrap ( ) ;
938- }
Original file line number Diff line number Diff line change @@ -37,6 +37,31 @@ fn test_named_thread() {
3737 . unwrap ( ) ;
3838}
3939
40+ #[ cfg( any( target_os = "linux" , target_os = "macos" , target_os = "ios" , target_os = "watchos" ) ) ]
41+ #[ test]
42+ fn test_named_thread_truncation ( ) {
43+ use crate :: ffi:: CStr ;
44+
45+ let long_name = crate :: iter:: once ( "test_named_thread_truncation" )
46+ . chain ( crate :: iter:: repeat ( " yada" ) . take ( 100 ) )
47+ . collect :: < String > ( ) ;
48+
49+ let result = Builder :: new ( ) . name ( long_name. clone ( ) ) . spawn ( move || {
50+ // Rust remembers the full thread name itself.
51+ assert_eq ! ( thread:: current( ) . name( ) , Some ( long_name. as_str( ) ) ) ;
52+
53+ // But the system is limited -- make sure we successfully set a truncation.
54+ let mut buf = vec ! [ 0u8 ; long_name. len( ) + 1 ] ;
55+ unsafe {
56+ libc:: pthread_getname_np ( libc:: pthread_self ( ) , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) ) ;
57+ }
58+ let cstr = CStr :: from_bytes_until_nul ( & buf) . unwrap ( ) ;
59+ assert ! ( cstr. to_bytes( ) . len( ) > 0 ) ;
60+ assert ! ( long_name. as_bytes( ) . starts_with( cstr. to_bytes( ) ) ) ;
61+ } ) ;
62+ result. unwrap ( ) . join ( ) . unwrap ( ) ;
63+ }
64+
4065#[ test]
4166#[ should_panic]
4267fn test_invalid_named_thread ( ) {
You can’t perform that action at this time.
0 commit comments