summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2019-04-30 12:01:57 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2019-04-30 22:11:35 +0100
commit9de726ec369917e942f039957e3ef512b68c646d (patch)
tree6107e7309d0a744d410948a76251ff5c69cc8a85
parent92cc0c9b69a55d37063e68945e8fff361bc11114 (diff)
virtual: Move the starter code into the starter module
There is nothing location update specific in the file. Let's move it into the starter file. Change-Id: I0cd5705eaf53a14523feacece9446331a53b3e59
-rw-r--r--src/osmo_gsm_tester/ms_driver.py4
-rw-r--r--src/osmo_ms_driver/__main__.py4
-rw-r--r--src/osmo_ms_driver/location_update_test.py160
-rw-r--r--src/osmo_ms_driver/starter.py163
4 files changed, 167 insertions, 164 deletions
diff --git a/src/osmo_gsm_tester/ms_driver.py b/src/osmo_gsm_tester/ms_driver.py
index 329662a..d35f02e 100644
--- a/src/osmo_gsm_tester/ms_driver.py
+++ b/src/osmo_gsm_tester/ms_driver.py
@@ -20,8 +20,8 @@ from . import log, util
from osmo_ms_driver.cdf import cdfs
from osmo_ms_driver.event_server import EventServer
from osmo_ms_driver.simple_loop import SimpleLoop
-from osmo_ms_driver.location_update_test import MassUpdateLocationTest, MobileTestStarter
-from osmo_ms_driver.starter import BinaryOptions
+from osmo_ms_driver.location_update_test import MassUpdateLocationTest
+from osmo_ms_driver.starter import BinaryOptions, MobileTestStarter
import os.path
import shutil
diff --git a/src/osmo_ms_driver/__main__.py b/src/osmo_ms_driver/__main__.py
index 642002f..c3da49d 100644
--- a/src/osmo_ms_driver/__main__.py
+++ b/src/osmo_ms_driver/__main__.py
@@ -18,9 +18,9 @@
# Local modules
from .event_server import EventServer
from .simple_loop import SimpleLoop
-from .location_update_test import MassUpdateLocationTest, MobileTestStarter
+from .location_update_test import MassUpdateLocationTest
from .cdf import cdfs
-from .starter import BinaryOptions
+from .starter import BinaryOptions, MobileTestStarter
from .test_support import imsi_ki_gen
from osmo_gsm_tester import log, util
from osmo_gsm_tester import ms_osmo_mobile
diff --git a/src/osmo_ms_driver/location_update_test.py b/src/osmo_ms_driver/location_update_test.py
index efb161e..125ee02 100644
--- a/src/osmo_ms_driver/location_update_test.py
+++ b/src/osmo_ms_driver/location_update_test.py
@@ -16,11 +16,6 @@
# 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 copy import copy
-from osmo_gsm_tester import log
-from .starter import OsmoVirtPhy, OsmoMobile
-from .test_support import ResultStore
-
from datetime import timedelta
import collections
@@ -137,158 +132,3 @@ class MassUpdateLocationTest(log.Origin):
res.append(result)
return res
-class MobileTestStarter(log.Origin):
- """
- A test to launch a configurable amount of MS and make them
- execute a Location Updating Procedure.
-
- Configure the number of MS to be tested and a function that
- decides how quickly to start them and a timeout.
- """
-
- TEMPLATE_LUA = "osmo-mobile.lua"
- TEMPLATE_CFG = "osmo-mobile.cfg"
-
- def __init__(self, name, options, cdf_function,
- event_server, tmp_dir, results, suite_run=None):
- super().__init__(log.C_RUN, name)
- self._binary_options = options
- self._cdf = cdf_function
- self._suite_run = suite_run
- self._tmp_dir = tmp_dir
- self._event_server = event_server
- self._results = results
- self._unstarted = []
- self._mobiles = []
- self._phys = []
-
- self._started = []
- self._subscribers = []
-
- self._event_server.register(self.handle_msg)
-
- def subscriber_add(self, subscriber):
- """
- Adds a subscriber to the list of subscribers.
-
- Must be called before starting the testcase.
- """
- self._subscribers.append(subscriber)
-
- def configure_tasks(self):
- """Sets up the test run."""
-
- self._cdf.set_target(len(self._subscribers))
- self._outstanding = len(self._subscribers)
- for i in range(0, self._outstanding):
- ms_name = "%.5d" % i
-
- phy = OsmoVirtPhy(self._binary_options.virtphy,
- self._binary_options.env,
- ms_name, self._tmp_dir)
- self._phys.append(phy)
-
- launcher = OsmoMobile(self._binary_options.mobile,
- self._binary_options.env,
- ms_name, self._tmp_dir, self.TEMPLATE_LUA,
- self.TEMPLATE_CFG, self._subscribers[i],
- phy.phy_filename(),
- self._event_server.server_path())
- self._results[ms_name] = ResultStore(ms_name)
- self._mobiles.append(launcher)
- self._unstarted = copy(self._mobiles)
-
- def pre_launch(self, loop):
- """
- We need the virtphy's be ready when the lua script in the
- mobile comes and kicks-off the test. In lua we don't seem to
- be able to just stat/check if a file/socket exists so we need
- to do this from here.
- """
- self.log("Pre-launching all virtphy's")
- for phy in self._phys:
- phy.start(loop, self._suite_run)
-
- self.log("Checking if sockets are in the filesystem")
- for phy in self._phys:
- phy.verify_ready()
-
- def prepare(self, loop):
- self.log("Starting testcase")
-
- self.configure_tasks()
- self.pre_launch(loop)
-
- self._start_time = time.clock_gettime(time.CLOCK_MONOTONIC)
- self._end_time = self._start_time + \
- self._cdf.duration().total_seconds() + \
- timedelta(seconds=120).total_seconds()
-
- self._started = []
- self._too_slow = 0
-
- def step_once(self, loop, current_time):
- if len(self._unstarted) <= 0:
- return current_time, None
-
- step_size = self._cdf.step_size().total_seconds()
-
- # Start
- self._cdf.step_once()
-
- # Check for timeout
- # start pending MS
- while len(self._started) < self._cdf.current_scaled_value() and len(self._unstarted) > 0:
- ms = self._unstarted.pop(0)
- ms.start(loop, self._suite_run)
- launch_time = time.clock_gettime(time.CLOCK_MONOTONIC)
- self._results[ms.name_number()].set_launch_time(launch_time)
- self._started.append(ms)
-
- now_time = time.clock_gettime(time.CLOCK_MONOTONIC)
- sleep_time = (current_time + step_size) - now_time
- if sleep_time <= 0:
- self.log("Starting too slowly. Moving on",
- target=(current_time + step_size), now=now_time, sleep=sleep_time)
- self._too_slow += 1
- sleep_time = 0
-
- if len(self._unstarted) == 0:
- end_time = time.clock_gettime(time.CLOCK_MONOTONIC)
- self.log("All started...", too_slow=self._too_slow, duration=end_time - self._start_time)
- return current_time, None
-
- return current_time + step_size, sleep_time
-
- def start_all(self, loop, test_duration):
- """
- Starts all processes according to the schedule set by the CDF.
- """
- self.prepare(loop)
-
- self._to_complete_time = self._start_time + test_duration.total_seconds()
- tick_time = self._start_time
-
- while len(self._unstarted) > 0:
- tick_time, sleep_time = self.step_once(loop, tick_time)
- now_time = time.clock_gettime(time.CLOCK_MONOTONIC)
- if sleep_time is None:
- sleep_time = self._to_complete_time - now_time
- if sleep_time < 0:
- break
- loop.schedule_timeout(sleep_time)
- loop.select()
- return self._to_complete_time
-
- def stop_all(self):
- for launcher in self._started:
- launcher.terminate()
-
- def handle_msg(self, _data, addr, time):
- data = json.loads(_data.decode())
-
- if data['type'] == 'register':
- ms = self._results[data['ms']]
- ms.set_start_time(time)
- launch_delay = ms.start_time() - ms.launch_time()
- self.log("MS start registered ", ms=ms, at=time, delay=launch_delay)
diff --git a/src/osmo_ms_driver/starter.py b/src/osmo_ms_driver/starter.py
index 20977d6..61d3bb0 100644
--- a/src/osmo_ms_driver/starter.py
+++ b/src/osmo_ms_driver/starter.py
@@ -18,7 +18,13 @@
from osmo_gsm_tester import log, process, template
+from .test_support import ResultStore
+
+from copy import copy
+from datetime import timedelta
+
import collections
+import json
import os
import os.path
import time
@@ -133,3 +139,160 @@ class OsmoMobile(Launcher):
"""Clean up things."""
if self._omob_proc:
self._omob_proc.terminate()
+
+
+class MobileTestStarter(log.Origin):
+ """
+ A test to launch a configurable amount of MS and make them
+ execute a Location Updating Procedure.
+
+ Configure the number of MS to be tested and a function that
+ decides how quickly to start them and a timeout.
+ """
+
+ TEMPLATE_LUA = "osmo-mobile.lua"
+ TEMPLATE_CFG = "osmo-mobile.cfg"
+
+ def __init__(self, name, options, cdf_function,
+ event_server, tmp_dir, results, suite_run=None):
+ super().__init__(log.C_RUN, name)
+ self._binary_options = options
+ self._cdf = cdf_function
+ self._suite_run = suite_run
+ self._tmp_dir = tmp_dir
+ self._event_server = event_server
+ self._results = results
+ self._unstarted = []
+ self._mobiles = []
+ self._phys = []
+
+ self._started = []
+ self._subscribers = []
+
+ self._event_server.register(self.handle_msg)
+
+ def subscriber_add(self, subscriber):
+ """
+ Adds a subscriber to the list of subscribers.
+
+ Must be called before starting the testcase.
+ """
+ self._subscribers.append(subscriber)
+
+ def configure_tasks(self):
+ """Sets up the test run."""
+
+ self._cdf.set_target(len(self._subscribers))
+ self._outstanding = len(self._subscribers)
+ for i in range(0, self._outstanding):
+ ms_name = "%.5d" % i
+
+ phy = OsmoVirtPhy(self._binary_options.virtphy,
+ self._binary_options.env,
+ ms_name, self._tmp_dir)
+ self._phys.append(phy)
+
+ launcher = OsmoMobile(self._binary_options.mobile,
+ self._binary_options.env,
+ ms_name, self._tmp_dir, self.TEMPLATE_LUA,
+ self.TEMPLATE_CFG, self._subscribers[i],
+ phy.phy_filename(),
+ self._event_server.server_path())
+ self._results[ms_name] = ResultStore(ms_name)
+ self._mobiles.append(launcher)
+ self._unstarted = copy(self._mobiles)
+
+ def pre_launch(self, loop):
+ """
+ We need the virtphy's be ready when the lua script in the
+ mobile comes and kicks-off the test. In lua we don't seem to
+ be able to just stat/check if a file/socket exists so we need
+ to do this from here.
+ """
+ self.log("Pre-launching all virtphy's")
+ for phy in self._phys:
+ phy.start(loop, self._suite_run)
+
+ self.log("Checking if sockets are in the filesystem")
+ for phy in self._phys:
+ phy.verify_ready()
+
+ def prepare(self, loop):
+ self.log("Starting testcase")
+
+ self.configure_tasks()
+ self.pre_launch(loop)
+
+ self._start_time = time.clock_gettime(time.CLOCK_MONOTONIC)
+ self._end_time = self._start_time + \
+ self._cdf.duration().total_seconds() + \
+ timedelta(seconds=120).total_seconds()
+
+ self._started = []
+ self._too_slow = 0
+
+ def step_once(self, loop, current_time):
+ if len(self._unstarted) <= 0:
+ return current_time, None
+
+ step_size = self._cdf.step_size().total_seconds()
+
+ # Start
+ self._cdf.step_once()
+
+ # Check for timeout
+ # start pending MS
+ while len(self._started) < self._cdf.current_scaled_value() and len(self._unstarted) > 0:
+ ms = self._unstarted.pop(0)
+ ms.start(loop, self._suite_run)
+ launch_time = time.clock_gettime(time.CLOCK_MONOTONIC)
+ self._results[ms.name_number()].set_launch_time(launch_time)
+ self._started.append(ms)
+
+ now_time = time.clock_gettime(time.CLOCK_MONOTONIC)
+ sleep_time = (current_time + step_size) - now_time
+ if sleep_time <= 0:
+ self.log("Starting too slowly. Moving on",
+ target=(current_time + step_size), now=now_time, sleep=sleep_time)
+ self._too_slow += 1
+ sleep_time = 0
+
+ if len(self._unstarted) == 0:
+ end_time = time.clock_gettime(time.CLOCK_MONOTONIC)
+ self.log("All started...", too_slow=self._too_slow, duration=end_time - self._start_time)
+ return current_time, None
+
+ return current_time + step_size, sleep_time
+
+ def start_all(self, loop, test_duration):
+ """
+ Starts all processes according to the schedule set by the CDF.
+ """
+ self.prepare(loop)
+
+ self._to_complete_time = self._start_time + test_duration.total_seconds()
+ tick_time = self._start_time
+
+ while len(self._unstarted) > 0:
+ tick_time, sleep_time = self.step_once(loop, tick_time)
+ now_time = time.clock_gettime(time.CLOCK_MONOTONIC)
+ if sleep_time is None:
+ sleep_time = self._to_complete_time - now_time
+ if sleep_time < 0:
+ break
+ loop.schedule_timeout(sleep_time)
+ loop.select()
+ return self._to_complete_time
+
+ def stop_all(self):
+ for launcher in self._started:
+ launcher.terminate()
+
+ def handle_msg(self, _data, addr, time):
+ data = json.loads(_data.decode())
+
+ if data['type'] == 'register':
+ ms = self._results[data['ms']]
+ ms.set_start_time(time)
+ launch_delay = ms.start_time() - ms.launch_time()
+ self.log("MS start registered ", ms=ms, at=time, delay=launch_delay)