virtual: Introduce a base class for test cases
Introduce a base class with the intended life cycle and use it.
Change-Id: I97968fb02436d5ac8248fc8020539e1af547b030
diff --git a/src/osmo_ms_driver/location_update_test.py b/src/osmo_ms_driver/location_update_test.py
index 7a58b93..1a33f09 100644
--- a/src/osmo_ms_driver/location_update_test.py
+++ b/src/osmo_ms_driver/location_update_test.py
@@ -16,10 +16,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from osmo_gsm_tester import log
-
from datetime import timedelta
+from .test_support import TestBase
+
import collections
import json
import time
@@ -55,12 +55,10 @@
LUStats = collections.namedtuple("LUStats", ["num_attempted", "num_completed",
"min_latency", "max_latency"])
-class MassUpdateLocationTest(log.Origin):
+class MassUpdateLocationTest(TestBase):
def __init__(self, name, event_server, results):
- super().__init__(log.C_RUN, name)
- self._event_server = event_server
+ super().__init__(name, event_server, results)
self._event_server.register(self.handle_msg)
- self._results = results
def configure(self, num_subscribers):
self._num_subscribers = num_subscribers
@@ -77,12 +75,12 @@
set_lu_time(ms, time)
self.log("MS performed LU ", ms=ms, at=time, lu_delay=lu_delay(ms))
- def all_completed(self):
+ def has_completed(self):
return self._outstanding == 0
def wait_for_test(self, loop, deadline):
"""Waits up to the absolute deadline for the test to complete."""
- while not self.all_completed():
+ while not self.has_completed():
now_time = time.clock_gettime(time.CLOCK_MONOTONIC)
sleep_time = deadline - now_time
if sleep_time < 0:
diff --git a/src/osmo_ms_driver/test_support.py b/src/osmo_ms_driver/test_support.py
index 670d795..cbfd444 100644
--- a/src/osmo_ms_driver/test_support.py
+++ b/src/osmo_ms_driver/test_support.py
@@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from abc import ABCMeta
from osmo_gsm_tester import log
def imsi_ki_gen():
@@ -63,3 +64,32 @@
def has_result(self, key):
"""Returns true if there is a value for the key."""
return self._results.get(key) is not None
+
+
+class TestBase(log.Origin, metaclass=ABCMeta):
+ """Base class for all mass test cases."""
+
+ def __init__(self, name, event_server, results):
+ super().__init__(log.C_RUN, name)
+ self._event_server = event_server
+ self._results = results
+
+ def configure(self, num_subscribers):
+ """Configures the test given the (number) of subscribers."""
+ pass
+
+ def before_start(self):
+ """Prepares the test for starting."""
+ pass
+
+ def after_start(self):
+ """Finishes the test after starting."""
+ pass
+
+ def has_completed(self):
+ """Returns true if the test has completed."""
+ pass
+
+ def print_stats(self):
+ """Prints statistics/results of the test."""
+ pass