summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2019-04-27 14:25:22 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2019-04-28 15:53:24 +0100
commit61f28773bfb47b13f74d584ed6f03c8fd79e5a0b (patch)
treeefcddc18ed92fa153e10587f7c782ee77d77e7e6
parente524f2ca594a31c0cacabb4dde78dd5d9145ed0a (diff)
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
-rw-r--r--src/osmo_gsm_tester/ms_driver.py6
-rw-r--r--src/osmo_ms_driver/location_update_test.py70
-rw-r--r--src/osmo_ms_driver/test_support.py18
-rw-r--r--suites/nitb_netreg_mass/register_default_mass.py12
4 files changed, 69 insertions, 37 deletions
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 @@ class MsDriver(log.Origin):
"""
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 set_lu_time(self, time):
- assert self._time_of_lu is None
- self._time_of_lu = time
+def has_lu_time(result):
+ """
+ Returns true if a LU occurred.
+ """
+ return result.has_result(LU_RESULT_NAME)
- def has_lu_time(self):
- return self._time_of_lu is not None
+def lu_time(result):
+ """
+ Returns the time of the LU occurrence.
+ """
+ return result.get_result(LU_RESULT_NAME, default=0)
- def lu_time(self):
- return self._time_of_lu or 0
+def lu_delay(result):
+ """
+ Returns the delay from LU success to MS start time.
+ """
+ return lu_time(result) - result.start_time()
- 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 @@ class MassUpdateLocationTest(log.Origin):
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 @@ class MassUpdateLocationTest(log.Origin):
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 @@ class MassUpdateLocationTest(log.Origin):
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 @@ class MassUpdateLocationTest(log.Origin):
"""
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 @@ class MassUpdateLocationTest(log.Origin):
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 @@ def imsi_ki_gen():
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 @@ class Results(log.Origin):
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 @@ if completion_ratio < 0.99:
# 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))