blob: 670d7957449bc9ff7f9aa8a2b6f1e6314359850a [file] [log] [blame]
Holger Hans Peter Freyther574e62f2018-06-20 09:15:15 +01001# osmo_ms_driver: Test helpers and base classes
2#
3# Copyright (C) 2018 by Holger Hans Peter Freyther
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as
7# published by the Free Software Foundation, either version 3 of the
8# License, or (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18from osmo_gsm_tester import log
19
20def imsi_ki_gen():
21 """
22 Generate IMSIs and KIs to be used by test.
23 """
24 n = 1010000000000
25 while True:
26 yield ("%.15d" % n, "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")
27 n += 1
28
Holger Hans Peter Freyther61f28772019-04-27 14:25:22 +010029class ResultStore(log.Origin):
Holger Hans Peter Freyther574e62f2018-06-20 09:15:15 +010030 """
Holger Hans Peter Freyther61f28772019-04-27 14:25:22 +010031 The class for results. There should be one result class per test subject.
32 Specific tests can use add_result to add their outcome to this object.
Holger Hans Peter Freyther574e62f2018-06-20 09:15:15 +010033 """
34
35 def __init__(self, name):
36 super().__init__(log.C_RUN, name)
37 self._time_of_registration = None
38 self._time_of_launch = None
Holger Hans Peter Freyther61f28772019-04-27 14:25:22 +010039 self._results = {}
Holger Hans Peter Freyther574e62f2018-06-20 09:15:15 +010040
41 def set_start_time(self, time):
42 assert self._time_of_registration is None
43 self._time_of_registration = time
44
45 def set_launch_time(self, time):
46 assert self._time_of_launch is None
47 self._time_of_launch = time
48
49 def start_time(self):
50 return self._time_of_registration or 0
51
52 def launch_time(self):
53 return self._time_of_launch or 0
Holger Hans Peter Freyther61f28772019-04-27 14:25:22 +010054
55 def set_result(self, key, value):
56 """Sets a result with the given key and value."""
57 self._results[key] = value
58
59 def get_result(self, key, default=None):
60 """Returns the result for the given key or default."""
61 return self._results.get(key, default)
62
63 def has_result(self, key):
64 """Returns true if there is a value for the key."""
65 return self._results.get(key) is not None