mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-16 07:28:52 +00:00
Fix fuzzer
This commit is contained in:
@@ -86,7 +86,6 @@ if __name__ == "__main__":
|
|||||||
install_csmith(tests_dir, csmith_bin)
|
install_csmith(tests_dir, csmith_bin)
|
||||||
|
|
||||||
# Run cargo test infinitely
|
# Run cargo test infinitely
|
||||||
TEST_FAIL_TOKEN = "test result: FAILED."
|
|
||||||
raw_test_file = "raw_test.c"
|
raw_test_file = "raw_test.c"
|
||||||
test_file = "test.c"
|
test_file = "test.c"
|
||||||
try:
|
try:
|
||||||
@@ -101,12 +100,16 @@ if __name__ == "__main__":
|
|||||||
print("Test case #{}".format(i))
|
print("Test case #{}".format(i))
|
||||||
preprocess(generate(tests_dir, csmith_bin, csmith_runtime, raw_test_file), test_file)
|
preprocess(generate(tests_dir, csmith_bin, csmith_runtime, raw_test_file), test_file)
|
||||||
args = ["cargo", "run", "--release", "--bin", "fuzz", "--", cargo_arg, os.path.join(csmith_runtime, test_file)]
|
args = ["cargo", "run", "--release", "--bin", "fuzz", "--", cargo_arg, os.path.join(csmith_runtime, test_file)]
|
||||||
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=tests_dir)
|
|
||||||
test_result = str(proc.stdout.read())
|
try:
|
||||||
if TEST_FAIL_TOKEN in test_result:
|
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=tests_dir)
|
||||||
sys.exit("[Error] Test failed. Check `{}` that failed to parse.\nTo investigate, run '{}` in terminal."
|
(out, err) = proc.communicate(timeout=10)
|
||||||
.format(os.path.join(csmith_runtime, test_file), " ".join(args)))
|
if proc.returncode != 0:
|
||||||
|
raise Exception("Test `{}` failed with exit code {}.".format(" ".join(args), proc.returncode))
|
||||||
|
except subprocess.TimeoutExpired as e:
|
||||||
|
proc.kill()
|
||||||
|
raise e
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
proc.terminate()
|
proc.terminate()
|
||||||
print("\n[KeyboardInterrupt] Test ended")
|
print("\n[Ctrl+C] interrupted")
|
||||||
|
|||||||
Reference in New Issue
Block a user