From d2a010d1e67e246e8ab4a847b8bbbdbce2b4e2d7 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Tue, 27 Apr 2021 12:14:15 -0400 Subject: [PATCH] Add abi0 conflict tests Add tests to make sure abi0 detection works properly in different linking and dlopen scenarios. Change-Id: I70927298163e5961e255250f7d8d6dd849d9d135 Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- .gitignore | 12 ++ configure.ac | 2 + tests/Makefile.am | 9 +- tests/regression/Makefile.am | 4 + tests/regression/abi0-conflict/Makefile.am | 83 ++++++++++ tests/regression/abi0-conflict/app_noust.c | 24 +++ .../abi0-conflict/app_noust_dlopen.c | 125 +++++++++++++++ tests/regression/abi0-conflict/app_ust.c | 43 ++++++ .../regression/abi0-conflict/app_ust_dlopen.c | 143 ++++++++++++++++++ tests/regression/abi0-conflict/fake-ust.c | 37 +++++ tests/regression/abi0-conflict/fake-ust.h | 18 +++ tests/regression/abi0-conflict/libone.c | 23 +++ tests/regression/abi0-conflict/libone.h | 8 + tests/regression/abi0-conflict/libzero.c | 25 +++ tests/regression/abi0-conflict/libzero.h | 8 + .../abi0-conflict/test_abi0_conflict | 129 ++++++++++++++++ tests/regression/abi0-conflict/tp.c | 8 + .../abi0-conflict/ust_tests_hello.h | 64 ++++++++ 18 files changed, 764 insertions(+), 1 deletion(-) create mode 100644 tests/regression/Makefile.am create mode 100644 tests/regression/abi0-conflict/Makefile.am create mode 100644 tests/regression/abi0-conflict/app_noust.c create mode 100644 tests/regression/abi0-conflict/app_noust_dlopen.c create mode 100644 tests/regression/abi0-conflict/app_ust.c create mode 100644 tests/regression/abi0-conflict/app_ust_dlopen.c create mode 100644 tests/regression/abi0-conflict/fake-ust.c create mode 100644 tests/regression/abi0-conflict/fake-ust.h create mode 100644 tests/regression/abi0-conflict/libone.c create mode 100644 tests/regression/abi0-conflict/libone.h create mode 100644 tests/regression/abi0-conflict/libzero.c create mode 100644 tests/regression/abi0-conflict/libzero.h create mode 100755 tests/regression/abi0-conflict/test_abi0_conflict create mode 100644 tests/regression/abi0-conflict/tp.c create mode 100644 tests/regression/abi0-conflict/ust_tests_hello.h diff --git a/.gitignore b/.gitignore index 12ec06c0..9d504cc0 100644 --- a/.gitignore +++ b/.gitignore @@ -100,6 +100,16 @@ cscope.* /tests/compile/api1/test-app-ctx/hello-compatapi1 /tests/compile/api1/ust-fields/ust-fields /tests/compile/api1/ust-fields/ust-fields-compatapi1 +/tests/regression/abi0-conflict/app_noust +/tests/regression/abi0-conflict/app_noust_dlopen +/tests/regression/abi0-conflict/app_noust_indirect_abi0 +/tests/regression/abi0-conflict/app_noust_indirect_abi0_abi1 +/tests/regression/abi0-conflict/app_noust_indirect_abi1 +/tests/regression/abi0-conflict/app_ust +/tests/regression/abi0-conflict/app_ust_dlopen +/tests/regression/abi0-conflict/app_ust_indirect_abi0 +/tests/regression/abi0-conflict/app_ust_indirect_abi0_abi1 +/tests/regression/abi0-conflict/app_ust_indirect_abi1 /tests/unit/gcc-weak-hidden/test_gcc_weak_hidden /tests/unit/libmsgpack/test_msgpack /tests/unit/libringbuffer/test_shm @@ -184,6 +194,8 @@ cscope.* /tests/compile/api1/hello/Makefile /tests/compile/api1/same_line_tracepoint/Makefile /tests/compile/api1/test-app-ctx/Makefile +/tests/regression/abi0-conflict/Makefile +/tests/regression/Makefile /tests/unit/Makefile /tests/unit/gcc-weak-hidden/Makefile /tests/unit/libmsgpack/Makefile diff --git a/configure.ac b/configure.ac index 2e2fbb93..7a5775f3 100644 --- a/configure.ac +++ b/configure.ac @@ -622,6 +622,8 @@ AC_CONFIG_FILES([ tests/compile/api1/test-app-ctx/Makefile tests/compile/Makefile tests/Makefile + tests/regression/abi0-conflict/Makefile + tests/regression/Makefile tests/unit/gcc-weak-hidden/Makefile tests/unit/libmsgpack/Makefile tests/unit/libringbuffer/Makefile diff --git a/tests/Makefile.am b/tests/Makefile.am index b2c1c2b5..d750ae39 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,6 @@ # SPDX-License-Identifier: LGPL-2.1-only -SUBDIRS = utils unit compile benchmark +SUBDIRS = utils unit compile benchmark regression LOG_DRIVER_FLAGS = --merge --comments LOG_DRIVER = env AM_TAP_AWK='$(AWK)' \ @@ -8,6 +8,8 @@ LOG_DRIVER = env AM_TAP_AWK='$(AWK)' \ UST_TESTS_BUILDDIR='$(abs_top_builddir)/tests' \ $(SHELL) $(srcdir)/utils/tap-driver.sh +# Unit tests + TESTS = \ unit/libringbuffer/test_shm \ unit/gcc-weak-hidden/test_gcc_weak_hidden \ @@ -23,6 +25,11 @@ TESTS += \ unit/ust-utils/test_ust_utils_cxx endif +# Regression tests + +TESTS += \ + regression/abi0-conflict/test_abi0_conflict + EXTRA_DIST = README check-loop: diff --git a/tests/regression/Makefile.am b/tests/regression/Makefile.am new file mode 100644 index 00000000..50bdbc7e --- /dev/null +++ b/tests/regression/Makefile.am @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: LGPL-2.1-only + +SUBDIRS = \ + abi0-conflict diff --git a/tests/regression/abi0-conflict/Makefile.am b/tests/regression/abi0-conflict/Makefile.am new file mode 100644 index 00000000..5b8761b6 --- /dev/null +++ b/tests/regression/abi0-conflict/Makefile.am @@ -0,0 +1,83 @@ +# SPDX-License-Identifier: LGPL-2.1-only + +AM_CPPFLAGS += -I$(top_srcdir)/tests/utils -I$(srcdir) + +noinst_LTLIBRARIES = \ + libfakeust0.la \ + libone.la \ + libzero.la + +libfakeust0_la_SOURCES = fake-ust.c fake-ust.h +libfakeust0_la_LDFLAGS = -module -shared -avoid-version -rpath $(abs_builddir)/.libs/ + +libzero_la_SOURCES = libzero.c libzero.h +libzero_la_LDFLAGS = -module -shared -avoid-version -rpath $(abs_builddir)/.libs/ +libzero_la_LIBADD = libfakeust0.la + +libone_la_SOURCES = libone.c libone.h +libone_la_LDFLAGS = -module -shared -avoid-version -rpath $(abs_builddir)/.libs/ +libone_la_LIBADD = $(top_builddir)/src/lib/lttng-ust/liblttng-ust.la + +noinst_PROGRAMS = \ + app_noust \ + app_noust_dlopen \ + app_noust_indirect_abi0 \ + app_noust_indirect_abi0_abi1 \ + app_noust_indirect_abi1 \ + app_ust \ + app_ust_dlopen \ + app_ust_indirect_abi0 \ + app_ust_indirect_abi0_abi1 \ + app_ust_indirect_abi1 + +app_ust_SOURCES = app_ust.c tp.c ust_tests_hello.h +app_ust_LDADD = \ + $(top_builddir)/src/lib/lttng-ust/liblttng-ust.la \ + $(DL_LIBS) + +app_ust_indirect_abi0_SOURCES = app_ust.c tp.c ust_tests_hello.h +app_ust_indirect_abi0_CFLAGS = -DUSE_LIBZERO $(AM_CFLAGS) +app_ust_indirect_abi0_LDADD = \ + $(top_builddir)/src/lib/lttng-ust/liblttng-ust.la \ + libzero.la \ + $(DL_LIBS) + +app_ust_indirect_abi1_SOURCES = app_ust.c tp.c ust_tests_hello.h +app_ust_indirect_abi1_CFLAGS = -DUSE_LIBONE $(AM_CFLAGS) +app_ust_indirect_abi1_LDADD = \ + $(top_builddir)/src/lib/lttng-ust/liblttng-ust.la \ + libone.la \ + $(DL_LIBS) + +app_ust_indirect_abi0_abi1_SOURCES = app_ust.c tp.c ust_tests_hello.h +app_ust_indirect_abi0_abi1_CFLAGS = -DUSE_LIBZERO -DUSE_LIBONE $(AM_CFLAGS) +app_ust_indirect_abi0_abi1_LDADD = \ + $(top_builddir)/src/lib/lttng-ust/liblttng-ust.la \ + libzero.la \ + libone.la \ + $(DL_LIBS) + +app_ust_dlopen_SOURCES = app_ust_dlopen.c tp.c ust_tests_hello.h +app_ust_dlopen_LDADD = \ + $(top_builddir)/src/lib/lttng-ust/liblttng-ust.la \ + $(DL_LIBS) + +app_noust_SOURCES = app_noust.c + +app_noust_indirect_abi0_SOURCES = app_noust.c +app_noust_indirect_abi0_CFLAGS = -DUSE_LIBZERO $(AM_CFLAGS) +app_noust_indirect_abi0_LDADD = libzero.la + +app_noust_indirect_abi1_SOURCES = app_noust.c +app_noust_indirect_abi1_CFLAGS = -DUSE_LIBONE $(AM_CFLAGS) +app_noust_indirect_abi1_LDADD = libone.la + +app_noust_indirect_abi0_abi1_SOURCES = app_noust.c +app_noust_indirect_abi0_abi1_CFLAGS = -DUSE_LIBZERO -DUSE_LIBONE $(AM_CFLAGS) +app_noust_indirect_abi0_abi1_LDADD = libzero.la libone.la + +app_noust_dlopen_SOURCES = app_noust_dlopen.c +app_noust_dlopen_LDADD = \ + $(DL_LIBS) + +dist_noinst_SCRIPTS = test_abi0_conflict diff --git a/tests/regression/abi0-conflict/app_noust.c b/tests/regression/abi0-conflict/app_noust.c new file mode 100644 index 00000000..35d11113 --- /dev/null +++ b/tests/regression/abi0-conflict/app_noust.c @@ -0,0 +1,24 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2021 Michael Jeanson + */ + +#include + +#include "./libzero.h" +#include "./libone.h" + +int main(void) +{ + printf("This application is NOT linked on liblttng-ust.\n"); + +#ifdef USE_LIBZERO + libzero(); +#endif +#ifdef USE_LIBONE + libone(); +#endif + + return 0; +} diff --git a/tests/regression/abi0-conflict/app_noust_dlopen.c b/tests/regression/abi0-conflict/app_noust_dlopen.c new file mode 100644 index 00000000..9a52bc79 --- /dev/null +++ b/tests/regression/abi0-conflict/app_noust_dlopen.c @@ -0,0 +1,125 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2021 Michael Jeanson + */ + +#include +#include +#include +#include +#include +#include + +#define LTTNG_UST_LIB_ABI0_SO_NAME "libfakeust0.so" +#define LTTNG_UST_LIB_ABI1_SO_NAME "liblttng-ust.so.1" + +static +int dlopen_ust(const char *lib_soname) +{ + int ret = EXIT_SUCCESS; + void *handle; + + handle = dlopen(lib_soname, RTLD_NOW | RTLD_GLOBAL); + if (!handle) { + printf("Error: dlopen of liblttng-ust shared library (%s).\n", lib_soname); + ret = EXIT_FAILURE; + } else { + printf("Success: dlopen of liblttng-ust shared library (%s).\n", lib_soname); + } + + return ret; +} + +static +int dlopen_abi0(void) +{ + return dlopen_ust(LTTNG_UST_LIB_ABI0_SO_NAME); +} + +static +int dlopen_abi1(void) +{ + return dlopen_ust(LTTNG_UST_LIB_ABI1_SO_NAME); +} + +static +int dlopen_abi0_abi1(void) +{ + int ret = EXIT_SUCCESS; + + ret = dlopen_ust(LTTNG_UST_LIB_ABI0_SO_NAME); + if (ret != EXIT_SUCCESS) + return ret; + + ret = dlopen_ust(LTTNG_UST_LIB_ABI1_SO_NAME); + + return ret; +} + +static +int dlopen_abi1_abi0(void) +{ + int ret = EXIT_SUCCESS; + + ret = dlopen_ust(LTTNG_UST_LIB_ABI1_SO_NAME); + if (ret != EXIT_SUCCESS) + return ret; + + ret = dlopen_ust(LTTNG_UST_LIB_ABI0_SO_NAME); + + return ret; +} + +static +int dlopen_abi1_abi1(void) +{ + int ret = EXIT_SUCCESS; + + ret = dlopen_ust(LTTNG_UST_LIB_ABI1_SO_NAME); + if (ret != EXIT_SUCCESS) + return ret; + + ret = dlopen_ust(LTTNG_UST_LIB_ABI1_SO_NAME); + + return ret; +} + +static +void usage(char **argv) +{ + printf("Usage: %s \n", argv[0]); + printf(" test_type: abi0, abi1, abi0_abi1, abi1_abi0, abi1_abi1\n"); +} + +int main(int argc, char **argv) +{ + int ret = EXIT_SUCCESS; + const char *test_type; + + if (argc != 2) { + usage(argv); + return EXIT_FAILURE; + } else { + test_type = argv[1]; + } + + printf("This application is NOT linked on liblttng-ust.\n"); + + if (strcmp(test_type, "abi0") == 0) + ret = dlopen_abi0(); + else if (strcmp(test_type, "abi1") == 0) + ret = dlopen_abi1(); + else if (strcmp(test_type, "abi0_abi1") == 0) + ret = dlopen_abi0_abi1(); + else if (strcmp(test_type, "abi1_abi0") == 0) + ret = dlopen_abi1_abi0(); + else if (strcmp(test_type, "abi1_abi1") == 0) + ret = dlopen_abi1_abi1(); + else { + usage(argv); + ret = EXIT_FAILURE; + } + + return ret; +} diff --git a/tests/regression/abi0-conflict/app_ust.c b/tests/regression/abi0-conflict/app_ust.c new file mode 100644 index 00000000..d9c17b6a --- /dev/null +++ b/tests/regression/abi0-conflict/app_ust.c @@ -0,0 +1,43 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2021 Michael Jeanson + */ + +#include +#include +#include +#include + +#include "./libzero.h" +#include "./libone.h" + +#define LTTNG_UST_TRACEPOINT_DEFINE +#include "ust_tests_hello.h" + +int main(void) +{ + int i, netint; + long values[] = { 1, 2, 3 }; + char text[10] = "test"; + double dbl = 2.0; + float flt = 2222.0; + bool mybool = 123; /* should print "1" */ + + printf("This application is linked on liblttng-ust.\n"); + +#ifdef USE_LIBZERO + libzero(); +#endif +#ifdef USE_LIBONE + libone(); +#endif + + for (i = 0; i < 10; i++) { + netint = htonl(i); + lttng_ust_tracepoint(ust_tests_hello, tptest, i, netint, values, + text, strlen(text), dbl, flt, mybool); + } + + return 0; +} diff --git a/tests/regression/abi0-conflict/app_ust_dlopen.c b/tests/regression/abi0-conflict/app_ust_dlopen.c new file mode 100644 index 00000000..ad9d1b29 --- /dev/null +++ b/tests/regression/abi0-conflict/app_ust_dlopen.c @@ -0,0 +1,143 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2021 Michael Jeanson + */ + +#include +#include +#include +#include +#include +#include +#include + +#define LTTNG_UST_TRACEPOINT_DEFINE +#include "ust_tests_hello.h" + +#define LTTNG_UST_LIB_ABI0_SO_NAME "libfakeust0.so" +#define LTTNG_UST_LIB_ABI1_SO_NAME "liblttng-ust.so.1" + +static +int dlopen_ust(const char *lib_soname) +{ + int ret = EXIT_SUCCESS; + void *handle; + + handle = dlopen(lib_soname, RTLD_NOW | RTLD_GLOBAL); + if (!handle) { + printf("Error: dlopen of liblttng-ust shared library (%s).\n", lib_soname); + ret = EXIT_FAILURE; + } else { + printf("Success: dlopen of liblttng-ust shared library (%s).\n", lib_soname); + } + + return ret; +} + +static +int dlopen_abi0(void) +{ + return dlopen_ust(LTTNG_UST_LIB_ABI0_SO_NAME); +} + +static +int dlopen_abi1(void) +{ + return dlopen_ust(LTTNG_UST_LIB_ABI1_SO_NAME); +} + +static +int dlopen_abi0_abi1(void) +{ + int ret = EXIT_SUCCESS; + + ret = dlopen_ust(LTTNG_UST_LIB_ABI0_SO_NAME); + if (ret != EXIT_SUCCESS) + return ret; + + ret = dlopen_ust(LTTNG_UST_LIB_ABI1_SO_NAME); + + return ret; +} + +static +int dlopen_abi1_abi0(void) +{ + int ret = EXIT_SUCCESS; + + ret = dlopen_ust(LTTNG_UST_LIB_ABI1_SO_NAME); + if (ret != EXIT_SUCCESS) + return ret; + + ret = dlopen_ust(LTTNG_UST_LIB_ABI0_SO_NAME); + + return ret; +} + +static +int dlopen_abi1_abi1(void) +{ + int ret = EXIT_SUCCESS; + + ret = dlopen_ust(LTTNG_UST_LIB_ABI1_SO_NAME); + if (ret != EXIT_SUCCESS) + return ret; + + ret = dlopen_ust(LTTNG_UST_LIB_ABI1_SO_NAME); + + return ret; +} + +static +void usage(char **argv) +{ + printf("Usage: %s \n", argv[0]); + printf(" test_type: abi0, abi1, abi0_abi1, abi1_abi0, abi1_abi1\n"); +} + +int main(int argc, char **argv) +{ + int ret = EXIT_SUCCESS; + const char *test_type; + + int i, netint; + long values[] = { 1, 2, 3 }; + char text[10] = "test"; + double dbl = 2.0; + float flt = 2222.0; + bool mybool = 123; /* should print "1" */ + + + if (argc != 2) { + usage(argv); + return EXIT_FAILURE; + } else { + test_type = argv[1]; + } + + printf("This application is linked on liblttng-ust.\n"); + + if (strcmp(test_type, "abi0") == 0) + ret = dlopen_abi0(); + else if (strcmp(test_type, "abi1") == 0) + ret = dlopen_abi1(); + else if (strcmp(test_type, "abi0_abi1") == 0) + ret = dlopen_abi0_abi1(); + else if (strcmp(test_type, "abi1_abi0") == 0) + ret = dlopen_abi1_abi0(); + else if (strcmp(test_type, "abi1_abi1") == 0) + ret = dlopen_abi1_abi1(); + else { + usage(argv); + ret = EXIT_FAILURE; + } + + for (i = 0; i < 10; i++) { + netint = htonl(i); + lttng_ust_tracepoint(ust_tests_hello, tptest, i, netint, values, + text, strlen(text), dbl, flt, mybool); + } + + return ret; +} diff --git a/tests/regression/abi0-conflict/fake-ust.c b/tests/regression/abi0-conflict/fake-ust.c new file mode 100644 index 00000000..f47cdc25 --- /dev/null +++ b/tests/regression/abi0-conflict/fake-ust.c @@ -0,0 +1,37 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2021 Michael Jeanson + */ + +#include +#include + +#include "./fake-ust.h" + +void init_usterr(void) +{ + fprintf(stderr, "libfakeust0: init_usterr() called.\n"); +} + +/* + * The symbol used by liblttng-ust.so.1 to detect liblttng-ust.so.0 in a + * process. + */ +int ltt_probe_register(struct lttng_probe_desc *desc __attribute__((unused))) +{ + fprintf(stderr, "libfakeust0: ltt_probe_register() called.\n"); + return 0; +} + +/* + * This constructor calls the 'init_usterr' canary function which is provided + * by liblttng-ust.so.1. + */ +static +void fake_ust_ctor(void) + __attribute__((constructor)); +static void fake_ust_ctor(void) +{ + init_usterr(); +} diff --git a/tests/regression/abi0-conflict/fake-ust.h b/tests/regression/abi0-conflict/fake-ust.h new file mode 100644 index 00000000..f784806d --- /dev/null +++ b/tests/regression/abi0-conflict/fake-ust.h @@ -0,0 +1,18 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2021 Michael Jeanson + */ + +#define LTTNG_UST_PROBE_DESC_PADDING 12 +struct lttng_probe_desc { + char padding[LTTNG_UST_PROBE_DESC_PADDING]; +}; + +void init_usterr(void); + +/* + * The symbol used by liblttng-ust.so.1 to detect liblttng-ust.so.0 in a + * process. + */ +int ltt_probe_register(struct lttng_probe_desc *desc); diff --git a/tests/regression/abi0-conflict/libone.c b/tests/regression/abi0-conflict/libone.c new file mode 100644 index 00000000..089b7e8e --- /dev/null +++ b/tests/regression/abi0-conflict/libone.c @@ -0,0 +1,23 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2021 Michael Jeanson + */ + +#include +#include + +#include "./libone.h" + +/* + * Dummy function to ensure we are properly linked on liblttng-ust.so.1. + */ +void libone_dummy(void) +{ + lttng_ust_after_setns(); +} + +void libone(void) +{ + printf("libone: this is libone()\n"); +} diff --git a/tests/regression/abi0-conflict/libone.h b/tests/regression/abi0-conflict/libone.h new file mode 100644 index 00000000..120623f7 --- /dev/null +++ b/tests/regression/abi0-conflict/libone.h @@ -0,0 +1,8 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2021 Michael Jeanson + */ + +void libone_dummy(void); +void libone(void); diff --git a/tests/regression/abi0-conflict/libzero.c b/tests/regression/abi0-conflict/libzero.c new file mode 100644 index 00000000..83f648c2 --- /dev/null +++ b/tests/regression/abi0-conflict/libzero.c @@ -0,0 +1,25 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2021 Michael Jeanson + */ + +#include + +#include "./libzero.h" +#include "./fake-ust.h" + +/* + * Dummy function to ensure we are properly linked on libfakeust0. + */ +int libzero_dummy(void) +{ + struct lttng_probe_desc probe_desc; + + return ltt_probe_register(&probe_desc); +} + +void libzero(void) +{ + printf("libzero: this is libzero()\n"); +} diff --git a/tests/regression/abi0-conflict/libzero.h b/tests/regression/abi0-conflict/libzero.h new file mode 100644 index 00000000..ad9f3677 --- /dev/null +++ b/tests/regression/abi0-conflict/libzero.h @@ -0,0 +1,8 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2021 Michael Jeanson + */ + +int libzero_dummy(void); +void libzero(void); diff --git a/tests/regression/abi0-conflict/test_abi0_conflict b/tests/regression/abi0-conflict/test_abi0_conflict new file mode 100755 index 00000000..e79e3772 --- /dev/null +++ b/tests/regression/abi0-conflict/test_abi0_conflict @@ -0,0 +1,129 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1-only + +if [ "x${UST_TESTS_SRCDIR:-}" != "x" ]; then + UTILSSH="$UST_TESTS_SRCDIR/utils/utils.sh" +else + UTILSSH="$(dirname "$0")/../../utils/utils.sh" +fi + +# shellcheck source=../../utils/utils.sh +source "$UTILSSH" + +# shellcheck source=../../utils/tap.sh +source "$UST_TESTS_SRCDIR/utils/tap.sh" + +CURDIR="${UST_TESTS_BUILDDIR}/regression/abi0-conflict" + +LIBFAKEUST0_PATH="${CURDIR}/.libs" +LIBFAKEUST0="${LIBFAKEUST0_PATH}/libfakeust0.so" + +LIBUST1_PATH="${UST_TESTS_BUILDDIR}/../src/lib/lttng-ust/.libs/" +LIBUST1="${LIBUST1_PATH}/liblttng-ust.so.1" + +STD_OUTPUT="/dev/null" +STD_ERROR="/dev/null" + +# Force abort on CRIT() to detect ABI conflicts +export LTTNG_UST_ABORT_ON_CRITICAL=1 + +plan_tests 22 + +### +## LD_PRELOAD tests +### + +diag "LD_PRELOAD" + +## App NOT linked on liblttn-ust + +"${CURDIR}/app_noust" >"$STD_OUTPUT" 2>"$STD_ERROR" +ok $? "LD_PRELOAD: no-ust app works" + +LD_PRELOAD="${LIBFAKEUST0}" "${CURDIR}/app_noust" >"$STD_OUTPUT" 2>"$STD_ERROR" +ok $? "LD_PRELOAD: no-ust app with abi0 preload succeeds" + +LD_PRELOAD="${LIBFAKEUST0}:${LIBUST1}" "${CURDIR}/app_noust" >"$STD_OUTPUT" 2>"$STD_ERROR" +isnt $? 0 "LD_PRELOAD: no-ust app with abi0 and abi1 preload fails" + +LD_PRELOAD="${LIBUST1}:${LIBFAKEUST0}" "${CURDIR}/app_noust" >"$STD_OUTPUT" 2>"$STD_ERROR" +isnt $? 0 "LD_PRELOAD: no-ust app with abi1 and abi0 preload fails" + + +## App linked on liblttn-ust.so.1 + +"${CURDIR}/app_ust" >"$STD_OUTPUT" 2>"$STD_ERROR" +ok $? "LD_PRELOAD: ust app works" + +LD_PRELOAD="${LIBFAKEUST0}" "${CURDIR}/app_ust" >"$STD_OUTPUT" 2>"$STD_ERROR" +isnt $? 0 "LD_PRELOAD: ust app with abi0 preload fails" + +LD_PRELOAD="${LIBFAKEUST0}:${LIBUST1}" "${CURDIR}/app_ust" >"$STD_OUTPUT" 2>"$STD_ERROR" +isnt $? 0 "LD_PRELOAD: ust app with abi0 and abi1 preload fails" + +LD_PRELOAD="${LIBUST1}:${LIBFAKEUST0}" "${CURDIR}/app_ust" >"$STD_OUTPUT" 2>"$STD_ERROR" +isnt $? 0 "LD_PRELOAD: ust app with abi1 and abi0 preload fails" + + +### +## dlopen tests +### + +diag "dlopen" + +## App NOT linked on liblttn-ust + +LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_noust_dlopen" abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" +ok $? "dlopen: no-ust app works" + +LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_noust_dlopen" abi1_abi1 >"$STD_OUTPUT" 2>"$STD_ERROR" +ok $? "dlopen: no-ust app with abi1 and abi1 succeeds" + +LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_noust_dlopen" abi0_abi1 >"$STD_OUTPUT" 2>"$STD_ERROR" +isnt $? 0 "dlopen: no-ust app with abi0 and abi1 fails" + +LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_noust_dlopen" abi1_abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" +isnt $? 0 "dlopen: no-ust app with abi1 and abi0 fails" + +## App linked on liblttn-ust.so.1 + +LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi1 >"$STD_OUTPUT" 2>"$STD_ERROR" +ok $? "dlopen: ust app works" + +LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" +isnt $? 0 "dlopen: ust app with abi0 fails" + +LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi0_abi1 >"$STD_OUTPUT" 2>"$STD_ERROR" +isnt $? 0 "dlopen: ust app with abi0 and abi1 fails" + +LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi1_abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" +isnt $? 0 "dlopen: ust app with abi1 and abi0 fails" + + +### +## Indirect linking +### + +diag "Indirect linking" + +## App NOT linked on liblttn-ust + +"${CURDIR}/app_noust_indirect_abi0" >"$STD_OUTPUT" 2>"$STD_ERROR" +ok $? "indirect: no-ust app with abi0 succeeds" + +"${CURDIR}/app_noust_indirect_abi1" >"$STD_OUTPUT" 2>"$STD_ERROR" +ok $? "indirect: no-ust app with abi1 succeeds" + +"${CURDIR}/app_noust_indirect_abi0_abi1" >"$STD_OUTPUT" 2>"$STD_ERROR" +isnt $? 0 "indirect: no-ust app with abi0 and abi1 fails" + +## App linked on liblttn-ust + +"${CURDIR}/app_ust_indirect_abi0" >"$STD_OUTPUT" 2>"$STD_ERROR" +isnt $? 0 "indirect: ust app with abi0 fails" + +"${CURDIR}/app_ust_indirect_abi1" >"$STD_OUTPUT" 2>"$STD_ERROR" +ok $? "indirect: ust app with abi1 succeeds" + +"${CURDIR}/app_ust_indirect_abi0_abi1" >"$STD_OUTPUT" 2>"$STD_ERROR" +isnt $? 0 "indirect: ust app with abi0 and abi1 fails" diff --git a/tests/regression/abi0-conflict/tp.c b/tests/regression/abi0-conflict/tp.c new file mode 100644 index 00000000..98669b6e --- /dev/null +++ b/tests/regression/abi0-conflict/tp.c @@ -0,0 +1,8 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright (C) 2011 Mathieu Desnoyers + */ + +#define LTTNG_UST_TRACEPOINT_CREATE_PROBES +#include "ust_tests_hello.h" diff --git a/tests/regression/abi0-conflict/ust_tests_hello.h b/tests/regression/abi0-conflict/ust_tests_hello.h new file mode 100644 index 00000000..639c7c9f --- /dev/null +++ b/tests/regression/abi0-conflict/ust_tests_hello.h @@ -0,0 +1,64 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright (C) 2011 Mathieu Desnoyers + */ + +#undef LTTNG_UST_TRACEPOINT_PROVIDER +#define LTTNG_UST_TRACEPOINT_PROVIDER ust_tests_hello + +#if !defined(_TRACEPOINT_UST_TESTS_HELLO_H) || defined(LTTNG_UST_TRACEPOINT_HEADER_MULTI_READ) +#define _TRACEPOINT_UST_TESTS_HELLO_H + +#include +#include +#include + +LTTNG_UST_TRACEPOINT_EVENT(ust_tests_hello, tptest, + LTTNG_UST_TP_ARGS(int, anint, int, netint, long *, values, + char *, text, size_t, textlen, + double, doublearg, float, floatarg, + bool, boolarg), + LTTNG_UST_TP_FIELDS( + lttng_ust_field_integer(int, intfield, anint) + lttng_ust_field_integer_hex(int, intfield2, anint) + lttng_ust_field_integer(long, longfield, anint) + lttng_ust_field_integer_network(int, netintfield, netint) + lttng_ust_field_integer_network_hex(int, netintfieldhex, netint) + lttng_ust_field_array_nowrite(long, arrfield1z, values, 3) + lttng_ust_field_array(long, blah, values, 3) + lttng_ust_field_array(long, arrfield1, values, 3) + lttng_ust_field_array_hex(long, arrfield1_hex, values, 3) + lttng_ust_field_array_network(long, arrfield1_network, values, 3) + lttng_ust_field_array_network_hex(long, arrfield1_network_hex, values, 3) + lttng_ust_field_array_text(char, arrfield2, text, 10) + lttng_ust_field_sequence(char, seqfield1, text, + size_t, textlen) + lttng_ust_field_sequence_nowrite(char, seqfield1z, text, + size_t, textlen) + lttng_ust_field_sequence_hex(char, seqfield1_hex, text, + size_t, textlen) + lttng_ust_field_sequence_text(char, seqfield2, text, + size_t, textlen) + lttng_ust_field_sequence_network(long, seqfield_network_3, values, + size_t, 3) + lttng_ust_field_string(stringfield, text) + lttng_ust_field_float(float, floatfield, floatarg) + lttng_ust_field_float(double, doublefield, doublearg) + lttng_ust_field_integer(bool, boolfield, boolarg) + lttng_ust_field_integer_nowrite(int, filterfield, anint) + ) +) + +LTTNG_UST_TRACEPOINT_EVENT(ust_tests_hello, tptest_sighandler, + LTTNG_UST_TP_ARGS(), + LTTNG_UST_TP_FIELDS() +) + +#endif /* _TRACEPOINT_UST_TESTS_HELLO_H */ + +#undef LTTNG_UST_TRACEPOINT_INCLUDE +#define LTTNG_UST_TRACEPOINT_INCLUDE "./ust_tests_hello.h" + +/* This part must be outside ifdef protection */ +#include -- 2.34.1