@@ -10,9 +10,8 @@ use uutests::util::TestScenario;
1010use uutests:: util:: log_info;
1111use uutests:: util_name;
1212
13- const ALGOS : [ & str ; 12 ] = [
14- "sysv" , "bsd" , "crc" , "crc32b" , "md5" , "sha1" , "sha224" , "sha256" , "sha384" , "sha512" ,
15- "blake2b" , "sm3" ,
13+ const ALGOS : [ & str ; 11 ] = [
14+ "sysv" , "bsd" , "crc" , "md5" , "sha1" , "sha224" , "sha256" , "sha384" , "sha512" , "blake2b" , "sm3" ,
1615] ;
1716const SHA_LENGTHS : [ u32 ; 4 ] = [ 224 , 256 , 384 , 512 ] ;
1817
@@ -2876,3 +2875,107 @@ mod format_mix {
28762875 . stderr_contains ( "cksum: WARNING: 1 line is improperly formatted" ) ;
28772876 }
28782877}
2878+
2879+ #[ cfg( not( target_os = "android" ) ) ]
2880+ mod debug_flag {
2881+ use super :: * ;
2882+
2883+ #[ test]
2884+ fn test_debug_flag ( ) {
2885+ // Test with default CRC algorithm - should output CPU feature detection
2886+ new_ucmd ! ( )
2887+ . arg ( "--debug" )
2888+ . arg ( "lorem_ipsum.txt" )
2889+ . succeeds ( )
2890+ . stdout_is_fixture ( "crc_single_file.expected" )
2891+ . stderr_contains ( "avx512" )
2892+ . stderr_contains ( "avx2" )
2893+ . stderr_contains ( "pclmul" ) ;
2894+
2895+ // Test with MD5 algorithm - CPU detection should be same regardless of algorithm
2896+ new_ucmd ! ( )
2897+ . arg ( "--debug" )
2898+ . arg ( "-a" )
2899+ . arg ( "md5" )
2900+ . arg ( "lorem_ipsum.txt" )
2901+ . succeeds ( )
2902+ . stdout_is_fixture ( "md5_single_file.expected" )
2903+ . stderr_contains ( "avx512" )
2904+ . stderr_contains ( "avx2" )
2905+ . stderr_contains ( "pclmul" ) ;
2906+
2907+ // Test with stdin - CPU detection should appear once
2908+ new_ucmd ! ( )
2909+ . arg ( "--debug" )
2910+ . pipe_in ( "test" )
2911+ . succeeds ( )
2912+ . stderr_contains ( "avx512" )
2913+ . stderr_contains ( "avx2" )
2914+ . stderr_contains ( "pclmul" ) ;
2915+
2916+ // Test with multiple files - CPU detection should appear once, not per file
2917+ new_ucmd ! ( )
2918+ . arg ( "--debug" )
2919+ . arg ( "lorem_ipsum.txt" )
2920+ . arg ( "alice_in_wonderland.txt" )
2921+ . succeeds ( )
2922+ . stdout_is_fixture ( "crc_multiple_files.expected" )
2923+ . stderr_str_check ( |stderr| {
2924+ // Verify CPU detection happens only once by checking the count of each feature line
2925+ let avx512_count = stderr. lines ( ) . filter ( |line| line. contains ( "avx512" ) ) . count ( ) ;
2926+ let avx2_count = stderr. lines ( ) . filter ( |line| line. contains ( "avx2" ) ) . count ( ) ;
2927+ let pclmul_count = stderr. lines ( ) . filter ( |line| line. contains ( "pclmul" ) ) . count ( ) ;
2928+
2929+ avx512_count == 1 && avx2_count == 1 && pclmul_count == 1
2930+ } ) ;
2931+ }
2932+
2933+ #[ test]
2934+ fn test_debug_with_algorithms ( ) {
2935+ // Test with SHA256 - CPU detection should be same regardless of algorithm
2936+ new_ucmd ! ( )
2937+ . arg ( "--debug" )
2938+ . arg ( "-a" )
2939+ . arg ( "sha256" )
2940+ . arg ( "lorem_ipsum.txt" )
2941+ . succeeds ( )
2942+ . stderr_contains ( "avx512" )
2943+ . stderr_contains ( "avx2" )
2944+ . stderr_contains ( "pclmul" ) ;
2945+
2946+ // Test with BLAKE2b default length
2947+ new_ucmd ! ( )
2948+ . arg ( "--debug" )
2949+ . arg ( "-a" )
2950+ . arg ( "blake2b" )
2951+ . arg ( "lorem_ipsum.txt" )
2952+ . succeeds ( )
2953+ . stderr_contains ( "avx512" )
2954+ . stderr_contains ( "avx2" )
2955+ . stderr_contains ( "pclmul" ) ;
2956+
2957+ // Test with BLAKE2b custom length
2958+ new_ucmd ! ( )
2959+ . arg ( "--debug" )
2960+ . arg ( "-a" )
2961+ . arg ( "blake2b" )
2962+ . arg ( "--length" )
2963+ . arg ( "256" )
2964+ . arg ( "lorem_ipsum.txt" )
2965+ . succeeds ( )
2966+ . stderr_contains ( "avx512" )
2967+ . stderr_contains ( "avx2" )
2968+ . stderr_contains ( "pclmul" ) ;
2969+
2970+ // Test with SHA1
2971+ new_ucmd ! ( )
2972+ . arg ( "--debug" )
2973+ . arg ( "-a" )
2974+ . arg ( "sha1" )
2975+ . arg ( "lorem_ipsum.txt" )
2976+ . succeeds ( )
2977+ . stderr_contains ( "avx512" )
2978+ . stderr_contains ( "avx2" )
2979+ . stderr_contains ( "pclmul" ) ;
2980+ }
2981+ }
0 commit comments