osmith has submitted this change. (
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/40450?usp=email )
Change subject: testenv: support using multiple titan versions
......................................................................
testenv: support using multiple titan versions
Install eclipse-titan versions 9.0.0 and 11.1.0 into
/opt/eclipse-titan-$version inside the podman container by using the new
optdir packages. Choose the appropriate version by setting related
environment variables. Use the version in $PATH on the host, unless
/opt/eclipse-titan-$version is also present on the host system.
Add a new --titan-version argument to explicitly set a version to use
when running a testsuite.
Rewrite the version check code to take titan_min, --titan-version and
the host version (if not using optdir) into account.
Related: OS#6490
Change-Id: I48d711da57c874cf7cd557480a163eea1a4167bd
---
M _testenv/README.md
M _testenv/data/podman/Dockerfile
M _testenv/testenv.py
M _testenv/testenv/__init__.py
M _testenv/testenv/podman.py
M _testenv/testenv/requirements.py
M _testenv/testenv/testenv_cfg.py
M _testenv/testenv/testsuite.py
8 files changed, 121 insertions(+), 36 deletions(-)
Approvals:
osmith: Looks good to me, approved
jolly: Looks good to me, but someone else must approve
Jenkins Builder: Verified
pespin: Looks good to me, but someone else must approve
diff --git a/_testenv/README.md b/_testenv/README.md
index a712dc8..ecc8701 100644
--- a/_testenv/README.md
+++ b/_testenv/README.md
@@ -66,7 +66,8 @@
#### Testsuite section
* `titan_min=`: the minimum required eclipse-titan version for building and
- running this testsuite.
+ running this testsuite. See the eclipse-titan versions section below for
+ details.
* `program=`: the executable for starting the testsuite, without arguments.
@@ -275,6 +276,17 @@
* `TERM`:
Is set to the same `TERM` passed to testenv with fallback to `dumb`.
+## Eclipse-titan versions
+
+It is possible to change the eclipse-titan version that is used to build and
+run a testsuite if multiple versions are installed. This is the case when
+running in podman (see `testenv/data/podman/Dockerfile`) or if multiple
+versions are installed as `/opt/eclipse-titan-$VERSION` paths on the host
+system.
+
+Switching between the versions is done either by setting a `titan_min` version
+in the `[testsuite]` section, or by using `-T` / `--titan-version`.
+
## Troubleshooting
### Timeout waiting for RESET-ACK after sending RESET
diff --git a/_testenv/data/podman/Dockerfile b/_testenv/data/podman/Dockerfile
index dca8a75..84aa0db 100644
--- a/_testenv/data/podman/Dockerfile
+++ b/_testenv/data/podman/Dockerfile
@@ -147,7 +147,8 @@
RUN set -x && \
apt-get update && \
apt-get install -y --no-install-recommends \
- eclipse-titan \
+ eclipse-titan-optdir-9.0.0 \
+ eclipse-titan-optdir-11.1.0 \
&& \
apt-get clean && \
rm /etc/apt/sources.list.d/osmocom-latest.list
diff --git a/_testenv/testenv.py b/_testenv/testenv.py
index f852c0c..2aac11e 100755
--- a/_testenv/testenv.py
+++ b/_testenv/testenv.py
@@ -43,6 +43,7 @@
if testenv.args.podman:
testenv.podman.init()
testenv.podman.start()
+ testenv.podman.check_titan_version()
if not testenv.args.binary_repo:
testenv.osmo_dev.init()
diff --git a/_testenv/testenv/__init__.py b/_testenv/testenv/__init__.py
index cb4a02c..511ec58 100644
--- a/_testenv/testenv/__init__.py
+++ b/_testenv/testenv/__init__.py
@@ -86,6 +86,7 @@
help="which testenv.cfg to use (supports * wildcards via fnmatch)",
)
group.add_argument("-i", "--io-uring",
action="store_true", help="set LIBOSMO_IO_BACKEND=IO_URING")
+ group.add_argument("-T", "--titan-version", help="which
eclipse-titan version to use")
group = sub_run.add_argument_group("source/binary options", "All
components are built from source by default.")
group.add_argument(
diff --git a/_testenv/testenv/podman.py b/_testenv/testenv/podman.py
index f8812e4..5099a95 100644
--- a/_testenv/testenv/podman.py
+++ b/_testenv/testenv/podman.py
@@ -12,6 +12,7 @@
import testenv.testdir
import testenv.coredump
import time
+import sys
image_name = None
distro = None
@@ -283,6 +284,20 @@
exec_cmd(["apt-get", "-q", "update"])
+def check_titan_version():
+ version, _ = testenv.testenv_cfg.get_titan_version_first_cfg()
+ if not testenv.cmd.run(["test", "-d",
f"/opt/eclipse-titan-{version}"], check=False).returncode:
+ return
+
+ up_to_date = testenv.podman.image_up_to_date()
+ logging.error(f"/opt/eclipse-titan-{version} not found in the podman
container!")
+ if up_to_date:
+ logging.error("Consider modifying _testenv/data/podman/Dockerfile.")
+ else:
+ logging.error("Try './testenv.py init podman' to update the
container.")
+ sys.exit(1)
+
+
def distro_to_repo_dir(distro):
if distro == "debian:bookworm":
return "Debian_12"
diff --git a/_testenv/testenv/requirements.py b/_testenv/testenv/requirements.py
index 6e7c32c..540fe55 100644
--- a/_testenv/testenv/requirements.py
+++ b/_testenv/testenv/requirements.py
@@ -1,10 +1,8 @@
# Copyright 2024 sysmocom - s.f.m.c. GmbH
# SPDX-License-Identifier: GPL-3.0-or-later
-from packaging.version import Version
import logging
import os.path
import shutil
-import subprocess
import sys
import testenv
import testenv.cmd
@@ -71,30 +69,6 @@
sys.exit(1)
-def check_ttcn3_compiler_version():
- if testenv.args.podman:
- return
-
- ttcn3_min_version = "9.0.0"
-
- v = subprocess.run(["ttcn3_compiler", "-v"], capture_output=True,
text=True)
- current = None
- for line in v.stderr.split("\n"):
- if not line.startswith("Version: "):
- continue
-
- current = line.split(":", 1)[1].strip()
- if Version(current) >= Version(ttcn3_min_version):
- return
-
- logging.error(f"Found ttcn3_compiler version {current}, but
{ttcn3_min_version} or higher is required.")
-
- if not current:
- logging.error("Could not parse ttcn3_compiler version.")
- logging.error(f"Please install at least version {ttcn3_min_version} and try
again.")
- sys.exit(1)
-
-
def check_fftranscode():
cmd = [
"grep",
@@ -124,7 +98,6 @@
def check():
check_programs()
- check_ttcn3_compiler_version()
if not testenv.args.podman:
check_fftranscode()
diff --git a/_testenv/testenv/testenv_cfg.py b/_testenv/testenv/testenv_cfg.py
index 5b1d32f..84176d7 100644
--- a/_testenv/testenv/testenv_cfg.py
+++ b/_testenv/testenv/testenv_cfg.py
@@ -1,5 +1,6 @@
# Copyright 2024 sysmocom - s.f.m.c. GmbH
# SPDX-License-Identifier: GPL-3.0-or-later
+from packaging.version import Version
import configparser
import fnmatch
import glob
@@ -10,6 +11,8 @@
cfgs = {}
current = None
+titan_version_in_path = None
+titan_min_previous = None
def set_current(cfg_name, loop_count=0):
@@ -74,6 +77,76 @@
return host, port
+def get_titan_version_in_path():
+ global titan_version_in_path
+
+ if titan_version_in_path:
+ return titan_version_in_path
+
+ ret = None
+ v = testenv.cmd.run(["ttcn3_compiler", "-v"],
capture_output=True, text=True)
+ for line in v.stderr.split("\n"):
+ if line.startswith("Version: "):
+ ret = line.split(":", 1)[1].strip()
+ logging.debug(f"eclipse-titan version: {ret}")
+ break
+ titan_version_in_path = ret
+ return ret
+
+
+def get_titan_version(cfg, path=None):
+ global titan_min_previous
+
+ ret_version = cfg["testsuite"]["titan_min"]
+ ret_reason = "from titan_min= in testenv.cfg"
+
+ if titan_min_previous and titan_min_previous["version"] != ret_version:
+ logging.error("Found different titan_min= versions in testenv.cfg files of
the same directory:")
+ logging.error(f" titan_min={ret_version} in {path}")
+ logging.error(f" titan_min={titan_min_previous['version']} in
{titan_min_previous['path']}")
+ logging.error("This is not supported, please fix it.")
+ sys.exit(1)
+ titan_min_previous = {"version": ret_version, "path": path}
+
+ if testenv.args.titan_version:
+ if Version(ret_version) > Version(testenv.args.titan_version):
+ logging.error(
+ f"--titan-version={testenv.args.titan_version} is lower than
titan_min={ret_version} in {path}"
+ )
+ sys.exit(1)
+ ret_version = testenv.args.titan_version
+ ret_reason = "from --titan-version"
+
+ if not testenv.args.podman and not
os.path.exists(f"/opt/eclipse-titan-{ret_version}"):
+ path_version = get_titan_version_in_path()
+ if not path_version:
+ logging.error("Failed to parse the ttcn3_compiler version.")
+ logging.error(f"Install eclipse-titan {ret_version} or higher or use
--podman.")
+ sys.exit(1)
+ if testenv.args.titan_version and ret_version != path_version:
+ logging.error(
+ f"Installed eclipse-titan version {path_version} is not the same as
--titan-version={ret_version}."
+ )
+ sys.exit(1)
+ if Version(ret_version) > Version(path_version):
+ logging.error(
+ f"Installed eclipse-titan version {path_version} is lower than
titan_min={ret_version} in {path}."
+ )
+ logging.error(f"Install eclipse-titan {ret_version} or higher or use
--podman.")
+ sys.exit(1)
+ ret_version = path_version
+ ret_reason = "installed on host system"
+
+ return ret_version, ret_reason
+
+
+def get_titan_version_first_cfg():
+ """The titan version is the same for all testenv.cfg files in the
same
+ testsuite directory, this is enforced in get_titan_version()."""
+ _, cfg = next(iter(cfgs.items()))
+ return get_titan_version(cfg)
+
+
def verify_qemu_cfgs():
"""Check if passed -C or -K args make sense with the testenv
configs."""
testsuite = testenv.args.testsuite
@@ -194,6 +267,7 @@
sys.exit(1)
get_vty_host_port(cfg, path)
+ get_titan_version(cfg, path)
def raise_error_config_arg(glob_result, config_arg):
diff --git a/_testenv/testenv/testsuite.py b/_testenv/testenv/testsuite.py
index 753773f..8452a80 100644
--- a/_testenv/testenv/testsuite.py
+++ b/_testenv/testenv/testsuite.py
@@ -11,6 +11,7 @@
import subprocess
import testenv
import testenv.cmd
+import testenv.testenv_cfg
import time
builddir_env = {}
@@ -35,15 +36,21 @@
atexit.register(stop)
update_deps()
- if testenv.args.podman:
- builddir = os.path.join(testenv.args.cache, "podman",
"ttcn3")
- builddir_env = {"BUILDDIR": builddir}
+ titan_version, _ = testenv.testenv_cfg.get_titan_version_first_cfg()
+ ttcn3_dir = f"/opt/eclipse-titan-{titan_version}"
+
+ if testenv.args.podman or os.path.exists(ttcn3_dir):
+ cache_dir = "podman" if testenv.args.podman else "host"
+ builddir = os.path.join(testenv.args.cache, cache_dir,
f"titan-{titan_version}")
+ path_old =
testenv.cmd.generate_env(podman=testenv.args.podman)["PATH"]
+ builddir_env = {"BUILDDIR": builddir, "TTCN3_DIR": ttcn3_dir,
"PATH": f"{ttcn3_dir}/bin:{path_old}"}
prepare_testsuite_dir()
def build():
- logging.info("Building testsuite")
+ titan_version, titan_reason = testenv.testenv_cfg.get_titan_version_first_cfg()
+ logging.info(f"Building testsuite (eclipse-titan {titan_version},
{titan_reason})")
env = copy.copy(builddir_env)
if testenv.args.jobs:
@@ -73,7 +80,7 @@
# stdout of this script is very verbose, making it harder to see the output
# that matters (tests failed or not), so redirect it to /dev/null
cmd = f"{shlex.quote(log_merge)} {shlex.quote(section_data['program'])}
--rm >/dev/null"
- testenv.cmd.run(cmd, cwd=cwd)
+ testenv.cmd.run(cmd, cwd=cwd, env=builddir_env)
def format_log_files(cfg):
@@ -81,7 +88,7 @@
logging.info("Formatting log files")
cmd = os.path.join(testenv.data_dir, "scripts/log_format.sh")
- testenv.cmd.run(cmd, cwd=cwd)
+ testenv.cmd.run(cmd, cwd=cwd, env=builddir_env)
def get_junit_logs(topdir):
@@ -151,7 +158,8 @@
else:
cmd += [f"{section_data['program']}.{test_arg}"]
- logging.info("Running testsuite")
+ titan_version, titan_reason = testenv.testenv_cfg.get_titan_version_first_cfg()
+ logging.info(f"Running testsuite (eclipse-titan {titan_version},
{titan_reason})")
if testenv.podman.is_running():
testsuite_proc = testenv.podman.exec_cmd_background(cmd, cwd=cwd, env=env)
--
To view, visit
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/40450?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: I48d711da57c874cf7cd557480a163eea1a4167bd
Gerrit-Change-Number: 40450
Gerrit-PatchSet: 3
Gerrit-Owner: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: jolly <andreas(a)eversberg.eu>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>