Andre Puschmann | f14ff81 | 2020-06-19 15:47:32 +0200 | [diff] [blame] | 1 | # osmo_gsm_tester: common methods shared among srsLTE components |
| 2 | # |
| 3 | # Copyright (C) 2020 by Software Radio Systems Ltd |
| 4 | # |
| 5 | # Author: Andre Puschmann <andre@softwareradiosystems.com> |
| 6 | # |
| 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as |
| 9 | # published by the Free Software Foundation, either version 3 of the |
| 10 | # License, or (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | from ..core import log |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 21 | from ..core.event_loop import MainLoop |
Andre Puschmann | f14ff81 | 2020-06-19 15:47:32 +0200 | [diff] [blame] | 22 | |
| 23 | class srslte_common(): # don't inherit from log.Origin here but instead use .name() from whoever inherits from us |
| 24 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 25 | def __init__(self): |
| 26 | self.log_file = None |
| 27 | self.process = None |
| 28 | self.metrics_file = None |
| 29 | self.stop_sleep_time = 6 # We require at most 5s to stop |
| 30 | self.kpis = None |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 31 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 32 | def sleep_after_stop(self): |
| 33 | # Only sleep once |
| 34 | if self.stop_sleep_time > 0: |
| 35 | MainLoop.sleep(self.stop_sleep_time) |
| 36 | self.stop_sleep_time = 0 |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 37 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 38 | def stop(self): |
Andre Puschmann | 215bec2 | 2021-01-08 12:34:48 +0100 | [diff] [blame^] | 39 | # Send q+Enter to stdin to self-terminate application |
| 40 | self.process.stdin_write('q\n') |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 41 | self.testenv.stop_process(self.process) |
| 42 | self.sleep_after_stop() |
Andre Puschmann | f14ff81 | 2020-06-19 15:47:32 +0200 | [diff] [blame] | 43 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 44 | def get_kpis(self): |
| 45 | ''' Return all KPI ''' |
| 46 | if self.kpis is None: |
| 47 | self.extract_kpis() |
| 48 | return self.kpis |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 49 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 50 | def get_log_kpis(self): |
| 51 | ''' Return KPIs extracted from log ''' |
| 52 | if self.kpis is None: |
| 53 | self.extract_kpis() |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 54 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 55 | # Use log KPIs if they exist for this node |
| 56 | if "log_" + self.name() in self.kpis: |
| 57 | log_kpi = self.kpis["log_" + self.name()] |
| 58 | else: |
| 59 | log_kpi = {} |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 60 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 61 | # Make sure we have the errors and warnings counter in the dict |
| 62 | if 'total_errors' not in log_kpi: |
| 63 | log_kpi['total_errors'] = 0 |
| 64 | if 'total_warnings' not in log_kpi: |
| 65 | log_kpi['total_warnings'] = 0 |
| 66 | return log_kpi |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 67 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 68 | def extract_kpis(self): |
| 69 | ''' Use the srsLTE KPI analyzer module (part of srsLTE.git) if available to collect KPIs ''' |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 70 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 71 | # Stop application, copy back logs and process them |
| 72 | if self.running(): |
| 73 | self.stop() |
| 74 | self.cleanup() |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 75 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 76 | self.kpis = {} |
| 77 | try: |
| 78 | # Please make sure the srsLTE scripts folder is included in your PYTHONPATH env variable |
| 79 | from kpi_analyzer import kpi_analyzer |
| 80 | analyzer = kpi_analyzer(self.name()) |
| 81 | if self.log_file is not None: |
| 82 | self.kpis["log_" + self.name()] = analyzer.get_kpi_from_logfile(self.log_file) |
| 83 | if self.process.get_output_file('stdout') is not None: |
| 84 | self.kpis["stdout_" + self.name()] = analyzer.get_kpi_from_stdout(self.process.get_output_file('stdout')) |
| 85 | if self.metrics_file is not None: |
| 86 | self.kpis["csv_" + self.name()] = analyzer.get_kpi_from_csv(self.metrics_file) |
| 87 | except ImportError: |
| 88 | self.log("Can't load KPI analyzer module.") |
| 89 | self.kpis = {} |
Andre Puschmann | f14ff81 | 2020-06-19 15:47:32 +0200 | [diff] [blame] | 90 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 91 | return self.kpis |
Andre Puschmann | f4fb48a | 2020-10-05 15:24:17 +0200 | [diff] [blame] | 92 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 93 | def get_num_phy_errors(self, kpi): |
| 94 | """ Use KPI analyzer to calculate the number PHY errors for either UE or eNB components from parsed KPI vector """ |
| 95 | try: |
| 96 | # Same as above, make sure the srsLTE scripts folder is included in your PYTHONPATH env variable |
| 97 | from kpi_analyzer import kpi_analyzer |
| 98 | analyzer = kpi_analyzer(self.name()) |
| 99 | return analyzer.get_num_phy_errors(kpi) |
| 100 | except ImportError: |
| 101 | self.log("Can't load KPI analyzer module.") |
Andre Puschmann | f249a02 | 2021-01-05 14:14:48 +0100 | [diff] [blame] | 102 | return 0 |