1818
1919
2020def main ():
21- parser = argparse .ArgumentParser (formatter_class = argparse .ArgumentDefaultsHelpFormatter )
21+ parser = argparse .ArgumentParser (
22+ formatter_class = argparse .ArgumentDefaultsHelpFormatter ,
23+ description = '''Run the fuzz targets with all inputs from the seed_dir once.''' ,
24+ )
2225 parser .add_argument (
2326 "-l" ,
2427 "--loglevel" ,
@@ -50,6 +53,10 @@ def main():
5053 nargs = '*' ,
5154 help = 'The target(s) to run. Default is to run all targets.' ,
5255 )
56+ parser .add_argument (
57+ '--m_dir' ,
58+ help = 'Merge inputs from this directory into the seed_dir. Needs /target subdirectory.' ,
59+ )
5360
5461 args = parser .parse_args ()
5562
@@ -112,6 +119,14 @@ def main():
112119 logging .error ("subprocess timed out: Currently only libFuzzer is supported" )
113120 sys .exit (1 )
114121
122+ if args .m_dir :
123+ merge_inputs (
124+ corpus = args .seed_dir ,
125+ test_list = test_list_selection ,
126+ build_dir = config ["environment" ]["BUILDDIR" ],
127+ merge_dir = args .m_dir ,
128+ )
129+
115130 run_once (
116131 corpus = args .seed_dir ,
117132 test_list = test_list_selection ,
@@ -121,6 +136,22 @@ def main():
121136 )
122137
123138
139+ def merge_inputs (* , corpus , test_list , build_dir , merge_dir ):
140+ logging .info ("Merge the inputs in the passed dir into the seed_dir. Passed dir {}" .format (merge_dir ))
141+ for t in test_list :
142+ args = [
143+ os .path .join (build_dir , 'src' , 'test' , 'fuzz' , t ),
144+ '-merge=1' ,
145+ os .path .join (corpus , t ),
146+ os .path .join (merge_dir , t ),
147+ ]
148+ os .makedirs (os .path .join (corpus , t ), exist_ok = True )
149+ os .makedirs (os .path .join (merge_dir , t ), exist_ok = True )
150+ logging .debug ('Run {} with args {}' .format (t , args ))
151+ output = subprocess .run (args , check = True , stderr = subprocess .PIPE , universal_newlines = True ).stderr
152+ logging .debug ('Output: {}' .format (output ))
153+
154+
124155def run_once (* , corpus , test_list , build_dir , export_coverage , use_valgrind ):
125156 for t in test_list :
126157 corpus_path = os .path .join (corpus , t )
0 commit comments