blob: 3548333843e10746c3e64ea9310b105cc35fb3d5 [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
Pau Espin Pedrolf2c2a342020-06-09 14:32:14 +02007def run_ttcn3(tenv, testdir, bts, osmocon, nat_rsl_ip, ttcn3_test_execute, ttcn3_test_extra_module_params=""):
Pau Espin Pedrolc9faa9e2020-02-06 16:13:53 +01008 own_dir = testdir
9 script_file = os.path.join(testdir, 'scripts', 'run_ttcn3_docker.sh')
10 bts_tmpl_file = os.path.join(testdir, 'scripts', 'BTS_Tests.cfg.tmpl')
Pau Espin Pedrolf2c2a342020-06-09 14:32:14 +020011 script_run_dir = tenv.test().get_run_dir().new_dir('ttcn3')
Pau Espin Pedrolc9faa9e2020-02-06 16:13:53 +010012 bts_cfg_file = os.path.join(str(script_run_dir), 'BTS_Tests.cfg')
Pau Espin Pedrol8ea4ba22020-06-10 14:20:53 +020013 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 +010014 if bts.bts_type() == 'osmo-bts-trx':
15 pcu_available = True
16 pcu_sk = bts.pcu_socket_path()
17 else: # PCU unix socket not available locally
18 pcu_available = False
19 pcu_sk = ''
20 docker_cmd = (script_file, str(script_run_dir), junit_ttcn3_dst_file, nat_rsl_ip, osmocon.l2_socket_path(), pcu_sk)
21
22 print('Creating template')
23 mytemplate = Template(filename=bts_tmpl_file)
Vadim Yanitskiyed5c7762020-08-06 01:46:20 +070024 r = mytemplate.render(btsvty_ctrl_hostname=bts.remote_addr(),
25 pcu_available=pcu_available,
26 ttcn3_test_execute=ttcn3_test_execute,
27 ttcn3_test_extra_module_params=ttcn3_test_extra_module_params)
Pau Espin Pedrolc9faa9e2020-02-06 16:13:53 +010028 with open(bts_cfg_file, 'w') as f:
29 f.write(r)
30
31
32 print('Starting TTCN3 test suite')
33 proc = process.Process('ttcn3', script_run_dir, docker_cmd)
34 try:
35 proc.launch()
36 print('TTCN3 test suite launched, waiting until it finishes')
37 proc.wait(timeout=3600)
38 except Exception as e:
39 proc.terminate()
40 raise e
41
42 if proc.result != 0:
43 raise RuntimeError("run_ttcn3_docker.sh exited with error code %d" % proc.result)
44
45 print('Done')