blob: 5b1e14587fb058db9dd8d6466831f7e30159d394 [file] [log] [blame]
Pau Espin Pedrolbc1ed882018-05-17 16:59:58 +02001# osmo_gsm_tester: specifics for running an osmocon
2#
3# Copyright (C) 2018 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 tempfile
22
23from . import log, util, process
24from .event_loop import MainLoop
25
26class Osmocon(log.Origin):
27 suite_run = None
28 run_dir = None
29 process = None
30 sk_tmp_dir = None
31
32 FIRMWARE_FILE="opt/osmocom-bb/target/firmware/board/compal_e88/layer1.compalram.bin"
33
34 def __init__(self, suite_run, conf):
35 serial_device = conf.get('serial_device')
36 if serial_device is None:
37 raise log.Error('osmocon_phone contains no attr "serial_device"')
38 self.serial_device = os.path.realpath(serial_device)
39 super().__init__(log.C_RUN, 'osmocon_%s' % os.path.basename(self.serial_device))
40 self.suite_run = suite_run
41 self.conf = conf
42 self.sk_tmp_dir = tempfile.mkdtemp('', 'ogtosmoconsk')
43 if len(self.l2_socket_path().encode()) > 107:
44 raise log.Error('Path for l2 socket is longer than max allowed len for unix socket path (107):', self.l2_socket_path())
45 if len(self.loader_socket_path().encode()) > 107:
46 raise log.Error('Path for loader socket is longer than max allowed len for unix socket path (107):', self.loader_socket_path())
47
48 def l2_socket_path(self):
49 return os.path.join(self.sk_tmp_dir, 'osmocom_l2')
50
51 def loader_socket_path(self):
52 return os.path.join(self.sk_tmp_dir, 'osmocom_loader')
53
54 def start(self):
55 self.log('Resetting the phone')
56 # TODO: make sure the pone is powered off before starting osmocon
57
58 self.log('Starting osmocon')
59 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
60
61 inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('osmocom-bb')))
62
63 binary = inst.child('sbin', 'osmocon')
64 if not os.path.isfile(binary):
65 raise RuntimeError('Binary missing: %r' % binary)
66 lib = inst.child('lib')
67 if not os.path.isdir(lib):
68 raise RuntimeError('No lib/ in %r' % inst)
69
70 env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
71
72 firmware_path = os.path.join(str(inst), Osmocon.FIRMWARE_FILE)
73 if not os.path.isfile(firmware_path):
74 raise RuntimeError('Binary missing: %r' % firmware_path)
75 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
76 self.process = process.Process(self.name(), self.run_dir,
77 (binary, '-p', self.serial_device,
78 '-m', 'c123xor',
79 '-s', self.l2_socket_path(),
80 '-l', self.loader_socket_path(),
81 firmware_path),
82 env=env)
83 self.suite_run.remember_to_stop(self.process)
84 self.process.launch()
85 self.log('Waiting for osmocon to be up and running')
86 MainLoop.wait(self, os.path.exists, self.l2_socket_path())
87
88 def running(self):
89 return not self.process.terminated()
90
91 def cleanup(self):
92 if self.sk_tmp_dir:
93 try:
94 os.remove(self.l2_socket_path())
95 except OSError:
96 pass
97 try:
98 os.remove(self.loader_socket_path())
99 except OSError:
100 pass
101 os.rmdir(self.sk_tmp_dir)
102
103# vim: expandtab tabstop=4 shiftwidth=4