| 1 | |
| 2 | import py |
| 3 | |
| 4 | from pypy.tool.bench.pypyresult import ResultDB, BenchResult |
| 5 | import pickle |
| 6 | |
| 7 | def setup_module(mod): |
| 8 | mod.tmpdir = py.test.ensuretemp(__name__) |
| 9 | |
| 10 | def gettestpickle(cache=[]): |
| 11 | if cache: |
| 12 | return cache[0] |
| 13 | pp = tmpdir.join("testpickle") |
| 14 | f = pp.open("wb") |
| 15 | pickle.dump({'./pypy-llvm-39474-O3-c_richards': 5}, f) |
| 16 | pickle.dump({'./pypy-llvm-39474-O3-c_richards': 42.0}, f) |
| 17 | f.close() |
| 18 | cache.append(pp) |
| 19 | return pp |
| 20 | |
| 21 | def test_unpickle(): |
| 22 | pp = gettestpickle() |
| 23 | db = ResultDB() |
| 24 | db.parsepickle(pp) |
| 25 | assert len(db.benchmarks) == 1 |
| 26 | l = db.getbenchmarks(name="richards") |
| 27 | assert len(l) == 1 |
| 28 | bench = l[0] |
| 29 | l = db.getbenchmarks(name="xyz") |
| 30 | assert not l |
| 31 | |
| 32 | def test_BenchResult_cpython(): |
| 33 | res = BenchResult("2.3.5_pystone", besttime=2.0, numruns=3) |
| 34 | assert res.executable == "cpython" |
| 35 | assert res.revision == "2.3.5" |
| 36 | assert res.name == "pystone" |
| 37 | assert res.numruns == 3 |
| 38 | assert res.besttime == 2.0 |
| 39 | |
| 40 | def test_BenchResult_pypy(): |
| 41 | res = BenchResult("pypy-llvm-39474-O3-c_richards", |
| 42 | besttime=2.0, numruns=3) |
| 43 | assert res.executable == "pypy-llvm-39474-O3-c" |
| 44 | assert res.revision == 39474 |
| 45 | assert res.name == "richards" |
| 46 | assert res.numruns == 3 |
| 47 | assert res.besttime == 2.0 |