blob: 23c93eb26db2541b0e017fc8f37e6ad4392ec40e [file] [log] [blame]
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +01001# 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
20import os
21import pprint
22import tempfile
23from . import log, config, util, template, process, event_loop
24
25class OsmoPcu(log.Origin):
26 suite_run = None
27 run_dir = None
28 inst = None
29 env = None
30
31 BIN_PCU = 'osmo-pcu'
32 PCU_OSMO_CFG = 'osmo-pcu.cfg'
33
34 def __init__(self, suite_run, bts, conf):
35 super().__init__(log.C_RUN, OsmoPcu.BIN_PCU)
36 self.suite_run = suite_run
37 self.bts = bts
38 self.conf = conf
39 self.env = {}
40
41 def start(self):
42 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
43 self.configure()
44
45 self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('osmo-pcu')))
46 lib = self.inst.child('lib')
47 if not os.path.isdir(lib):
48 raise RuntimeError('No lib/ in %r' % self.inst)
49 self.env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
50
51 self.launch_process(OsmoPcu.BIN_PCU, '-r', '1',
52 '-c', os.path.abspath(self.config_file),
53 '-i', self.bts.bsc.addr())
54 self.suite_run.poll()
55
56 def launch_process(self, binary_name, *args):
57 binary = os.path.abspath(self.inst.child('bin', binary_name))
58 run_dir = self.run_dir.new_dir(binary_name)
59 if not os.path.isfile(binary):
60 raise RuntimeError('Binary missing: %r' % binary)
61 proc = process.Process(binary_name, run_dir,
62 (binary,) + args,
63 env=self.env)
64 self.suite_run.remember_to_stop(proc)
65 proc.launch()
66 return proc
67
68 def configure(self):
69 self.config_file = self.run_dir.new_file(OsmoPcu.PCU_OSMO_CFG)
70 self.dbg(config_file=self.config_file)
71
72 values = dict(osmo_pcu=config.get_defaults('osmo_pcu'))
73 config.overlay(values, self.suite_run.config())
74 config.overlay(values, {
75 'osmo_pcu': {
76 'pcu_socket_path': self.bts.pcu_socket_path(),
77 }
78 })
79 config.overlay(values, { 'osmo_pcu': self.conf })
80
81 self.dbg('OSMO-PCU CONFIG:\n' + pprint.pformat(values))
82
83 with open(self.config_file, 'w') as f:
84 r = template.render(OsmoPcu.PCU_OSMO_CFG, values)
85 self.dbg(r)
86 f.write(r)
87
88# vim: expandtab tabstop=4 shiftwidth=4