Change in osmo-gsm-tester[master]: virtual: Introduce a base class for test cases

Holger Freyther gerrit-no-reply at lists.osmocom.org
Tue Apr 30 21:13:54 UTC 2019


Holger Freyther has uploaded this change for review. ( https://gerrit.osmocom.org/13825


Change subject: virtual: Introduce a base class for test cases
......................................................................

virtual: Introduce a base class for test cases

Introduce a base class with the intended life cycle and use it.

Change-Id: I97968fb02436d5ac8248fc8020539e1af547b030
---
M src/osmo_gsm_tester/ms_driver.py
M src/osmo_ms_driver/location_update_test.py
M src/osmo_ms_driver/test_support.py
3 files changed, 38 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/25/13825/1

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 @@
         """
         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 @@
 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 @@
                 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

-- 
To view, visit https://gerrit.osmocom.org/13825
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I97968fb02436d5ac8248fc8020539e1af547b030
Gerrit-Change-Number: 13825
Gerrit-PatchSet: 1
Gerrit-Owner: Holger Freyther <holger at freyther.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190430/c13a4b2e/attachment-0001.html>


More information about the gerrit-log mailing list