File tree 2 files changed +25
-25
lines changed
2 files changed +25
-25
lines changed Original file line number Diff line number Diff line change @@ -920,28 +920,3 @@ fn min_stack_size(_: *const libc::pthread_attr_t) -> usize {
920
920
fn min_stack_size ( _: * const libc:: pthread_attr_t ) -> usize {
921
921
2048 // just a guess
922
922
}
923
-
924
- #[ test]
925
- #[ cfg( any( target_os = "linux" , target_os = "macos" , target_os = "ios" , target_os = "watchos" ) ) ]
926
- fn test_named_thread_truncation ( ) {
927
- use crate :: thread:: { self , Builder } ;
928
-
929
- let long_name = crate :: iter:: once ( "test_named_thread_truncation" )
930
- . chain ( crate :: iter:: repeat ( " yada" ) . take ( 100 ) )
931
- . collect :: < String > ( ) ;
932
-
933
- let result = Builder :: new ( ) . name ( long_name. clone ( ) ) . spawn ( move || {
934
- // Rust remembers the full thread name itself.
935
- assert_eq ! ( thread:: current( ) . name( ) , Some ( long_name. as_str( ) ) ) ;
936
-
937
- // But the kernel is limited -- make sure we successfully set a truncation.
938
- let mut buf = vec ! [ 0u8 ; long_name. len( ) + 1 ] ;
939
- unsafe {
940
- libc:: pthread_getname_np ( libc:: pthread_self ( ) , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) ) ;
941
- }
942
- let cstr = CStr :: from_bytes_until_nul ( & buf) . unwrap ( ) ;
943
- assert ! ( cstr. to_bytes( ) . len( ) > 0 ) ;
944
- assert ! ( long_name. as_bytes( ) . starts_with( cstr. to_bytes( ) ) ) ;
945
- } ) ;
946
- result. unwrap ( ) . join ( ) . unwrap ( ) ;
947
- }
Original file line number Diff line number Diff line change @@ -37,6 +37,31 @@ fn test_named_thread() {
37
37
. unwrap ( ) ;
38
38
}
39
39
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
+
40
65
#[ test]
41
66
#[ should_panic]
42
67
fn test_invalid_named_thread ( ) {
You can’t perform that action at this time.
0 commit comments