From d27818cab950e4fcc0b101af1579e798d5f723c7 Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Fri, 17 Jan 2025 16:01:24 -0500 Subject: [PATCH] tests: Test ABI diff of liblttng-ctl MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: Ic401829c4485773215013bd4233f589f39549372 Signed-off-by: Kienan Stewart Signed-off-by: Jérémie Galarneau --- configure.ac | 1 + tests/regression/Makefile.am | 1 + tests/regression/tools/Makefile.am | 1 + tests/regression/tools/lttng-ctl/Makefile.am | 19 ++++ .../tools/lttng-ctl/test_liblttng-ctl_abi.py | 106 ++++++++++++++++++ 5 files changed, 128 insertions(+) create mode 100644 tests/regression/tools/lttng-ctl/Makefile.am create mode 100755 tests/regression/tools/lttng-ctl/test_liblttng-ctl_abi.py diff --git a/configure.ac b/configure.ac index 59c00fe88..40135ce48 100644 --- a/configure.ac +++ b/configure.ac @@ -1280,6 +1280,7 @@ AC_CONFIG_FILES([ tests/regression/tools/health/Makefile tests/regression/tools/tracefile-limits/Makefile tests/regression/tools/snapshots/Makefile + tests/regression/tools/lttng-ctl/Makefile tests/regression/tools/live/Makefile tests/regression/tools/exclusion/Makefile tests/regression/tools/save-load/Makefile diff --git a/tests/regression/Makefile.am b/tests/regression/Makefile.am index 86a351d08..c0665c8a1 100644 --- a/tests/regression/Makefile.am +++ b/tests/regression/Makefile.am @@ -71,6 +71,7 @@ SERIAL_TESTS = tools/base-path/test_ust \ TESTS = tools/live/test_early_inactive_app.py \ tools/live/test_miss_short_lived_app.py \ tools/live/test_per_application_leaks.py \ + tools/lttng-ctl/test_liblttng-ctl_abi.py \ tools/context/test_ust.py \ tools/client/test_session_commands.py \ tools/client/test_event_rule_listing.py \ diff --git a/tests/regression/tools/Makefile.am b/tests/regression/tools/Makefile.am index ecd4eabd6..e88fd67bc 100644 --- a/tests/regression/tools/Makefile.am +++ b/tests/regression/tools/Makefile.am @@ -10,6 +10,7 @@ SUBDIRS = base-path \ filtering \ health \ live \ + lttng-ctl \ metadata \ mi \ notification \ diff --git a/tests/regression/tools/lttng-ctl/Makefile.am b/tests/regression/tools/lttng-ctl/Makefile.am new file mode 100644 index 000000000..a6dae046e --- /dev/null +++ b/tests/regression/tools/lttng-ctl/Makefile.am @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-2.0-only +# SPDX-FileCopyrightText: 2025 Kienan Stewart + +noinst_SCRIPTS = test_liblttng-ctl_abi.py +EXTRA_DIST = test_liblttng-ctl_abi.py + +all-local: + @if [ x"$(srcdir)" != x"$(builddir)" ]; then \ + for script in $(EXTRA_DIST); do \ + cp -f $(srcdir)/$$script $(builddir); \ + done; \ + fi + +clean-local: + @if [ x"$(srcdir)" != x"$(builddir)" ]; then \ + for script in $(EXTRA_DIST); do \ + rm -f $(builddir)/$$script; \ + done; \ + fi diff --git a/tests/regression/tools/lttng-ctl/test_liblttng-ctl_abi.py b/tests/regression/tools/lttng-ctl/test_liblttng-ctl_abi.py new file mode 100755 index 000000000..4680b105c --- /dev/null +++ b/tests/regression/tools/lttng-ctl/test_liblttng-ctl_abi.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 +# +# SPDX-FileCopyrightText: 2025 Kienan Stewart +# SPDX-License-Identifier: GPL-2.0-only +# + +""" +Generate a representation of the ABI for the built liblttng-ctl library, and +diff against the stored copy, if any. +""" + +import os +import pathlib +import shutil +import subprocess +import sys +import tempfile + +test_utils_import_path = pathlib.Path(__file__).absolute().parents[3] / "utils" +sys.path.append(str(test_utils_import_path)) + +import lttngtest + + +def test_abi_diff(tap, test_env): + if not shutil.which("abidw") or not shutil.which("abidiff"): + tap.skip("abidw and abidiff are not available") + return + + lttngctl_path = ( + pathlib.Path(test_env._project_root) / "src/lib/lttng-ctl/.libs/liblttng-ctl.so" + ) + lttngctl_version = os.readlink(str(lttngctl_path)).split(".", 2)[-1] + tap.diagnostic("Discovered liblttng-ctl version '{}'".format(lttngctl_version)) + + abi_path = pathlib.Path( + test_env._project_root + ) / "src/lib/lttng-ctl/abi_ref/{}/abi.xml".format(lttngctl_version) + + headers_dir = pathlib.Path(test_env._project_root) / "include" + + if not lttngctl_path.exists(): + tap.skip("'{}' does not exist".format(str(lttngctl_path))) + return + + if not abi_path.exists(): + tap.skip("'{}' does not exist".format(str(abi_path))) + return + + abi_tmp = tempfile.NamedTemporaryFile() + abidw_command = [ + "abidw", + "--drop-undefined-syms", + "--drop-private-types", + "--headers-dir", + str(headers_dir), + str(lttngctl_path), + ] + + tap.diagnostic("Generation command: `{}`".format(" ".join(abidw_command))) + abidw = subprocess.Popen( + abidw_command, + stdout=abi_tmp.file, + stderr=subprocess.PIPE, + ) + abidw.wait() + if abidw.returncode != 0: + tap.diagnostic(abidw.stderr.read().decode("utf-8")) + tap.fail( + "Failed to produce XML representation of current ABI, returncode '{}'".format( + abidw.returncode + ) + ) + return + + abidiff_command = ["abidiff", str(abi_path), str(abi_tmp.name)] + tap.diagnostic("Diff command: `{}`".format(" ".join(abidiff_command))) + abidiff = subprocess.Popen( + abidiff_command, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + ) + abidiff.wait() + + message = "No ABI changes detected" + success = True + if abidiff.returncode & 8 == 8: + success = False + message = "Breaking ABI changes detected" + elif abidiff.returncode & 4 == 4: + message = "ABI changes changes detected" + elif abidiff.returncode != 0: + success = False + message = "Error running abidiff, return code '{}'".format(abidiff.returncode) + + tap.diagnostic("ABI diff output:\n{}".format(abidiff.stdout.read().decode("utf-8"))) + tap.test(success, message) + + +tap = lttngtest.TapGenerator(1) +with lttngtest.test_environment( + log=tap.diagnostic, with_relayd=False, with_sessiond=False +) as test_env: + test_abi_diff(tap, test_env) + +sys.exit(0 if tap.is_successful else 1) -- 2.39.5