blob: c3b3f350dd41972fb2957169d7354f2f2e8a3145 [file] [log] [blame]
Pau Espin Pedrolc9faa9e2020-02-06 16:13:53 +01001#!/usr/bin/env python3
2import os
3from mako.template import Template
4
5from osmo_gsm_tester.testenv import *
6
Vadim Yanitskiyd1cb7592020-08-06 01:53:24 +07007def run_ttcn3(tenv, testdir, bts, osmocon, nat_rsl_ip,
8 ttcn3_test_groups = [],
9 ttcn3_test_extra_module_params=""):
Pau Espin Pedrolc9faa9e2020-02-06 16:13:53 +010010 own_dir = testdir
11 script_file = os.path.join(testdir, 'scripts', 'run_ttcn3_docker.sh')
12 bts_tmpl_file = os.path.join(testdir, 'scripts', 'BTS_Tests.cfg.tmpl')
Pau Espin Pedrolf2c2a342020-06-09 14:32:14 +020013 script_run_dir = tenv.test().get_run_dir().new_dir('ttcn3')
Pau Espin Pedrolc9faa9e2020-02-06 16:13:53 +010014 bts_cfg_file = os.path.join(str(script_run_dir), 'BTS_Tests.cfg')
Pau Espin Pedrol8ea4ba22020-06-10 14:20:53 +020015 junit_ttcn3_dst_file = os.path.join(str(tenv.suite().trial().get_run_dir()), 'trial-' + tenv.suite().name() + '.' + tenv.test().module_name() + '.xml')
Pau Espin Pedrolc9faa9e2020-02-06 16:13:53 +010016 if bts.bts_type() == 'osmo-bts-trx':
17 pcu_available = True
18 pcu_sk = bts.pcu_socket_path()
19 else: # PCU unix socket not available locally
20 pcu_available = False
21 pcu_sk = ''
22 docker_cmd = (script_file, str(script_run_dir), junit_ttcn3_dst_file, nat_rsl_ip, osmocon.l2_socket_path(), pcu_sk)
23
24 print('Creating template')
25 mytemplate = Template(filename=bts_tmpl_file)
Vadim Yanitskiyed5c7762020-08-06 01:46:20 +070026 r = mytemplate.render(btsvty_ctrl_hostname=bts.remote_addr(),
27 pcu_available=pcu_available,
Vadim Yanitskiyd1cb7592020-08-06 01:53:24 +070028 ttcn3_test_groups=ttcn3_test_groups,
Vadim Yanitskiyed5c7762020-08-06 01:46:20 +070029 ttcn3_test_extra_module_params=ttcn3_test_extra_module_params)
Pau Espin Pedrolc9faa9e2020-02-06 16:13:53 +010030 with open(bts_cfg_file, 'w') as f:
31 f.write(r)
32
33
34 print('Starting TTCN3 test suite')
35 proc = process.Process('ttcn3', script_run_dir, docker_cmd)
36 try:
37 proc.launch()
38 print('TTCN3 test suite launched, waiting until it finishes')
39 proc.wait(timeout=3600)
40 except Exception as e:
41 proc.terminate()
42 raise e
43
44 if proc.result != 0:
45 raise RuntimeError("run_ttcn3_docker.sh exited with error code %d" % proc.result)
46
47 print('Done')