forked from fuzzland/ityfuzz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_test.py
64 lines (49 loc) · 1.86 KB
/
integration_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import glob
import subprocess
import os
import time
TIMEOUT_BIN = "timeout" if os.name == "posix" else "gtimeout"
def test_one(path):
# cleanup
os.system(f"rm -rf {path}/build")
# compile with solc
p = subprocess.run(
" ".join(["solc", f"{path}/*.sol", "-o", f"{path}/",
"--bin", "--abi", "--overwrite", "--base-path", "."]),
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if b"Error" in p.stderr or b"Error" in p.stdout:
print(f"Error compiling {path}")
return
# run fuzzer and check whether the stdout has string success
start_time = time.time()
p = subprocess.run(" ".join([
TIMEOUT_BIN, "3m", "./cli/target/release/cli", "evm", "-t", f"'{path}/*'", "-f", "--panic-on-bug"]),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True
)
if b"target bug found" not in p.stderr \
and b"bug() hit" not in p.stdout \
and b"[typed_bug]" not in p.stdout \
and b"[selfdestruct]" not in p.stdout \
and b"[echidna_bug]" not in p.stdout\
and b"Found violations!" not in p.stdout:
print("================ STDERR =================")
print(p.stderr.decode("utf-8"))
print("================ STDOUT =================")
print(p.stdout.decode("utf-8"))
raise Exception(f"Failed to fuzz {path}")
# clean up
os.system(f"rm -rf {path}/*.abi")
os.system(f"rm -rf {path}/*.bin")
print(f"=== Success: {path}, Finished in {time.time() - start_time}s")
def build_fuzzer():
# build fuzzer
os.chdir("cli")
subprocess.run(["cargo", "build", "--release"])
os.chdir("..")
import multiprocessing
if __name__ == "__main__":
build_fuzzer()
with multiprocessing.Pool(3) as p:
p.map(test_one, glob.glob("./tests/evm/*/", recursive=True))