Change in osmo-gsm-tester[master]: ttcn3: Refactor ttcn3 launching bits into a testlib

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Tue Feb 11 10:56:34 UTC 2020


pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-gsm-tester/+/17097 )

Change subject: ttcn3: Refactor ttcn3 launching bits into a testlib
......................................................................

ttcn3: Refactor ttcn3 launching bits into a testlib

This way new tests can be more easily created which run some specific
TTCN3 test.

Change-Id: Ic61c7b7db9cf3050dc4b101ef0fb181421577424
---
A ttcn3/suites/ttcn3_bts_tests/lib/testlib.py
M ttcn3/suites/ttcn3_bts_tests/ttcn3_bts_tests.py
2 files changed, 47 insertions(+), 36 deletions(-)

Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, approved



diff --git a/ttcn3/suites/ttcn3_bts_tests/lib/testlib.py b/ttcn3/suites/ttcn3_bts_tests/lib/testlib.py
new file mode 100644
index 0000000..6a2bbaa
--- /dev/null
+++ b/ttcn3/suites/ttcn3_bts_tests/lib/testlib.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+import os
+from mako.template import Template
+
+from osmo_gsm_tester.testenv import *
+
+def run_ttcn3(suite, test_obj, testdir, bts, osmocon, nat_rsl_ip, ttcn3_test_execute):
+    own_dir = testdir
+    script_file = os.path.join(testdir, 'scripts', 'run_ttcn3_docker.sh')
+    bts_tmpl_file = os.path.join(testdir, 'scripts', 'BTS_Tests.cfg.tmpl')
+    script_run_dir = test_obj.get_run_dir().new_dir('ttcn3')
+    bts_cfg_file = os.path.join(str(script_run_dir), 'BTS_Tests.cfg')
+    junit_ttcn3_dst_file = os.path.join(str(suite.trial.get_run_dir()), 'trial-') + test_obj.basename + '.xml'
+    if bts.bts_type() == 'osmo-bts-trx':
+        pcu_available = True
+        pcu_sk = bts.pcu_socket_path()
+    else: # PCU unix socket not available locally
+        pcu_available = False
+        pcu_sk = ''
+    docker_cmd = (script_file, str(script_run_dir), junit_ttcn3_dst_file, nat_rsl_ip, osmocon.l2_socket_path(), pcu_sk)
+
+    print('Creating template')
+    mytemplate = Template(filename=bts_tmpl_file)
+    r = mytemplate.render(btsvty_ctrl_hostname=bts.remote_addr(), pcu_available=pcu_available, ttcn3_test_execute=ttcn3_test_execute)
+    with open(bts_cfg_file, 'w') as f:
+        f.write(r)
+
+
+    print('Starting TTCN3 test suite')
+    proc = process.Process('ttcn3', script_run_dir, docker_cmd)
+    try:
+        proc.launch()
+        print('TTCN3 test suite launched, waiting until it finishes')
+        proc.wait(timeout=3600)
+    except Exception as e:
+        proc.terminate()
+        raise e
+
+    if proc.result != 0:
+        raise RuntimeError("run_ttcn3_docker.sh exited with error code %d" % proc.result)
+
+    print('Done')
diff --git a/ttcn3/suites/ttcn3_bts_tests/ttcn3_bts_tests.py b/ttcn3/suites/ttcn3_bts_tests/ttcn3_bts_tests.py
index 4839052..a34c847 100755
--- a/ttcn3/suites/ttcn3_bts_tests/ttcn3_bts_tests.py
+++ b/ttcn3/suites/ttcn3_bts_tests/ttcn3_bts_tests.py
@@ -1,8 +1,10 @@
 #!/usr/bin/env python3
 import os
-from mako.template import Template
 
 from osmo_gsm_tester.testenv import *
+import testlib
+suite.test_import_modules_register_for_cleanup(testlib)
+from testlib import run_ttcn3
 
 ttcn3_test_execute="BTS_Tests.control"
 
@@ -43,38 +45,5 @@
 print('Starting osmocon')
 osmocon.start()
 
-own_dir = os.path.dirname(os.path.realpath(__file__))
-script_file = os.path.join(own_dir, 'scripts', 'run_ttcn3_docker.sh')
-bts_tmpl_file = os.path.join(own_dir, 'scripts', 'BTS_Tests.cfg.tmpl')
-script_run_dir = test.get_run_dir().new_dir('ttcn3')
-bts_cfg_file = os.path.join(str(script_run_dir), 'BTS_Tests.cfg')
-junit_ttcn3_dst_file = os.path.join(str(suite.trial.get_run_dir()), 'trial-') + suite.name() + '.xml'
-if bts.bts_type() == 'osmo-bts-trx':
-    pcu_available = True
-    pcu_sk = bts.pcu_socket_path()
-else: # PCU unix socket not available locally
-    pcu_available = False
-    pcu_sk = ''
-docker_cmd = (script_file, str(script_run_dir), junit_ttcn3_dst_file, nat_rsl_ip, osmocon.l2_socket_path(), pcu_sk)
-
-print('Creating template')
-mytemplate = Template(filename=bts_tmpl_file)
-r = mytemplate.render(btsvty_ctrl_hostname=bts.remote_addr(), pcu_available=pcu_available, ttcn3_test_execute=ttcn3_test_execute)
-with open(bts_cfg_file, 'w') as f:
-    f.write(r)
-
-
-print('Starting TTCN3 tests')
-proc = process.Process('ttcn3', script_run_dir, docker_cmd)
-try:
-    proc.launch()
-    print('Starting TTCN3 launched, waiting until it finishes')
-    proc.wait(timeout=3600)
-except Exception as e:
-    proc.terminate()
-    raise e
-
-if proc.result != 0:
-    raise RuntimeError("run_ttcn3_docker.sh exited with error code %d" % proc.result)
-
-print('Done')
+testdir = os.path.dirname(os.path.realpath(__file__))
+run_ttcn3(suite, test, testdir, bts, osmocon, nat_rsl_ip, ttcn3_test_execute)

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-gsm-tester/+/17097
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Change-Id: Ic61c7b7db9cf3050dc4b101ef0fb181421577424
Gerrit-Change-Number: 17097
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-CC: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200211/1953d928/attachment.htm>


More information about the gerrit-log mailing list