Pau Espin Pedrol | bc1ed88 | 2018-05-17 16:59:58 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | import os |
| 3 | from mako.template import Template |
| 4 | |
| 5 | from osmo_gsm_tester.testenv import * |
| 6 | |
Pau Espin Pedrol | ceb7ea6 | 2020-02-06 15:59:48 +0100 | [diff] [blame^] | 7 | ttcn3_test_execute="BTS_Tests.control" |
| 8 | |
Pau Espin Pedrol | bc1ed88 | 2018-05-17 16:59:58 +0200 | [diff] [blame] | 9 | hlr_dummy = suite.hlr() |
| 10 | mgw_dummy = suite.mgw() |
| 11 | stp_dummy = suite.stp() |
| 12 | msc_dummy = suite.msc(hlr_dummy, mgw_dummy, stp_dummy) |
| 13 | ggsn_dummy = suite.ggsn() |
| 14 | sgsn_dummy = suite.sgsn(hlr_dummy, ggsn_dummy) |
| 15 | bsc = suite.bsc(msc_dummy, mgw_dummy, stp_dummy) |
| 16 | bts = suite.bts() |
| 17 | osmocon = suite.osmocon() |
| 18 | |
| 19 | bts.set_num_trx(1) |
| 20 | bts.set_trx_phy_channel(0, 0, 'CCCH+SDCCH4') |
| 21 | bts.set_trx_phy_channel(0, 1, 'TCH/F') |
| 22 | bts.set_trx_phy_channel(0, 2, 'TCH/F') |
| 23 | bts.set_trx_phy_channel(0, 3, 'TCH/F_PDCH') |
| 24 | bts.set_trx_phy_channel(0, 4, 'TCH/F_TCH/H_PDCH') |
| 25 | bts.set_trx_phy_channel(0, 5, 'TCH/H') |
| 26 | bts.set_trx_phy_channel(0, 6, 'SDCCH8') |
| 27 | bts.set_trx_phy_channel(0, 7, 'PDCH') |
| 28 | |
| 29 | print('Starting CNI') |
| 30 | hlr_dummy.start() |
| 31 | stp_dummy.start() |
| 32 | msc_dummy.start() |
| 33 | mgw_dummy.start() |
| 34 | |
Pau Espin Pedrol | a528556 | 2018-10-15 17:20:50 +0200 | [diff] [blame] | 35 | nat_rsl_ip = suite.ip_address().get('addr') |
| 36 | bsc.set_rsl_ip(nat_rsl_ip) |
Pau Espin Pedrol | bc1ed88 | 2018-05-17 16:59:58 +0200 | [diff] [blame] | 37 | bsc.bts_add(bts) |
| 38 | sgsn_dummy.bts_add(bts) |
| 39 | |
| 40 | bsc.start() |
| 41 | bts.start(keepalive=True) |
| 42 | |
| 43 | print('Starting osmocon') |
| 44 | osmocon.start() |
| 45 | |
| 46 | own_dir = os.path.dirname(os.path.realpath(__file__)) |
| 47 | script_file = os.path.join(own_dir, 'scripts', 'run_ttcn3_docker.sh') |
| 48 | bts_tmpl_file = os.path.join(own_dir, 'scripts', 'BTS_Tests.cfg.tmpl') |
| 49 | script_run_dir = test.get_run_dir().new_dir('ttcn3') |
| 50 | bts_cfg_file = os.path.join(str(script_run_dir), 'BTS_Tests.cfg') |
| 51 | junit_ttcn3_dst_file = os.path.join(str(suite.trial.get_run_dir()), 'trial-') + suite.name() + '.xml' |
Pau Espin Pedrol | f616614 | 2018-10-11 17:49:34 +0200 | [diff] [blame] | 52 | if bts.bts_type() == 'osmo-bts-trx': |
| 53 | pcu_available = True |
| 54 | pcu_sk = bts.pcu_socket_path() |
| 55 | else: # PCU unix socket not available locally |
| 56 | pcu_available = False |
| 57 | pcu_sk = '' |
Pau Espin Pedrol | a528556 | 2018-10-15 17:20:50 +0200 | [diff] [blame] | 58 | docker_cmd = (script_file, str(script_run_dir), junit_ttcn3_dst_file, nat_rsl_ip, osmocon.l2_socket_path(), pcu_sk) |
Pau Espin Pedrol | bc1ed88 | 2018-05-17 16:59:58 +0200 | [diff] [blame] | 59 | |
| 60 | print('Creating template') |
| 61 | mytemplate = Template(filename=bts_tmpl_file) |
Pau Espin Pedrol | ceb7ea6 | 2020-02-06 15:59:48 +0100 | [diff] [blame^] | 62 | r = mytemplate.render(btsvty_ctrl_hostname=bts.remote_addr(), pcu_available=pcu_available, ttcn3_test_execute=ttcn3_test_execute) |
Pau Espin Pedrol | bc1ed88 | 2018-05-17 16:59:58 +0200 | [diff] [blame] | 63 | with open(bts_cfg_file, 'w') as f: |
| 64 | f.write(r) |
| 65 | |
| 66 | |
| 67 | print('Starting TTCN3 tests') |
| 68 | proc = process.Process('ttcn3', script_run_dir, docker_cmd) |
| 69 | try: |
| 70 | proc.launch() |
| 71 | print('Starting TTCN3 launched, waiting until it finishes') |
| 72 | proc.wait(timeout=3600) |
| 73 | except Exception as e: |
| 74 | proc.terminate() |
| 75 | raise e |
| 76 | |
| 77 | if proc.result != 0: |
| 78 | raise RuntimeError("run_ttcn3_docker.sh exited with error code %d" % proc.result) |
| 79 | |
| 80 | print('Done') |