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 |
Andre Puschmann | 3ce6725 | 2021-01-29 17:45:18 +0100 | [diff] [blame] | 30 | self.log_kpi = None |
| 31 | self.stdout_kpi = None |
| 32 | self.csv_kpi = None |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 33 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 34 | def sleep_after_stop(self): |
| 35 | # Only sleep once |
| 36 | if self.stop_sleep_time > 0: |
| 37 | MainLoop.sleep(self.stop_sleep_time) |
| 38 | self.stop_sleep_time = 0 |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 39 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 40 | def stop(self): |
Andre Puschmann | 215bec2 | 2021-01-08 12:34:48 +0100 | [diff] [blame] | 41 | # Send q+Enter to stdin to self-terminate application |
| 42 | self.process.stdin_write('q\n') |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 43 | self.testenv.stop_process(self.process) |
| 44 | self.sleep_after_stop() |
Andre Puschmann | f14ff81 | 2020-06-19 15:47:32 +0200 | [diff] [blame] | 45 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 46 | def get_kpis(self): |
Andre Puschmann | 3ce6725 | 2021-01-29 17:45:18 +0100 | [diff] [blame] | 47 | ''' Merge all KPI and return as flat dict ''' |
| 48 | self.extract_kpis() |
| 49 | kpi_flat = {} |
| 50 | kpi_flat.update(self.log_kpi) |
| 51 | kpi_flat.update(self.stdout_kpi) |
| 52 | kpi_flat.update(self.csv_kpi) |
| 53 | return kpi_flat |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 54 | |
Andre Puschmann | 3ce6725 | 2021-01-29 17:45:18 +0100 | [diff] [blame] | 55 | def get_kpi_tree(self): |
| 56 | ''' Return all KPI as dict of dict in which the source (e.g. stdout_srsue1) is the key of the first dict ''' |
| 57 | self.extract_kpis() |
| 58 | kpi_tree = {} |
| 59 | kpi_tree["log_" + self.name()] = self.log_kpi |
| 60 | kpi_tree["csv_" + self.name()] = self.csv_kpi |
| 61 | kpi_tree["stdout_" + self.name()] = self.stdout_kpi |
| 62 | return kpi_tree |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 63 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 64 | def extract_kpis(self): |
| 65 | ''' 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] | 66 | |
Andre Puschmann | 3ce6725 | 2021-01-29 17:45:18 +0100 | [diff] [blame] | 67 | # Make sure this only runs once |
Andre Puschmann | 67ab78b | 2021-03-16 16:44:20 +0100 | [diff] [blame] | 68 | if self.csv_kpi is not None and self.log_kpi is not None and self.stdout_kpi is not None: |
Andre Puschmann | 3ce6725 | 2021-01-29 17:45:18 +0100 | [diff] [blame] | 69 | return |
| 70 | |
| 71 | # Start with empty KPIs |
| 72 | self.log_kpi = {} |
| 73 | self.stdout_kpi = {} |
| 74 | self.csv_kpi = {} |
| 75 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 76 | # Stop application, copy back logs and process them |
| 77 | if self.running(): |
| 78 | self.stop() |
| 79 | self.cleanup() |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 80 | try: |
| 81 | # Please make sure the srsLTE scripts folder is included in your PYTHONPATH env variable |
| 82 | from kpi_analyzer import kpi_analyzer |
| 83 | analyzer = kpi_analyzer(self.name()) |
| 84 | if self.log_file is not None: |
Andre Puschmann | 3ce6725 | 2021-01-29 17:45:18 +0100 | [diff] [blame] | 85 | self.log_kpi = analyzer.get_kpi_from_logfile(self.log_file) |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 86 | if self.process.get_output_file('stdout') is not None: |
Andre Puschmann | 3ce6725 | 2021-01-29 17:45:18 +0100 | [diff] [blame] | 87 | self.stdout_kpi = analyzer.get_kpi_from_stdout(self.process.get_output_file('stdout')) |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 88 | if self.metrics_file is not None: |
Andre Puschmann | 3ce6725 | 2021-01-29 17:45:18 +0100 | [diff] [blame] | 89 | self.csv_kpi = analyzer.get_kpi_from_csv(self.metrics_file) |
| 90 | # PHY errors for either UE or eNB components from parsed KPI vector as extra entry in dict |
| 91 | self.log_kpi["num_phy_errors"] = analyzer.get_num_phy_errors(self.log_kpi) |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 92 | except ImportError: |
Andre Puschmann | 3ce6725 | 2021-01-29 17:45:18 +0100 | [diff] [blame] | 93 | self.log("Can't load KPI analyzer module.") |