blob: aac6901c656aafb1546cea4fe3f4276c8fa50db1 [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
Holger Hans Peter Freytherd03acdf2018-09-23 18:06:48 +010022from . import config, util, template, process, pcu
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010023
Pau Espin Pedrol150abb42018-03-08 17:27:35 +010024class OsmoPcu(pcu.Pcu):
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010025
26 BIN_PCU = 'osmo-pcu'
27 PCU_OSMO_CFG = 'osmo-pcu.cfg'
28
29 def __init__(self, suite_run, bts, conf):
Pau Espin Pedrol150abb42018-03-08 17:27:35 +010030 super().__init__(suite_run, bts, conf, OsmoPcu.BIN_PCU)
Pau Espin Pedrol58603672018-08-09 13:45:55 +020031 self.run_dir = None
32 self.inst = None
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010033 self.conf = conf
34 self.env = {}
35
Pau Espin Pedrolb1526b92018-05-22 20:32:30 +020036 def start(self, keepalive=False):
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010037 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 Pedrolb1526b92018-05-22 20:32:30 +020046 self.launch_process(keepalive, OsmoPcu.BIN_PCU, '-r', '1',
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010047 '-c', os.path.abspath(self.config_file),
48 '-i', self.bts.bsc.addr())
49 self.suite_run.poll()
50
Pau Espin Pedrolb1526b92018-05-22 20:32:30 +020051 def launch_process(self, keepalive, binary_name, *args):
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010052 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 Pedrolb1526b92018-05-22 20:32:30 +020059 self.suite_run.remember_to_stop(proc, keepalive)
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010060 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': {
Pau Espin Pedrolba213a32020-04-06 17:17:41 +020071 'bts_addr': self.bts.remote_addr(),
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010072 'pcu_socket_path': self.bts.pcu_socket_path(),
Pau Espin Pedrol29b71322020-04-06 18:14:29 +020073 'egprs_enabled': self.egprs_enabled(),
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010074 }
75 })
76 config.overlay(values, { 'osmo_pcu': self.conf })
77
78 self.dbg('OSMO-PCU CONFIG:\n' + pprint.pformat(values))
79
80 with open(self.config_file, 'w') as f:
81 r = template.render(OsmoPcu.PCU_OSMO_CFG, values)
82 self.dbg(r)
83 f.write(r)
84
85# vim: expandtab tabstop=4 shiftwidth=4