Holger Hans Peter Freyther | 574e62f | 2018-06-20 09:15:15 +0100 | [diff] [blame] | 1 | # 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 | |
| 18 | from osmo_gsm_tester import log |
| 19 | |
| 20 | def 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 Freyther | 61f2877 | 2019-04-27 14:25:22 +0100 | [diff] [blame] | 29 | class ResultStore(log.Origin): |
Holger Hans Peter Freyther | 574e62f | 2018-06-20 09:15:15 +0100 | [diff] [blame] | 30 | """ |
Holger Hans Peter Freyther | 61f2877 | 2019-04-27 14:25:22 +0100 | [diff] [blame] | 31 | 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 Freyther | 574e62f | 2018-06-20 09:15:15 +0100 | [diff] [blame] | 33 | """ |
| 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 Freyther | 61f2877 | 2019-04-27 14:25:22 +0100 | [diff] [blame] | 39 | self._results = {} |
Holger Hans Peter Freyther | 574e62f | 2018-06-20 09:15:15 +0100 | [diff] [blame] | 40 | |
| 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 Freyther | 61f2877 | 2019-04-27 14:25:22 +0100 | [diff] [blame] | 54 | |
| 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 |