20
20
import platform
21
21
from colorama import Fore , Style
22
22
from threading import Lock
23
- from random import randbytes
24
- from base64 import b64encode
23
+ from random import randbytes , choices
24
+ from string import printable
25
25
from itertools import zip_longest
26
26
from tqdm import tqdm
27
27
@@ -442,46 +442,50 @@ def random_test_patterns(tests_path: str, include: Optional[list[str]], exclude:
442
442
LOG .error ("❌ hyperscan pattern compilation error in '%s'" , dirpath )
443
443
exit (1 )
444
444
445
- goal = 100000000000
446
- chunk_size = 100000000
445
+ binary_goal = 1000000000
446
+ ascii_goal = 1000000000
447
+ binary_chunk_size = 100000000
448
+ ascii_chunk_size = 100000000
447
449
448
450
if progress :
449
- pb = tqdm (total = goal , unit_scale = True , unit = 'B' )
451
+ pb = tqdm (total = binary_goal + ascii_goal , unit_scale = True , unit = 'B' )
450
452
451
- # read 100GB of random data (a mix of binary and base64 encoded)
452
- while size_read < goal :
453
+ # read 100GB of random binary data
454
+ while size_read < binary_goal :
453
455
# read random bytes, 100MB at a time
454
- content = randbytes (chunk_size )
455
-
456
- size_read += len (content )
457
- if progress :
458
- pb .update (len (content ))
456
+ binary_content = randbytes (binary_chunk_size )
459
457
460
458
scan (db ,
461
459
None ,
462
- content ,
460
+ binary_content ,
463
461
patterns ,
464
462
verbose = verbose ,
465
463
quiet = quiet ,
466
464
write_to_results = True ,
467
465
dry_run = True )
468
466
469
- # same content, base64 encoded
470
- content_b64 = b64encode (content )
471
-
472
- size_read += len (content_b64 )
467
+ size_read += binary_chunk_size
473
468
if progress :
474
- pb .update (len (content_b64 ))
469
+ pb .update (binary_chunk_size )
470
+
471
+ # read 1GB of random ascii data
472
+ while size_read < binary_goal + ascii_goal :
473
+ # some random ASCII (printable characters)
474
+ ascii_content = '' .join (choices (printable , k = ascii_chunk_size )).encode ('utf-8' )
475
475
476
476
scan (db ,
477
477
None ,
478
- content_b64 ,
478
+ ascii_content ,
479
479
patterns ,
480
480
verbose = verbose ,
481
481
quiet = quiet ,
482
482
write_to_results = True ,
483
483
dry_run = True )
484
484
485
+ size_read += ascii_chunk_size
486
+ if progress :
487
+ pb .update (ascii_chunk_size )
488
+
485
489
if progress :
486
490
pb .close ()
487
491
@@ -491,7 +495,7 @@ def random_test_patterns(tests_path: str, include: Optional[list[str]], exclude:
491
495
for pattern_name , results in RESULTS .items ():
492
496
count = sum ((1 for result in results ))
493
497
if count > 0 :
494
- LOG .info ("%s: %d" , pattern_name , )
498
+ LOG .info ("%s: %d" , pattern_name , count )
495
499
496
500
497
501
# sideffect: writes to global RESULTS
0 commit comments