Change in osmo-gsm-tester[master]: virtual: Have a single result class that can store data

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 Apr 30 07:20:29 UTC 2019


Holger Freyther has submitted this change and it was merged. ( https://gerrit.osmocom.org/13805 )

Change subject: virtual: Have a single result class that can store data
......................................................................

virtual: Have a single result class that can store data

We want to have LU, SMS and other tests run at the same time. Begin
by creating a single result where testcases can store additional data.

Move the stats code into the UL test case handling and out of the
suite.

Change-Id: Ie99351bee1515de8cf6870467f08256a53701907
---
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
M suites/nitb_netreg_mass/register_default_mass.py
4 files changed, 69 insertions(+), 37 deletions(-)

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



diff --git a/src/osmo_gsm_tester/ms_driver.py b/src/osmo_gsm_tester/ms_driver.py
index 96b907a..3cfcad6 100644
--- a/src/osmo_gsm_tester/ms_driver.py
+++ b/src/osmo_gsm_tester/ms_driver.py
@@ -130,6 +130,12 @@
         """
         return self._test_case.get_result_values()
 
+    def lus_less_than(self, acceptable_delay):
+        """
+        Returns the results that completed their LU within the acceptable delay.
+        """
+        return self._test_case.lus_less_than(acceptable_delay)
+
     def cleanup(self):
         """
         Cleans up the driver (e.g. AF_UNIX files).
diff --git a/src/osmo_ms_driver/location_update_test.py b/src/osmo_ms_driver/location_update_test.py
index 82c1cb3..29abf73 100644
--- a/src/osmo_ms_driver/location_update_test.py
+++ b/src/osmo_ms_driver/location_update_test.py
@@ -19,32 +19,39 @@
 from copy import copy
 from osmo_gsm_tester import log
 from .starter import OsmoVirtPhy, OsmoMobile
-from .test_support import Results
+from .test_support import ResultStore
 
 from datetime import timedelta
 
 import collections
 import time
 
-class LUResult(Results):
-    """Representation of a Location Updating Result."""
+# Key used for the result dictionary
+LU_RESULT_NAME = 'lu_time'
 
-    def __init__(self, name):
-        super().__init__(name)
-        self._time_of_lu = None
+def has_lu_time(result):
+    """
+    Returns true if a LU occurred.
+    """
+    return result.has_result(LU_RESULT_NAME)
 
-    def set_lu_time(self, time):
-        assert self._time_of_lu is None
-        self._time_of_lu = time
+def lu_time(result):
+    """
+    Returns the time of the LU occurrence.
+    """
+    return result.get_result(LU_RESULT_NAME, default=0)
 
-    def has_lu_time(self):
-        return self._time_of_lu is not None
+def lu_delay(result):
+    """
+    Returns the delay from LU success to MS start time.
+    """
+    return lu_time(result) - result.start_time()
 
-    def lu_time(self):
-        return self._time_of_lu or 0
-
-    def lu_delay(self):
-        return self.lu_time() - self.start_time()
+def set_lu_time(result, time):
+    """
+    Sets/Overrides the time of the LU success for this MS.
+    """
+    result.set_result(LU_RESULT_NAME, time)
 
 
 LUStats = collections.namedtuple("LUStats", ["num_attempted", "num_completed",
@@ -106,7 +113,7 @@
                                 self.TEMPLATE_CFG, self._subscribers[i],
                                 phy.phy_filename(),
                                 self._event_server.server_path())
-            self._results[ms_name] = LUResult(ms_name)
+            self._results[ms_name] = ResultStore(ms_name)
             self._mobiles.append(launcher)
         self._unstarted = copy(self._mobiles)
 
@@ -204,10 +211,10 @@
         elif data['type'] == 'event':
             if data['data']['lu_done'] == 1:
                 ms = self._results[data['ms']]
-                if not ms.has_lu_time():
+                if not has_lu_time(ms):
                     self._outstanding = self._outstanding - 1
-                ms.set_lu_time(time)
-                self.log("MS performed LU ", ms=ms, at=time, lu_delay=ms.lu_delay())
+                set_lu_time(ms, time)
+                self.log("MS performed LU ", ms=ms, at=time, lu_delay=lu_delay(ms))
         else:
             print(time, data)
             raise Exception("Unknown event type..:" + _data.decode())
@@ -219,10 +226,10 @@
     def find_min_max(self, results):
         min_value = max_value = None
         for result in results:
-            if min_value is None or result.lu_delay() < min_value:
-                min_value = result.lu_delay()
-            if max_value is None or result.lu_delay() > max_value:
-                max_value = result.lu_delay()
+            if min_value is None or lu_delay(result) < min_value:
+                min_value = lu_delay(result)
+            if max_value is None or lu_delay(result) > max_value:
+                max_value = lu_delay(result)
         return min_value, max_value
 
     def get_result_values(self):
@@ -237,7 +244,7 @@
         """
         attempted = len(self._subscribers)
         completed = attempted - self._outstanding
-        min_latency, max_latency = self.find_min_max(filter(lambda x: x.has_lu_time(), self._results.values()))
+        min_latency, max_latency = self.find_min_max(filter(lambda x: has_lu_time(x), self._results.values()))
         return LUStats(attempted, completed, min_latency, max_latency)
 
     def print_stats(self):
@@ -246,3 +253,16 @@
 
         self.log("Tests done", all_completed=all_completed,
                     min=stats.min_latency, max=stats.max_latency)
+
+    def lus_less_than(self, acceptable_delay):
+        """
+        Returns LUs that completed within the acceptable delay.
+        """
+        res = []
+        for result in self._results.values():
+            if not has_lu_time(result):
+                continue
+            if timedelta(seconds=lu_delay(result)) >= acceptable_delay:
+                continue
+            res.append(result)
+        return res
diff --git a/src/osmo_ms_driver/test_support.py b/src/osmo_ms_driver/test_support.py
index f1c34fb..670d795 100644
--- a/src/osmo_ms_driver/test_support.py
+++ b/src/osmo_ms_driver/test_support.py
@@ -26,15 +26,17 @@
         yield ("%.15d" % n, "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")
         n += 1
 
-class Results(log.Origin):
+class ResultStore(log.Origin):
     """
-    A base class to collect results from tests.
+    The class for results. There should be one result class per test subject.
+    Specific tests can use add_result to add their outcome to this object.
     """
 
     def __init__(self, name):
         super().__init__(log.C_RUN, name)
         self._time_of_registration = None
         self._time_of_launch = None
+        self._results = {}
 
     def set_start_time(self, time):
         assert self._time_of_registration is None
@@ -49,3 +51,15 @@
 
     def launch_time(self):
         return self._time_of_launch or 0
+
+    def set_result(self, key, value):
+        """Sets a result with the given key and value."""
+        self._results[key] = value
+
+    def get_result(self, key, default=None):
+        """Returns the result for the given key or default."""
+        return self._results.get(key, default)
+
+    def has_result(self, key):
+        """Returns true if there is a value for the key."""
+        return self._results.get(key) is not None
diff --git a/suites/nitb_netreg_mass/register_default_mass.py b/suites/nitb_netreg_mass/register_default_mass.py
index 306eb81..f4e5e80 100644
--- a/suites/nitb_netreg_mass/register_default_mass.py
+++ b/suites/nitb_netreg_mass/register_default_mass.py
@@ -46,15 +46,7 @@
 
 # Check how many results are below our threshold.
 acceptable_delay = timedelta(seconds=30)
-results = ms_driver.get_result_values()
-quick_enough = 0
-for result in results:
-    if not result.has_lu_time():
-        continue
-    if timedelta(seconds=result.lu_delay()) >= acceptable_delay:
-        continue
-    quick_enough = quick_enough + 1
-
-latency_ratio = quick_enough / len(results)
+quick_enough = len(ms_driver.lus_less_than(acceptable_delay))
+latency_ratio = quick_enough / stats.num_attempted
 if latency_ratio < 0.99:
     raise Exception("Latency ratio of %f%% lower than threshold." % (latency_ratio * 100.0))

-- 
To view, visit https://gerrit.osmocom.org/13805
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: Ie99351bee1515de8cf6870467f08256a53701907
Gerrit-Change-Number: 13805
Gerrit-PatchSet: 3
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/20190430/f4629120/attachment.htm>


More information about the gerrit-log mailing list