Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 1 | # osmo_gsm_tester: specifics for running an SRS UE process |
| 2 | # |
| 3 | # Copyright (C) 2020 by sysmocom - s.f.m.c. GmbH |
| 4 | # |
| 5 | # Author: Pau Espin Pedrol <pespin@sysmocom.de> |
| 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 | import os |
| 21 | import pprint |
| 22 | |
| 23 | from . import log, util, config, template, process, remote |
| 24 | from .run_node import RunNode |
Pau Espin Pedrol | 151b08a | 2020-03-02 14:14:27 +0100 | [diff] [blame] | 25 | from .event_loop import MainLoop |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 26 | from .ms import MS |
| 27 | |
Pau Espin Pedrol | a9a2fe2 | 2020-02-13 19:29:55 +0100 | [diff] [blame] | 28 | def rf_type_valid(rf_type_str): |
| 29 | return rf_type_str in ('zmq', 'UHD', 'soapy', 'bladeRF') |
| 30 | |
Pau Espin Pedrol | 2aeadeb | 2020-03-02 11:50:23 +0100 | [diff] [blame] | 31 | #reference: srsLTE.git srslte_symbol_sz() |
| 32 | def num_prb2symbol_sz(num_prb): |
| 33 | if num_prb <= 6: |
| 34 | return 128 |
| 35 | if num_prb <= 15: |
| 36 | return 256 |
| 37 | if num_prb <= 25: |
| 38 | return 384 |
| 39 | if num_prb <= 50: |
| 40 | return 768 |
| 41 | if num_prb <= 75: |
| 42 | return 1024 |
| 43 | if num_prb <= 110: |
| 44 | return 1536 |
| 45 | raise log.Error('invalid num_prb %r', num_prb) |
| 46 | |
| 47 | def num_prb2base_srate(num_prb): |
| 48 | return num_prb2symbol_sz(num_prb) * 15 * 1000 |
| 49 | |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 50 | class srsUE(MS): |
| 51 | |
| 52 | REMOTE_DIR = '/osmo-gsm-tester-srsue' |
| 53 | BINFILE = 'srsue' |
| 54 | CFGFILE = 'srsue.conf' |
| 55 | PCAPFILE = 'srsue.pcap' |
| 56 | LOGFILE = 'srsue.log' |
Pau Espin Pedrol | a031995 | 2020-03-02 11:06:51 +0100 | [diff] [blame] | 57 | METRICSFILE = 'srsue_metrics.csv' |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 58 | |
| 59 | def __init__(self, suite_run, conf): |
| 60 | self._addr = conf.get('addr', None) |
| 61 | if self._addr is None: |
| 62 | raise log.Error('addr not set') |
| 63 | super().__init__('srsue_%s' % self._addr, conf) |
| 64 | self.enb = None |
| 65 | self.run_dir = None |
| 66 | self.config_file = None |
| 67 | self.log_file = None |
| 68 | self.pcap_file = None |
Pau Espin Pedrol | a031995 | 2020-03-02 11:06:51 +0100 | [diff] [blame] | 69 | self.metrics_file = None |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 70 | self.process = None |
| 71 | self.rem_host = None |
| 72 | self.remote_config_file = None |
| 73 | self.remote_log_file = None |
| 74 | self.remote_pcap_file = None |
Pau Espin Pedrol | a031995 | 2020-03-02 11:06:51 +0100 | [diff] [blame] | 75 | self.remote_metrics_file = None |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 76 | self.enable_pcap = False |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 77 | self.suite_run = suite_run |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 78 | self.remote_user = conf.get('remote_user', None) |
Pau Espin Pedrol | a9a2fe2 | 2020-02-13 19:29:55 +0100 | [diff] [blame] | 79 | if not rf_type_valid(conf.get('rf_dev_type', None)): |
| 80 | raise log.Error('Invalid rf_dev_type=%s' % conf.get('rf_dev_type', None)) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 81 | |
| 82 | def cleanup(self): |
| 83 | if self.process is None: |
| 84 | return |
| 85 | if self.setup_runs_locally(): |
| 86 | return |
Pau Espin Pedrol | 5b31cc3 | 2020-03-09 16:34:45 +0100 | [diff] [blame] | 87 | # When using zmq, srsUE is known to hang for a few seconds before |
| 88 | # exiting (3 seconds after alarm() watchdog kicks in). We hence need to |
| 89 | # wait to make sure the remote process terminated and the file was |
| 90 | # flushed, since cleanup() triggered means only the local ssh client was killed. |
| 91 | if self._conf and self._conf.get('rf_dev_type', '') == 'zmq': |
| 92 | MainLoop.sleep(self, 3) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 93 | # copy back files (may not exist, for instance if there was an early error of process): |
| 94 | try: |
| 95 | self.rem_host.scpfrom('scp-back-log', self.remote_log_file, self.log_file) |
| 96 | except Exception as e: |
| 97 | self.log(repr(e)) |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 98 | if self.enable_pcap: |
| 99 | try: |
| 100 | self.rem_host.scpfrom('scp-back-pcap', self.remote_pcap_file, self.pcap_file) |
| 101 | except Exception as e: |
| 102 | self.log(repr(e)) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 103 | |
| 104 | def setup_runs_locally(self): |
| 105 | return self.remote_user is None |
| 106 | |
| 107 | def netns(self): |
| 108 | return "srsue1" |
| 109 | |
Pau Espin Pedrol | 151b08a | 2020-03-02 14:14:27 +0100 | [diff] [blame] | 110 | def stop(self): |
| 111 | self.suite_run.stop_process(self.process) |
| 112 | |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 113 | def connect(self, enb): |
| 114 | self.log('Starting srsue') |
| 115 | self.enb = enb |
| 116 | self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name())) |
| 117 | self.configure() |
| 118 | if self.setup_runs_locally(): |
| 119 | self.start_locally() |
| 120 | else: |
| 121 | self.start_remotely() |
| 122 | |
Andre Puschmann | 2e8626f | 2020-03-21 21:18:39 +0100 | [diff] [blame] | 123 | # send t+Enter to enable console trace |
| 124 | self.dbg('Enabling console trace') |
| 125 | self.process.stdin_write('t\n') |
| 126 | |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 127 | def start_remotely(self): |
| 128 | self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('srslte'))) |
| 129 | lib = self.inst.child('lib') |
| 130 | if not os.path.isdir(lib): |
| 131 | raise log.Error('No lib/ in', self.inst) |
| 132 | if not self.inst.isfile('bin', srsUE.BINFILE): |
| 133 | raise log.Error('No %s binary in' % srsUE.BINFILE, self.inst) |
| 134 | |
| 135 | self.rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self._addr) |
| 136 | remote_prefix_dir = util.Dir(srsUE.REMOTE_DIR) |
| 137 | remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst)))) |
| 138 | remote_run_dir = util.Dir(remote_prefix_dir.child(srsUE.BINFILE)) |
| 139 | self.remote_config_file = remote_run_dir.child(srsUE.CFGFILE) |
| 140 | self.remote_log_file = remote_run_dir.child(srsUE.LOGFILE) |
| 141 | self.remote_pcap_file = remote_run_dir.child(srsUE.PCAPFILE) |
Pau Espin Pedrol | a031995 | 2020-03-02 11:06:51 +0100 | [diff] [blame] | 142 | self.remote_metrics_file = remote_run_dir.child(srsUE.METRICSFILE) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 143 | |
| 144 | self.rem_host.recreate_remote_dir(remote_inst) |
| 145 | self.rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir) |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 146 | self.rem_host.recreate_remote_dir(remote_run_dir) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 147 | self.rem_host.scp('scp-cfg-to-remote', self.config_file, self.remote_config_file) |
| 148 | |
| 149 | remote_lib = remote_inst.child('lib') |
| 150 | remote_binary = remote_inst.child('bin', srsUE.BINFILE) |
| 151 | # setting capabilities will later disable use of LD_LIBRARY_PATH from ELF loader -> modify RPATH instead. |
| 152 | self.log('Setting RPATH for srsue') |
| 153 | # srsue binary needs patchelf >= 0.9+52 to avoid failing during patch. OS#4389, patchelf-GH#192. |
| 154 | self.rem_host.set_remote_env({'PATCHELF_BIN': '/opt/bin/patchelf-v0.10' }) |
| 155 | self.rem_host.change_elf_rpath(remote_binary, remote_lib) |
| 156 | |
| 157 | # srsue requires CAP_SYS_ADMIN to cjump to net network namespace: netns(CLONE_NEWNET): |
| 158 | # srsue requires CAP_NET_ADMIN to create tunnel devices: ioctl(TUNSETIFF): |
| 159 | self.log('Applying CAP_SYS_ADMIN+CAP_NET_ADMIN capability to srsue') |
| 160 | self.rem_host.setcap_netsys_admin(remote_binary) |
| 161 | |
Pau Espin Pedrol | 69b2cf3 | 2020-02-24 10:58:59 +0100 | [diff] [blame] | 162 | self.log('Creating netns %s' % self.netns()) |
| 163 | self.rem_host.create_netns(self.netns()) |
| 164 | |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 165 | #'strace', '-ff', |
| 166 | args = (remote_binary, self.remote_config_file, |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 167 | '--gw.netns=' + self.netns(), |
Pau Espin Pedrol | 5b31cc3 | 2020-03-09 16:34:45 +0100 | [diff] [blame] | 168 | '--log.filename=' + self.remote_log_file, |
Pau Espin Pedrol | a031995 | 2020-03-02 11:06:51 +0100 | [diff] [blame] | 169 | '--pcap.filename=' + self.remote_pcap_file, |
| 170 | '--general.metrics_csv_filename=' + self.remote_metrics_file) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 171 | |
Andre Puschmann | cfdcf89 | 2020-03-21 21:21:55 +0100 | [diff] [blame] | 172 | self.process = self.rem_host.RemoteProcess(srsUE.BINFILE, args) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 173 | #self.process = self.rem_host.RemoteProcessFixIgnoreSIGHUP(srsUE.BINFILE, remote_run_dir, args, remote_lib) |
| 174 | self.suite_run.remember_to_stop(self.process) |
| 175 | self.process.launch() |
| 176 | |
| 177 | def start_locally(self): |
| 178 | inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('srslte'))) |
| 179 | |
Pau Espin Pedrol | 9aa932f | 2020-03-31 11:46:04 +0200 | [diff] [blame] | 180 | binary = inst.child('bin', srsUE.BINFILE) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 181 | if not os.path.isfile(binary): |
| 182 | raise log.Error('Binary missing:', binary) |
| 183 | lib = inst.child('lib') |
| 184 | if not os.path.isdir(lib): |
| 185 | raise log.Error('No lib/ in', inst) |
| 186 | |
| 187 | env = {} |
| 188 | |
| 189 | # setting capabilities will later disable use of LD_LIBRARY_PATH from ELF loader -> modify RPATH instead. |
| 190 | self.log('Setting RPATH for srsue') |
| 191 | util.change_elf_rpath(binary, util.prepend_library_path(lib), self.run_dir.new_dir('patchelf')) |
| 192 | |
| 193 | # srsue requires CAP_SYS_ADMIN to cjump to net network namespace: netns(CLONE_NEWNET): |
| 194 | # srsue requires CAP_NET_ADMIN to create tunnel devices: ioctl(TUNSETIFF): |
| 195 | self.log('Applying CAP_SYS_ADMIN+CAP_NET_ADMIN capability to srsue') |
| 196 | util.setcap_netsys_admin(binary, self.run_dir.new_dir('setcap_netsys_admin')) |
| 197 | |
Pau Espin Pedrol | 69b2cf3 | 2020-02-24 10:58:59 +0100 | [diff] [blame] | 198 | self.log('Creating netns %s' % self.netns()) |
| 199 | util.create_netns(self.netns(), self.run_dir.new_dir('create_netns')) |
| 200 | |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 201 | args = (binary, os.path.abspath(self.config_file), |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 202 | '--gw.netns=' + self.netns(), |
| 203 | '--log.filename=' + self.log_file, |
Pau Espin Pedrol | a031995 | 2020-03-02 11:06:51 +0100 | [diff] [blame] | 204 | '--pcap.filename=' + self.pcap_file, |
| 205 | '--general.metrics_csv_filename=' + self.metrics_file) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 206 | |
| 207 | self.dbg(run_dir=self.run_dir, binary=binary, env=env) |
| 208 | self.process = process.Process(self.name(), self.run_dir, args, env=env) |
| 209 | self.suite_run.remember_to_stop(self.process) |
| 210 | self.process.launch() |
| 211 | |
| 212 | def configure(self): |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 213 | self.config_file = self.run_dir.child(srsUE.CFGFILE) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 214 | self.log_file = self.run_dir.child(srsUE.LOGFILE) |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 215 | self.pcap_file = self.run_dir.child(srsUE.PCAPFILE) |
Pau Espin Pedrol | a031995 | 2020-03-02 11:06:51 +0100 | [diff] [blame] | 216 | self.metrics_file = self.run_dir.child(srsUE.METRICSFILE) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 217 | self.dbg(config_file=self.config_file) |
| 218 | |
| 219 | values = dict(ue=config.get_defaults('srsue')) |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 220 | config.overlay(values, dict(ue=self.suite_run.config().get('modem', {}))) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 221 | config.overlay(values, dict(ue=self._conf)) |
Pau Espin Pedrol | f796ad0 | 2020-03-09 15:50:57 +0100 | [diff] [blame] | 222 | config.overlay(values, dict(ue=dict(num_antennas = self.enb.num_ports()))) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 223 | |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 224 | # Convert parsed boolean string to Python boolean: |
| 225 | self.enable_pcap = util.str2bool(values['ue'].get('enable_pcap', 'false')) |
| 226 | config.overlay(values, dict(ue={'enable_pcap': self.enable_pcap})) |
| 227 | |
Pau Espin Pedrol | a9a2fe2 | 2020-02-13 19:29:55 +0100 | [diff] [blame] | 228 | # We need to set some specific variables programatically here to match IP addresses: |
| 229 | if self._conf.get('rf_dev_type') == 'zmq': |
Pau Espin Pedrol | 2aeadeb | 2020-03-02 11:50:23 +0100 | [diff] [blame] | 230 | base_srate = num_prb2base_srate(self.enb.num_prb()) |
Pau Espin Pedrol | f796ad0 | 2020-03-09 15:50:57 +0100 | [diff] [blame] | 231 | config.overlay(values, dict(ue=dict(rf_dev_args = 'tx_port=tcp://' + self.addr() + ':2001' \ |
| 232 | + ',tx_port2=tcp://' + self.addr() + ':2003' \ |
| 233 | + ',rx_port=tcp://' + self.enb.addr() + ':2000' \ |
| 234 | + ',rx_port2=tcp://' + self.enb.addr() + ':2002' \ |
Andre Puschmann | 3ffea80 | 2020-03-24 12:09:25 +0100 | [diff] [blame] | 235 | + ',tx_freq=2510e6,rx_freq=2630e6,tx_freq2=2530e6,rx_freq2=2650e6' \ |
Pau Espin Pedrol | f796ad0 | 2020-03-09 15:50:57 +0100 | [diff] [blame] | 236 | + ',id=ue,base_srate='+ str(base_srate) |
Pau Espin Pedrol | 2aeadeb | 2020-03-02 11:50:23 +0100 | [diff] [blame] | 237 | ))) |
Pau Espin Pedrol | a9a2fe2 | 2020-02-13 19:29:55 +0100 | [diff] [blame] | 238 | |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 239 | self.dbg('SRSUE CONFIG:\n' + pprint.pformat(values)) |
| 240 | |
| 241 | with open(self.config_file, 'w') as f: |
| 242 | r = template.render(srsUE.CFGFILE, values) |
| 243 | self.dbg(r) |
| 244 | f.write(r) |
| 245 | |
| 246 | def is_connected(self, mcc_mnc=None): |
| 247 | return 'Network attach successful.' in (self.process.get_stdout() or '') |
| 248 | |
| 249 | def is_attached(self): |
| 250 | return self.is_connected() |
| 251 | |
| 252 | def running(self): |
| 253 | return not self.process.terminated() |
| 254 | |
| 255 | def addr(self): |
| 256 | return self._addr |
| 257 | |
| 258 | def run_node(self): |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 259 | return RunNode(RunNode.T_REM_SSH, self._addr, self.remote_user, self._addr) |
| 260 | |
| 261 | def run_netns_wait(self, name, popen_args): |
| 262 | if self.setup_runs_locally(): |
| 263 | proc = process.NetNSProcess(name, self.run_dir.new_dir(name), self.netns(), popen_args, env={}) |
| 264 | else: |
| 265 | proc = self.rem_host.RemoteNetNSProcess(name, self.netns(), popen_args, env={}) |
| 266 | proc.launch_sync() |
Pau Espin Pedrol | 2bcd346 | 2020-03-05 18:30:37 +0100 | [diff] [blame] | 267 | return proc |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 268 | |
Pau Espin Pedrol | 151b08a | 2020-03-02 14:14:27 +0100 | [diff] [blame] | 269 | def verify_metric(self, value, operation='avg', metric='dl_brate', criterion='gt'): |
| 270 | # file is not properly flushed until the process has stopped. |
| 271 | if self.running(): |
| 272 | self.stop() |
| 273 | # metrics file is not flushed immediatelly by the OS during process |
| 274 | # tear down, we need to wait some extra time: |
| 275 | MainLoop.sleep(self, 2) |
| 276 | if not self.setup_runs_locally(): |
| 277 | try: |
| 278 | self.rem_host.scpfrom('scp-back-metrics', self.remote_metrics_file, self.metrics_file) |
| 279 | except Exception as e: |
| 280 | self.err('Failed copying back metrics file from remote host') |
| 281 | raise e |
| 282 | metrics = srsUEMetrics(self.metrics_file) |
| 283 | return metrics.verify(value, operation, metric, criterion) |
| 284 | |
| 285 | import numpy |
| 286 | |
| 287 | class srsUEMetrics(log.Origin): |
| 288 | |
| 289 | VALID_OPERATIONS = ['avg', 'sum'] |
| 290 | VALID_CRITERION = ['eq','gt','lt'] |
| 291 | CRITERION_TO_SYM = { 'eq' : '==', 'gt' : '>', 'lt' : '<' } |
| 292 | CRYTERION_TO_SYM_OPPOSITE = { 'eq' : '!=', 'gt' : '<=', 'lt' : '>=' } |
| 293 | |
| 294 | |
| 295 | def __init__(self, metrics_file): |
| 296 | super().__init__(log.C_RUN, 'srsue_metrics') |
| 297 | self.raw_data = None |
| 298 | self.metrics_file = metrics_file |
| 299 | # read CSV, guessing data type with first row being the legend |
| 300 | try: |
| 301 | self.raw_data = numpy.genfromtxt(self.metrics_file, names=True, delimiter=';', dtype=None) |
| 302 | except (ValueError, IndexError, IOError) as error: |
| 303 | self.err("Error parsing metrics CSV file %s" % self.metrics_file) |
| 304 | raise error |
| 305 | |
| 306 | def verify(self, value, operation='avg', metric='dl_brate', criterion='gt'): |
| 307 | if operation not in self.VALID_OPERATIONS: |
| 308 | raise log.Error('Unknown operation %s not in %r' % (operation, self.VALID_OPERATIONS)) |
| 309 | if criterion not in self.VALID_CRITERION: |
| 310 | raise log.Error('Unknown operation %s not in %r' % (operation, self.VALID_CRITERION)) |
| 311 | # check if given metric exists in data |
| 312 | try: |
| 313 | sel_data = self.raw_data[metric] |
| 314 | except ValueError as err: |
| 315 | print('metric %s not available' % metric) |
| 316 | raise err |
| 317 | |
| 318 | if operation == 'avg': |
| 319 | result = numpy.average(sel_data) |
| 320 | elif operation == 'sum': |
| 321 | result = numpy.sum(sel_data) |
| 322 | self.dbg(result=result, value=value) |
| 323 | |
| 324 | success = False |
| 325 | if criterion == 'eq' and result == value or \ |
| 326 | criterion == 'gt' and result > value or \ |
| 327 | criterion == 'lt' and result < value: |
| 328 | success = True |
| 329 | |
| 330 | # Convert bitrate in Mbit/s: |
| 331 | if metric.find('brate') > 0: |
| 332 | result /= 1e6 |
| 333 | value /= 1e6 |
| 334 | mbit_str = ' Mbit/s' |
| 335 | else: |
| 336 | mbit_str = '' |
| 337 | |
| 338 | if not success: |
| 339 | result_msg = "{:.2f}{} {} {:.2f}{}".format(result, mbit_str, self.CRYTERION_TO_SYM_OPPOSITE[criterion], value, mbit_str) |
| 340 | raise log.Error(result_msg) |
| 341 | result_msg = "{:.2f}{} {} {:.2f}{}".format(result, mbit_str, self.CRITERION_TO_SYM[criterion], value, mbit_str) |
| 342 | # TODO: overwrite test system-out with this text. |
| 343 | return result_msg |
| 344 | |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 345 | # vim: expandtab tabstop=4 shiftwidth=4 |