Anonymous avatar Anonymous committed 2443039

Preserve pyfuzz output between iterations

Previously, pyfuzz would reuse the same pathname over and over, making it
difficult/impossible to debug crashes/errors if --break was not given. This
patch makes pyfuzz use a unique filename for each iteration.

Patch by Collin Winter

Comments (0)

Files changed (2)

 import subprocess
 import time
 import pickle
+import os
 import random
     parser.add_option("-p", "--pickle", action="store_true", dest="pickle", default=False, help="Output pickled AST.")
     parser.add_option("-i", type="int", dest="iterations", default=100000, help="Number of test iterations.")
     parser.add_option("-s", "--seed", type="int", dest="seed", default=None, help="Seed value for random number generator")
+    parser.add_option("--codepath", type="string", dest="codepath", default=".", help="Path to store code files.")
     (options, args) = parser.parse_args()
         clock = time.time()
         mod = pgen.generate()
         fixed = fix.generate(mod)
-        with open("code.pickle","w") as code_pickle:
+        prefix = "pyfuzz-output.%d" % i
+        prefix = os.path.join(options.codepath, prefix)
+        with open(prefix + ".pickle", "w") as code_pickle:
             pickle.dump(fixed, code_pickle)
         code = gen.generate(fixed)
-        with open("", "w") as code_file:
+        code_path = prefix + ".py"
+        with open(code_path, "w") as code_file:
         clock_test = time.time()    
-        test_command = [options.test] + options.testargs.split() + ['']
+        test_command = [options.test] + options.testargs.split() + [code_path]
         p_test = subprocess.Popen(test_command,
                     stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         stdout_test, stderr_test = p_test.communicate()
         clock_base = time.time()
-        base_command = [options.base] + options.baseargs.split() + ['']
+        base_command = [options.base] + options.baseargs.split() + [code_path]
         p_base = subprocess.Popen(base_command,
                     stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         stdout_base, stderr_base = p_base.communicate()
 #            print "Test", clock_test
 #            print "Base", clock_base
 ##            print code
         if stdout_base != stdout_test:
             print "------- Encountered different result --------"
             print "Test %s" % (stdout_test, )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.