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

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Holger Freyther gerrit-no-reply at lists.osmocom.org
Tue May 7 16:55:26 UTC 2019


Holger Freyther has submitted this change and it was merged. ( 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(+), 8 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Pau Espin Pedrol: Looks good to me, approved



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

-- 
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: merged
Gerrit-Change-Id: I97968fb02436d5ac8248fc8020539e1af547b030
Gerrit-Change-Number: 13825
Gerrit-PatchSet: 2
Gerrit-Owner: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190507/7669f98c/attachment.htm>


More information about the gerrit-log mailing list