Skip to content

Commit

Permalink
Added support for capturing data points for testing
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <git@stefan-marr.de>
  • Loading branch information
smarr committed Jul 29, 2018
1 parent 27dd6f8 commit 8b57299
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 8 deletions.
4 changes: 4 additions & 0 deletions rebench/model/data_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def __init__(self, run_id):
self._total = None
self._invocation = -1

@property
def run_id(self):
return self._run_id

@property
def invocation(self):
return self._invocation
Expand Down
2 changes: 1 addition & 1 deletion rebench/model/run_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def is_completed(self, ui):
def run_failed(self):
return (self._termination_check.fails_consecutively() or
self._termination_check.has_too_many_failures(
len(self.get_number_of_data_points())))
self.get_number_of_data_points()))

def __hash__(self):
return hash(self.cmdline())
Expand Down
11 changes: 9 additions & 2 deletions rebench/tests/executor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import subprocess
import os

from .persistence import TestPersistence
from .rebench_test_case import ReBenchTestCase
from ..rebench import ReBench
from ..executor import Executor
Expand Down Expand Up @@ -79,10 +80,16 @@ def test_broken_command_format_with_TypeError(self):
def _basic_execution(self, cnf):
runs = cnf.get_runs()
self.assertEqual(8, len(runs))
ex = Executor(cnf.get_runs(), cnf.use_nice, cnf.do_builds, TestDummyUI())

runs = cnf.get_runs()
persistence = TestPersistence()
for run in runs:
run.add_persistence(persistence)

ex = Executor(runs, cnf.use_nice, cnf.do_builds, TestDummyUI())
ex.execute()
for run in runs:
data_points = run.get_data_points()
data_points = persistence.get_data_points(run)
self.assertEqual(10, len(data_points))
for data_point in data_points:
measurements = data_point.get_measurements()
Expand Down
9 changes: 7 additions & 2 deletions rebench/tests/features/issue_16_multiple_data_points_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from ...configurator import Configurator, load_config
from ...executor import Executor
from ...persistence import DataStore
from ..persistence import TestPersistence
from ..rebench_test_case import ReBenchTestCase


Expand All @@ -38,12 +39,16 @@ def _records_data_points(self, exp_name, num_data_points):
cnf = Configurator(load_config(self._path + '/issue_16.conf'), DataStore(self._ui),
self._ui, exp_name=exp_name,
data_file=self._tmp_file)
runs = cnf.get_runs()
persistence = TestPersistence()
for run in runs:
run.add_persistence(persistence)
ex = Executor(cnf.get_runs(), False, False, self._ui)
ex.execute()
self.assertEqual(1, len(cnf.get_runs()))
run = next(iter(cnf.get_runs()))
self.assertEqual(num_data_points, len(run.get_data_points()))
return run.get_data_points()
self.assertEqual(num_data_points, run.get_number_of_data_points())
return persistence.get_data_points()

def test_records_multiple_data_points_from_single_execution_10(self):
self._records_data_points('Test1', 10)
Expand Down
12 changes: 9 additions & 3 deletions rebench/tests/features/issue_31_multivariate_data_points_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from ...configurator import Configurator, load_config
from ...executor import Executor
from ...persistence import DataStore
from ..persistence import TestPersistence
from ..rebench_test_case import ReBenchTestCase


Expand All @@ -38,12 +39,17 @@ def _records_data_points(self, exp_name, num_data_points):
cnf = Configurator(load_config(self._path + '/issue_31.conf'), DataStore(self._ui),
self._ui, exp_name=exp_name,
data_file=self._tmp_file)
ex = Executor(cnf.get_runs(), False, False, self._ui)
runs = cnf.get_runs()
persistence = TestPersistence()
for run in runs:
run.add_persistence(persistence)

ex = Executor(runs, False, False, self._ui)
ex.execute()
self.assertEqual(1, len(cnf.get_runs()))
run = next(iter(cnf.get_runs()))
self.assertEqual(num_data_points, len(run.get_data_points()))
return run.get_data_points()
self.assertEqual(num_data_points, run.get_number_of_data_points())
return persistence.get_data_points()

def test_records_multiple_data_points_from_single_execution_10(self):
self._records_data_points('Test1', 10)
Expand Down
15 changes: 15 additions & 0 deletions rebench/tests/persistence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class TestPersistence(object):

def __init__(self):
self._data_points = []

def get_data_points(self, run_id=None):
if run_id:
return [dp for dp in self._data_points if dp.run_id is run_id]
return self._data_points

def persist_data_point(self, data_point):
self._data_points.append(data_point)

def close(self):
pass

0 comments on commit 8b57299

Please sign in to comment.