summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2019-04-30 15:38:51 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2019-04-30 22:12:07 +0100
commit70bc4aad74a38ad8124f38f41d71fbf50d064b87 (patch)
treea6d2d3ba58aa3b74346044eda84011b67fe659f3
parent9de726ec369917e942f039957e3ef512b68c646d (diff)
virtual: Introduce a base class for test cases
Introduce a base class with the intended life cycle and use it. Change-Id: I97968fb02436d5ac8248fc8020539e1af547b030
-rw-r--r--src/osmo_gsm_tester/ms_driver.py2
-rw-r--r--src/osmo_ms_driver/location_update_test.py12
-rw-r--r--src/osmo_ms_driver/test_support.py30
3 files changed, 38 insertions, 6 deletions
diff --git a/src/osmo_gsm_tester/ms_driver.py b/src/osmo_gsm_tester/ms_driver.py
index d35f02e..dddedf7 100644
--- a/src/osmo_gsm_tester/ms_driver.py
+++ b/src/osmo_gsm_tester/ms_driver.py
@@ -114,7 +114,9 @@ class MsDriver(log.Origin):
"""
if not self._configured:
self.configure()
+ self._test_case.before_start()
deadline = self._starter.start_all(self._loop, self._test_duration)
+ self._test_case.after_start()
self._test_case.wait_for_test(self._loop, deadline)
def print_stats(self):
diff --git a/src/osmo_ms_driver/location_update_test.py b/src/osmo_ms_driver/location_update_test.py
index 125ee02..1a33f09 100644
--- a/src/osmo_ms_driver/location_update_test.py
+++ b/src/osmo_ms_driver/location_update_test.py
@@ -18,6 +18,8 @@
from datetime import timedelta
+from .test_support import TestBase
+
import collections
import json
import time
@@ -53,12 +55,10 @@ def set_lu_time(result, time):
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
@@ -75,12 +75,12 @@ class MassUpdateLocationTest(log.Origin):
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 @@ class ResultStore(log.Origin):
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