| 1 | #!/bin/bash |
| 2 | # SPDX-License-Identifier: LGPL-2.1-only |
| 3 | |
| 4 | if [ "x${UST_TESTS_SRCDIR:-}" != "x" ]; then |
| 5 | UTILSSH="$UST_TESTS_SRCDIR/utils/utils.sh" |
| 6 | else |
| 7 | UTILSSH="$(dirname "$0")/../../utils/utils.sh" |
| 8 | fi |
| 9 | |
| 10 | # shellcheck source=../../utils/utils.sh |
| 11 | source "$UTILSSH" |
| 12 | |
| 13 | # shellcheck source=../../utils/tap.sh |
| 14 | source "$UST_TESTS_SRCDIR/utils/tap.sh" |
| 15 | |
| 16 | CURDIR="${UST_TESTS_BUILDDIR}/regression/abi0-conflict" |
| 17 | |
| 18 | LIBFAKEUST0_PATH="${CURDIR}/.libs" |
| 19 | LIBFAKEUST0="${LIBFAKEUST0_PATH}/libfakeust0.so" |
| 20 | |
| 21 | LIBUST1_PATH="${UST_TESTS_BUILDDIR}/../src/lib/lttng-ust/.libs/" |
| 22 | LIBUST1="${LIBUST1_PATH}/liblttng-ust.so.1" |
| 23 | |
| 24 | STD_OUTPUT="/dev/null" |
| 25 | STD_ERROR="/dev/null" |
| 26 | |
| 27 | NUM_TESTS=22 |
| 28 | |
| 29 | # Set this variable to disable tests that rely on a library using a symbol from |
| 30 | # the global offset table even if it provides its own copy, which is the |
| 31 | # default behavior on Linux. This happens when using the '-Bsymbolic-functions' |
| 32 | # linker flag. |
| 33 | UST_TESTS_LD_SYMBOLIC_FUNC=${UST_TESTS_LD_SYMBOLIC_FUNC:-} |
| 34 | |
| 35 | # On FreeBSD, symbol resolution when dlopening a shared object will always |
| 36 | # favor symbols local to this shared object and thus our canary function will |
| 37 | # never be called which breaks our abi conflict detection when abi1 is loaded |
| 38 | # first. |
| 39 | if [ "$UST_OS_TYPE" = "freebsd" ]; then |
| 40 | UST_TESTS_LD_SYMBOLIC_FUNC=1 |
| 41 | fi |
| 42 | |
| 43 | if [ "$UST_TESTS_LD_SYMBOLIC_FUNC" != "" ]; then |
| 44 | NUM_TESTS=$((NUM_TESTS - 4)) |
| 45 | fi |
| 46 | |
| 47 | # Force abort on CRIT() to detect ABI conflicts |
| 48 | export LTTNG_UST_ABORT_ON_CRITICAL=1 |
| 49 | |
| 50 | plan_tests $NUM_TESTS |
| 51 | |
| 52 | ### |
| 53 | ## LD_PRELOAD tests |
| 54 | ### |
| 55 | |
| 56 | diag "LD_PRELOAD" |
| 57 | |
| 58 | ## App NOT linked on liblttng-ust |
| 59 | |
| 60 | "${CURDIR}/app_noust" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 61 | ok $? "LD_PRELOAD: no-ust app works" |
| 62 | |
| 63 | LD_PRELOAD="${LIBFAKEUST0}" "${CURDIR}/app_noust" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 64 | ok $? "LD_PRELOAD: no-ust app with abi0 preload succeeds" |
| 65 | |
| 66 | LD_PRELOAD="${LIBFAKEUST0}:${LIBUST1}" "${CURDIR}/app_noust" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 67 | isnt $? 0 "LD_PRELOAD: no-ust app with abi0 and abi1 preload fails" |
| 68 | |
| 69 | LD_PRELOAD="${LIBUST1}:${LIBFAKEUST0}" "${CURDIR}/app_noust" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 70 | isnt $? 0 "LD_PRELOAD: no-ust app with abi1 and abi0 preload fails" |
| 71 | |
| 72 | |
| 73 | ## App linked on liblttng-ust.so.1 |
| 74 | |
| 75 | "${CURDIR}/app_ust" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 76 | ok $? "LD_PRELOAD: ust app works" |
| 77 | |
| 78 | LD_PRELOAD="${LIBFAKEUST0}" "${CURDIR}/app_ust" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 79 | isnt $? 0 "LD_PRELOAD: ust app with abi0 preload fails" |
| 80 | |
| 81 | LD_PRELOAD="${LIBFAKEUST0}:${LIBUST1}" "${CURDIR}/app_ust" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 82 | isnt $? 0 "LD_PRELOAD: ust app with abi0 and abi1 preload fails" |
| 83 | |
| 84 | LD_PRELOAD="${LIBUST1}:${LIBFAKEUST0}" "${CURDIR}/app_ust" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 85 | isnt $? 0 "LD_PRELOAD: ust app with abi1 and abi0 preload fails" |
| 86 | |
| 87 | |
| 88 | ### |
| 89 | ## dlopen tests |
| 90 | ### |
| 91 | |
| 92 | diag "dlopen" |
| 93 | |
| 94 | ## App NOT linked on liblttng-ust |
| 95 | |
| 96 | LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_noust_dlopen" abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 97 | ok $? "dlopen: no-ust app works" |
| 98 | |
| 99 | LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_noust_dlopen" abi1_abi1 >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 100 | ok $? "dlopen: no-ust app with abi1 and abi1 succeeds" |
| 101 | |
| 102 | LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_noust_dlopen" abi0_abi1 >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 103 | isnt $? 0 "dlopen: no-ust app with abi0 and abi1 fails" |
| 104 | |
| 105 | if [ "$UST_TESTS_LD_SYMBOLIC_FUNC" = "" ]; then |
| 106 | LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_noust_dlopen" abi1_abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 107 | isnt $? 0 "dlopen: no-ust app with abi1 and abi0 fails" |
| 108 | fi |
| 109 | |
| 110 | ## App linked on liblttng-ust.so.1 |
| 111 | |
| 112 | LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi1 >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 113 | ok $? "dlopen: ust app works" |
| 114 | |
| 115 | if [ "$UST_TESTS_LD_SYMBOLIC_FUNC" = "" ]; then |
| 116 | LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 117 | isnt $? 0 "dlopen: ust app with abi0 fails" |
| 118 | |
| 119 | LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi0_abi1 >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 120 | isnt $? 0 "dlopen: ust app with abi0 and abi1 fails" |
| 121 | |
| 122 | LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi1_abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 123 | isnt $? 0 "dlopen: ust app with abi1 and abi0 fails" |
| 124 | fi |
| 125 | |
| 126 | |
| 127 | ### |
| 128 | ## Indirect linking |
| 129 | ### |
| 130 | |
| 131 | diag "Indirect linking" |
| 132 | |
| 133 | ## App NOT linked on liblttng-ust |
| 134 | |
| 135 | "${CURDIR}/app_noust_indirect_abi0" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 136 | ok $? "indirect: no-ust app with abi0 succeeds" |
| 137 | |
| 138 | "${CURDIR}/app_noust_indirect_abi1" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 139 | ok $? "indirect: no-ust app with abi1 succeeds" |
| 140 | |
| 141 | "${CURDIR}/app_noust_indirect_abi0_abi1" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 142 | isnt $? 0 "indirect: no-ust app with abi0 and abi1 fails" |
| 143 | |
| 144 | ## App linked on liblttng-ust |
| 145 | |
| 146 | "${CURDIR}/app_ust_indirect_abi0" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 147 | isnt $? 0 "indirect: ust app with abi0 fails" |
| 148 | |
| 149 | "${CURDIR}/app_ust_indirect_abi1" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 150 | ok $? "indirect: ust app with abi1 succeeds" |
| 151 | |
| 152 | "${CURDIR}/app_ust_indirect_abi0_abi1" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 153 | isnt $? 0 "indirect: ust app with abi0 and abi1 fails" |