Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 1 | # osmo_gsm_tester: specifics for running an osmo-pcu |
| 2 | # |
| 3 | # Copyright (C) 2016-2017 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 |
Holger Hans Peter Freyther | d03acdf | 2018-09-23 18:06:48 +0100 | [diff] [blame] | 22 | from . import config, util, template, process, pcu |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 23 | |
Pau Espin Pedrol | 150abb4 | 2018-03-08 17:27:35 +0100 | [diff] [blame] | 24 | class OsmoPcu(pcu.Pcu): |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 25 | |
| 26 | BIN_PCU = 'osmo-pcu' |
| 27 | PCU_OSMO_CFG = 'osmo-pcu.cfg' |
| 28 | |
| 29 | def __init__(self, suite_run, bts, conf): |
Pau Espin Pedrol | 150abb4 | 2018-03-08 17:27:35 +0100 | [diff] [blame] | 30 | super().__init__(suite_run, bts, conf, OsmoPcu.BIN_PCU) |
Pau Espin Pedrol | 5860367 | 2018-08-09 13:45:55 +0200 | [diff] [blame] | 31 | self.run_dir = None |
| 32 | self.inst = None |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 33 | self.conf = conf |
| 34 | self.env = {} |
| 35 | |
Pau Espin Pedrol | b1526b9 | 2018-05-22 20:32:30 +0200 | [diff] [blame] | 36 | def start(self, keepalive=False): |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 37 | self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name())) |
| 38 | self.configure() |
| 39 | |
| 40 | self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('osmo-pcu'))) |
| 41 | lib = self.inst.child('lib') |
| 42 | if not os.path.isdir(lib): |
| 43 | raise RuntimeError('No lib/ in %r' % self.inst) |
| 44 | self.env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) } |
| 45 | |
Pau Espin Pedrol | b1526b9 | 2018-05-22 20:32:30 +0200 | [diff] [blame] | 46 | self.launch_process(keepalive, OsmoPcu.BIN_PCU, '-r', '1', |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 47 | '-c', os.path.abspath(self.config_file), |
| 48 | '-i', self.bts.bsc.addr()) |
| 49 | self.suite_run.poll() |
| 50 | |
Pau Espin Pedrol | b1526b9 | 2018-05-22 20:32:30 +0200 | [diff] [blame] | 51 | def launch_process(self, keepalive, binary_name, *args): |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 52 | binary = os.path.abspath(self.inst.child('bin', binary_name)) |
| 53 | run_dir = self.run_dir.new_dir(binary_name) |
| 54 | if not os.path.isfile(binary): |
| 55 | raise RuntimeError('Binary missing: %r' % binary) |
| 56 | proc = process.Process(binary_name, run_dir, |
| 57 | (binary,) + args, |
| 58 | env=self.env) |
Pau Espin Pedrol | b1526b9 | 2018-05-22 20:32:30 +0200 | [diff] [blame] | 59 | self.suite_run.remember_to_stop(proc, keepalive) |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 60 | proc.launch() |
| 61 | return proc |
| 62 | |
| 63 | def configure(self): |
| 64 | self.config_file = self.run_dir.new_file(OsmoPcu.PCU_OSMO_CFG) |
| 65 | self.dbg(config_file=self.config_file) |
| 66 | |
| 67 | values = dict(osmo_pcu=config.get_defaults('osmo_pcu')) |
| 68 | config.overlay(values, self.suite_run.config()) |
| 69 | config.overlay(values, { |
| 70 | 'osmo_pcu': { |
| 71 | 'pcu_socket_path': self.bts.pcu_socket_path(), |
| 72 | } |
| 73 | }) |
| 74 | config.overlay(values, { 'osmo_pcu': self.conf }) |
| 75 | |
| 76 | self.dbg('OSMO-PCU CONFIG:\n' + pprint.pformat(values)) |
| 77 | |
| 78 | with open(self.config_file, 'w') as f: |
| 79 | r = template.render(OsmoPcu.PCU_OSMO_CFG, values) |
| 80 | self.dbg(r) |
| 81 | f.write(r) |
| 82 | |
| 83 | # vim: expandtab tabstop=4 shiftwidth=4 |