|
| 1 | +import json |
| 2 | +import os |
| 3 | +import sys |
| 4 | +import ethereum.testutils as testutils |
| 5 | +import cProfile |
| 6 | +import pstats |
| 7 | +import StringIO |
| 8 | +import time |
| 9 | +from ethereum.utils import sha3_call_counter, sha3 |
| 10 | +from ethereum.slogging import get_logger, configure_logging, get_configuration |
| 11 | +logger = get_logger() |
| 12 | +import sys |
| 13 | + |
| 14 | + |
| 15 | +def do_test_vm(filename, testname=None, testdata=None, limit=99999999, profiler=None): |
| 16 | + logger.debug('running test:%r in %r' % (testname, filename)) |
| 17 | + testutils.run_vm_test(testutils.fixture_to_bytes(testdata), testutils.VERIFY, profiler=profiler) |
| 18 | + |
| 19 | +if __name__ == '__main__': |
| 20 | + num = 5000 |
| 21 | + print 'loading tests' |
| 22 | + fixtures = testutils.get_tests_from_file_or_dir( |
| 23 | + os.path.join(testutils.fixture_path, 'VMTests')) |
| 24 | + |
| 25 | + def run(profiler=None): |
| 26 | + print 'running' |
| 27 | + i = 0 |
| 28 | + seen = b'' |
| 29 | + for filename, tests in fixtures.items(): |
| 30 | + for testname, testdata in tests.items(): |
| 31 | + if i == num: |
| 32 | + break |
| 33 | + do_test_vm(filename, testname, testdata, profiler=profiler) |
| 34 | + seen += str(testname) |
| 35 | + i += 1 |
| 36 | + print 'ran %d tests' % i |
| 37 | + print 'test key', sha3(seen).encode('hex') |
| 38 | + |
| 39 | + if len(sys.argv) == 2: |
| 40 | + pr = cProfile.Profile() |
| 41 | + run(pr) |
| 42 | + s = StringIO.StringIO() |
| 43 | + sortby = 'tottime' |
| 44 | + ps = pstats.Stats(pr, stream=s).sort_stats(sortby) |
| 45 | + ps.print_stats(50) |
| 46 | + print s.getvalue() |
| 47 | + else: |
| 48 | + st = time.time() |
| 49 | + run() |
| 50 | + print |
| 51 | + print 'took total', time.time() - st |
| 52 | + print 'took w/o sha3', time.time() - st - sha3_call_counter[3] |
0 commit comments