-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.py
119 lines (96 loc) · 3.47 KB
/
run_tests.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python
import glob
import json
import os
import pickle
os.chdir(os.path.dirname(__file__))
from test_evm.global_test_params import (
PASS, FAIL, TIME_OUT, UNKNOWN_INSTRUCTION, EXCEPTION, EMPTY_RESULT,
INCORRECT_GAS, PICKLE_PATH)
from test_evm.evm_unit_test import EvmUnitTest
def remove_temporary_files():
rm_file('bytecode')
rm_file('bytecode.disasm')
rm_file(PICKLE_PATH)
def rm_file(path):
if os.path.isfile(path):
os.unlink(path)
def status(exit_code):
if exit_code == 100: return "Pass"
if exit_code == 101: return "Fail"
if exit_code == 102: return "Time out"
if exit_code == 103: return "Unkown instruction"
if exit_code == 104: return "Exception"
if exit_code == 105: return "Empty result"
if exit_code == 106: return "Incorrect gas tracked"
return str(exit_code)
def main():
test_dir = 'test_evm/test_data'
files = glob.glob(test_dir + '/*.json')
test_cases = {}
num_tests = num_passes = num_fails = \
num_time_outs = num_unkown_instrs = \
num_exceptions = num_empty_res = num_incorrect_gas = 0
fails, time_outs, \
unkown_instrs, exceptions, empty_res, \
incorrect_gas = [], [], [], [], [], []
for f in files:
test_cases.update(json.loads(open(f).read()))
print "*****************************************************"
print " ************* "
print " Start "
for testname, testdata in list(test_cases.items()):
print
print
print "===============Loading: %s====================" % testname
current_test = EvmUnitTest(testname, testdata)
pickle.dump(current_test, open(PICKLE_PATH, 'wb'), pickle.HIGHEST_PROTOCOL)
exit_code = current_test.run_test()
# Special case when symExec run into exception but it is correct result
if exit_code == EXCEPTION and current_test.is_exception_case():
exit_code = PASS
if exit_code:
print "===============%s!====================" % status(exit_code).upper()
else:
print "no exit code returned"
testname = testname.encode('utf8')
num_tests += 1
if exit_code == PASS:
num_passes += 1
elif exit_code == FAIL:
fails.append(testname)
num_fails += 1
elif exit_code == TIME_OUT:
time_outs.append(testname)
num_time_outs += 1
elif exit_code == UNKNOWN_INSTRUCTION:
unkown_instrs.append(testname)
num_unkown_instrs += 1
elif exit_code == EXCEPTION:
exceptions.append(testname)
num_exceptions += 1
elif exit_code == EMPTY_RESULT:
empty_res.append(testname)
num_empty_res += 1
elif exit_code == INCORRECT_GAS:
incorrect_gas.append(testname)
num_incorrect_gas += 1
remove_temporary_files()
print "Done!"
print "Total: ", num_tests
print
print "Pass: ", num_passes
print
print "Fail: ", num_fails, fails
print
print "Time out: ", num_time_outs, time_outs
print
print "Unkown instruction: ", num_unkown_instrs, unkown_instrs
print
print "Exception: ", num_exceptions, exceptions
print
print "Empty result: ", num_empty_res, empty_res
print
print "Incorrect gas tracked", num_incorrect_gas, incorrect_gas
if __name__ == '__main__':
main()