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