From: Kienan Stewart Date: Thu, 26 Oct 2023 20:08:27 +0000 (-0400) Subject: tests: Add tests for LTTNG_UST_APP_PATH and LTTNG_UST_CTL_PATH X-Git-Url: http://git.lttng.org./?a=commitdiff_plain;h=39c3cb7445a9505648730719aedcad602973cf1e;p=lttng-tools.git tests: Add tests for LTTNG_UST_APP_PATH and LTTNG_UST_CTL_PATH test_blocking_mode: Verifies that the sessiond starts (or doesn't start) appropriately depending on the combination of path settings in conjuction with `LTTNG_UST_ALLOW_BLOCKING` and `--blocking-timeout`. test_path_separators:Path separators: Verifies the behaviour of the sessiond and applications with multiple `LTTNG_UST_APP_PATH`s and multiple `LTTNG_UST_CTL_PATHS`, including the verification of Java JUL and Python agents. test_ust_app_ctl_paths: Verifies the sessiond and traced applications with different combinations of `LTTNG_UST_APP_PATH` and `LTTNG_UST_CTL_PATH` settings. Signed-off-by: Kienan Stewart Signed-off-by: Jérémie Galarneau Change-Id: I9f25cdc20fd482cdcc71294aadff3a2a6b34c01e --- diff --git a/configure.ac b/configure.ac index d8980edcd..ee4ee5aa7 100644 --- a/configure.ac +++ b/configure.ac @@ -1333,6 +1333,7 @@ AC_CONFIG_FILES([ tests/regression/ust/rotation-destroy-flush/Makefile tests/regression/ust/blocking/Makefile tests/regression/ust/namespaces/Makefile + tests/regression/ust/ust-app-ctl-paths/Makefile tests/regression/ust/ust-constructor/Makefile tests/stress/Makefile tests/unit/Makefile diff --git a/tests/regression/Makefile.am b/tests/regression/Makefile.am index 8afb7600a..3dda0a2b6 100644 --- a/tests/regression/Makefile.am +++ b/tests/regression/Makefile.am @@ -94,6 +94,9 @@ TESTS += ust/before-after/test_before_after \ ust/blocking/test_blocking \ ust/multi-lib/test_multi_lib \ ust/rotation-destroy-flush/test_rotation_destroy_flush \ + ust/ust-app-ctl-paths/test_blocking \ + ust/ust-app-ctl-paths/test_path_separators \ + ust/ust-app-ctl-paths/test_ust_app_ctl_paths \ ust/ust-constructor/test_ust_constructor_c_dynamic.py \ ust/ust-constructor/test_ust_constructor_c_static.py \ ust/ust-constructor/test_ust_constructor_cpp_dynamic.py \ @@ -103,7 +106,8 @@ TESTS += ust/before-after/test_before_after \ tools/trigger/rate-policy/test_ust_rate_policy if TEST_JAVA_JUL_AGENT -TESTS += ust/java-jul/test_java_jul +TESTS += ust/java-jul/test_java_jul \ + ust/java-jul/test_ust_app_ctl_path_separators.sh endif # TEST_JAVA_JUL_AGENT if TEST_JAVA_LOG4J_AGENT diff --git a/tests/regression/ust/Makefile.am b/tests/regression/ust/Makefile.am index dd8186f9a..997e1415d 100644 --- a/tests/regression/ust/Makefile.am +++ b/tests/regression/ust/Makefile.am @@ -25,6 +25,7 @@ SUBDIRS = \ periodical-metadata-flush \ rotation-destroy-flush \ type-declarations \ + ust-app-ctl-paths \ ust-constructor if HAVE_OBJCOPY diff --git a/tests/regression/ust/java-jul/Makefile.am b/tests/regression/ust/java-jul/Makefile.am index 5748c7ce1..671b5c174 100644 --- a/tests/regression/ust/java-jul/Makefile.am +++ b/tests/regression/ust/java-jul/Makefile.am @@ -2,8 +2,12 @@ JAVAROOT = . -noinst_SCRIPTS = test_java_jul JTestLTTng.java -EXTRA_DIST = test_java_jul JTestLTTng.java +noinst_SCRIPTS = test_java_jul \ + JTestLTTng.java \ + test_ust_app_ctl_path_separators.sh +EXTRA_DIST = test_java_jul \ + JTestLTTng.java \ + test_ust_app_ctl_path_separators.sh if TEST_JAVA_JUL_AGENT dist_noinst_JAVA = JTestLTTng.java diff --git a/tests/regression/ust/java-jul/test_ust_app_ctl_path_separators.sh b/tests/regression/ust/java-jul/test_ust_app_ctl_path_separators.sh new file mode 100755 index 000000000..754a481e4 --- /dev/null +++ b/tests/regression/ust/java-jul/test_ust_app_ctl_path_separators.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# +# Copyright (C) 2024 Kienan Stewart +# +# SPDX-License-Identifier: LGPL-2.1-only +# + +TEST_DESC="Verifies the behaviour of the sessiond and Java JUL agents with multiple LTTNG_UST_APP_PATHs and multiple LTTNG_UST_CTL_PATHS" +NUM_TESTS=10 + +CURDIR="$(dirname "${0}")" +TESTDIR="${CURDIR}/../../../" + +# shellcheck source=../../../utils/utils.sh +source "${TESTDIR}/utils/utils.sh" + +SESSION_NAME="ust-app-ctl-path-separator" +CHANNEL_NAME="ust-app-ctl-path-separator" + +TESTAPP_JAVA_JUL="JTestLTTng" +EVENT_NAMES_JAVA_JUL="JTestLTTng" +JAVA_JUL_CP="${CURDIR}:${CLASSPATH}" + +function test_app_path_with_separators_java_jul +{ + CTL_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.ctl.XXXXXX")" + CTL_PATH2="$(mktemp -d -t "tmp.${FUNCNAME[0]}.ctl2.XXXXXX")" + TRACE_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.trace.XXXXXX")" + + env_vars=( + LTTNG_UST_CTL_PATH="${CTL_PATH}:${CTL_PATH2}" + ) + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars[*]}" start_lttng_sessiond + + create_lttng_session_ok "${SESSION_NAME}" "${TRACE_PATH}" + enable_ust_lttng_channel_ok "${SESSION_NAME}" "${CHANNEL_NAME}" + enable_jul_lttng_event "${SESSION_NAME}" "${EVENT_NAMES_JAVA_JUL}" "${CHANNEL_NAME}" + start_lttng_tracing_ok "${SESSION_NAME}" + + # Run app + pushd "${TESTAPP_JAVA_JUL_DIR}" + LTTNG_UST_APP_PATH="${CTL_PATH}:${CTL_PATH2}" java -cp "${JAVA_JUL_CP}" -Djava.library.path="${LD_LIBRARY_PATH}:/usr/local/lib:/usr/lib:/usr/local/lib64/:/usr/lib64/" "${TESTAPP_JAVA_JUL}" 100 0 + popd + + stop_lttng_tracing_ok "${SESSION_NAME}" + destroy_lttng_session_ok "${SESSION_NAME}" --no-wait + + validate_trace_count "lttng_jul:event" "${TRACE_PATH}" 100 0 + + # shellcheck disable=SC2119 + stop_lttng_sessiond + + # Cleanup + rm -rf "${CTL_PATH}" "${CTL_PATH2}" "${TRACE_PATH}" +} + +plan_tests "${NUM_TESTS}" +print_test_banner "${TEST_DESC}" +bail_out_if_no_babeltrace +test_app_path_with_separators_java_jul diff --git a/tests/regression/ust/python-logging/test_python_logging.in b/tests/regression/ust/python-logging/test_python_logging.in index 0bb7ef24d..28e5f524b 100755 --- a/tests/regression/ust/python-logging/test_python_logging.in +++ b/tests/regression/ust/python-logging/test_python_logging.in @@ -25,7 +25,7 @@ run_test=@RUN_PYTHON_AGENT_TEST@ if [[ -z "$run_test" ]]; then NUM_TESTS=1 else - NUM_TESTS=$(((199 * ${#python_versions[@]})+2)) + NUM_TESTS=$(((208 * ${#python_versions[@]})+2)) fi source $TESTDIR/utils/utils.sh @@ -714,6 +714,40 @@ function test_python_trigger_notify_action rm -f "${tmp_expected_stdout}" } + +function test_app_path_with_separators +{ + local PYTHON="${1}" + + diag "Test LTTNG_UST_APP_PATH and LTTNG_UST_CTL_PATH with separators" + CTL_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.ctl.XXXXXX")" + CTL_PATH2="$(mktemp -d -t "tmp.${FUNCNAME[0]}.ctl2.XXXXXX")" + TRACE_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.trace.XXXXXX")" + + env_vars=( + LTTNG_UST_CTL_PATH="${CTL_PATH}:${CTL_PATH2}" + ) + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars[*]}" start_lttng_sessiond + + create_lttng_session_ok "${SESSION_NAME}" "${TRACE_PATH}" + enable_python_lttng_event_loglevel "${SESSION_NAME}" "${EVENT_NAME}" "INFO" + start_lttng_tracing_ok "${SESSION_NAME}" + + LTTNG_UST_APP_PATH="${CTL_PATH}:${CTL_PATH2}" "${PYTHON}" "$TESTAPP_PATH/$TESTAPP_BIN" -n 100 -s 0 + + stop_lttng_tracing_ok "${SESSION_NAME}" + destroy_lttng_session_ok "${SESSION_NAME}" --no-wait + + validate_trace_count "${EVENT_NAME}" "${TRACE_PATH}" 100 0 + + # shellcheck disable=SC2119 + stop_lttng_sessiond + + # Cleanup + rm -rf "${CTL_PATH}" "${CTL_PATH2}" "${TRACE_PATH}" +} + plan_tests $NUM_TESTS print_test_banner "$TEST_DESC" @@ -748,6 +782,9 @@ skip $skip_agent "Python agent test skipped." $NUM_TESTS || test_python_filter_loglevel test_python_trigger_notify_action ) + standalone_tests=( + test_app_path_with_separators + ) for python_version in ${python_versions[*]}; @@ -765,4 +802,11 @@ skip $skip_agent "Python agent test skipped." $NUM_TESTS || done done stop_lttng_sessiond + + for python_version in "${python_versions[@]}"; do + for fct_test in "${standalone_tests[@]}"; do + diag "(Python $python_version)" + "${fct_test}" "${python_version}" + done + done } diff --git a/tests/regression/ust/ust-app-ctl-paths/Makefile.am b/tests/regression/ust/ust-app-ctl-paths/Makefile.am new file mode 100644 index 000000000..14ebb683d --- /dev/null +++ b/tests/regression/ust/ust-app-ctl-paths/Makefile.am @@ -0,0 +1,23 @@ +# SPDX-License-Identifier: GPL-2.0-only + +noinst_SCRIPTS = test_blocking \ + test_path_separators \ + test_ust_app_ctl_paths + +EXTRA_DIST = test_blocking \ + test_path_separators \ + test_ust_app_ctl_paths + +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/ust/ust-app-ctl-paths/test_blocking b/tests/regression/ust/ust-app-ctl-paths/test_blocking new file mode 100755 index 000000000..ed587938f --- /dev/null +++ b/tests/regression/ust/ust-app-ctl-paths/test_blocking @@ -0,0 +1,181 @@ +#!/bin/bash +# +# Copyright (C) 2023 Kienan Stewart +# +# SPDX-License-Identifier: LGPL-2.1-only +# + +TEST_DESC="Verifies that the sessiond starts (or doesn't start) appropriately depending on the combination of path settings in conjuction with LTTNG_UST_ALLOW_BLOCKING and '--blocking-timeout'" + +CURDIR="$(dirname "${0}")" +TESTDIR="${CURDIR}/../../../" + +NUM_TESTS=33 + +# shellcheck source=../../../utils/utils.sh +source "${TESTDIR}/utils/utils.sh" + +TESTAPP="${TESTDIR}/utils/testapp/gen-ust-events/gen-ust-events" +SESSION_NAME="ust-blocking" +CHANNEL_NAME="ust-blocking" +EVENT_NAMES="tp:tptest" + +function test_blocking_mode_app_path() +{ + APP_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.app.XXXXXX")" + TRACE_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.trace.XXXXXX")" + + env_vars=( + LTTNG_UST_ALLOW_BLOCKING=1 + LTTNG_UST_APP_PATH="${APP_PATH}" + ) + + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars[*]}" start_lttng_sessiond + create_lttng_session_ok "${SESSION_NAME}" "${TRACE_PATH}" + enable_ust_lttng_channel_ok "${SESSION_NAME}" "${CHANNEL_NAME}" "--blocking-timeout=inf" + enable_ust_lttng_event_ok "${SESSION_NAME}" "--all" "${CHANNEL_NAME}" + start_lttng_tracing_ok "${SESSION_NAME}" + "${TESTAPP}" -i 100 -w 0 + stop_lttng_tracing_ok "${SESSION_NAME}" + destroy_lttng_session_ok "${SESSION_NAME}" --no-wait + validate_trace_count "${EVENT_NAMES}" "${TRACE_PATH}" 100 + + # shellcheck disable=SC2119 + stop_lttng_sessiond + rm -rf "${APP_PATH}" "${TRACE_PATH}" +} + +function test_blocking_mode_defaults_paths() +{ + diag "Test starting sessiond in blocking with neither LTTNG_UST_APP_PATH nor LTTNG_UST_CTL_PATH set" + env_vars=( + LTTNG_UST_ALLOW_BLOCKING=1 + ) + + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars[*]}" start_lttng_sessiond_fail + # shellcheck disable=SC2119 + stop_lttng_sessiond_cleanup +} + +function test_blocking_mode_ctl_path() +{ + diag "Test starting sessiond in blocking with LTTNG_UST_CTL_PATH set" + CTL_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.ctl.XXXXXX")" + TRACE_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.trace.XXXXXX")" + + env_vars=( + LTTNG_UST_ALLOW_BLOCKING=1 + LTTNG_UST_CTL_PATH="${CTL_PATH}" + ) + + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars[*]}" start_lttng_sessiond + create_lttng_session_ok "${SESSION_NAME}" "${TRACE_PATH}" + enable_ust_lttng_channel_ok "${SESSION_NAME}" "${CHANNEL_NAME}" "--blocking-timeout=inf" + enable_ust_lttng_event_ok "${SESSION_NAME}" "--all" "${CHANNEL_NAME}" + start_lttng_tracing_ok "${SESSION_NAME}" + LTTNG_UST_APP_PATH="${CTL_PATH}" "${TESTAPP}" -i 100 -w 0 + stop_lttng_tracing_ok "${SESSION_NAME}" + destroy_lttng_session_ok "${SESSION_NAME}" --no-wait + validate_trace_count "${EVENT_NAMES}" "${TRACE_PATH}" 100 + + # shellcheck disable=SC2119 + stop_lttng_sessiond + rm -rf "${CTL_PATH}" "${TRACE_PATH}" +} + +function test_blocking_mode_with_different_paths() +{ + diag "Test starting sessiond in blocking with different LTTNG_UST_APP_PATH and LTTNG_UST_CTL_PATHs" + CTL_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.ctl.XXXXXX")" + APP_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.app.XXXXXX")" + TRACE_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.trace.XXXXXX")" + + env_vars=( + LTTNG_UST_ALLOW_BLOCKING=1 + LTTNG_UST_CTL_PATH="${CTL_PATH}" + LTTNG_UST_APP_PATH="${APP_PATH}" + ) + + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars[*]}" start_lttng_sessiond + create_lttng_session_ok "${SESSION_NAME}" "${TRACE_PATH}" + enable_ust_lttng_channel_ok "${SESSION_NAME}" "${CHANNEL_NAME}" "--blocking-timeout=inf" + enable_ust_lttng_event_ok "${SESSION_NAME}" "--all" "${CHANNEL_NAME}" + start_lttng_tracing_ok "${SESSION_NAME}" + LTTNG_UST_APP_PATH="${CTL_PATH}" "${TESTAPP}" -i 100 -w 0 + stop_lttng_tracing_ok "${SESSION_NAME}" + destroy_lttng_session_ok "${SESSION_NAME}" --no-wait + validate_trace_count "${EVENT_NAMES}" "${TRACE_PATH}" 100 + + # shellcheck disable=SC2119 + stop_lttng_sessiond + rm -rf "${CTL_PATH}" "${TRACE_PATH}" "${APP_PATH}" +} + +function test_blocking_mode_with_same_paths() +{ + diag "Test starting sessiond in blocking with the same LTTNG_UST_APP_PATH and LTTNG_UST_CTL_PATHs" + CTL_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.XXXXXX")" + env_vars=( + LTTNG_UST_CTL_PATH="${CTL_PATH}" + LTTNG_UST_APP_PATH="${CTL_PATH}" + LTTNG_UST_ALLOW_BLOCKING=1 + ) + + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars[*]}" start_lttng_sessiond_fail + # shellcheck disable=SC2119 + stop_lttng_sessiond_cleanup + + rm -rf "${CTL_PATH}" +} + +function test_blocking_mode_app_path_is_default_ctl_path() { + diag "Test starting sessiond when it's app path happens to match the default ctl path" + APP_PATH="$(lttng_default_rundir)" + + env_vars=( + LTTNG_UST_APP_PATH="${APP_PATH}" + LTTNG_UST_ALLOW_BLOCKING=1 + ) + + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars[*]}" start_lttng_sessiond_fail + # shellcheck disable=SC2119 + stop_lttng_sessiond_cleanup +} + +function test_blocking_mode_ctl_path_is_default_app_path() { + diag "Test starting sessiond when it's ctl path happens to match the default ctl path" + CTL_PATH="$(lttng_default_rundir)" + + env_vars=( + LTTNG_UST_CTL_PATH="${APP_PATH}" + LTTNG_UST_ALLOW_BLOCKING=1 + ) + + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars[*]}" start_lttng_sessiond_fail + # shellcheck disable=SC2119 + stop_lttng_sessiond_cleanup +} + +TESTS=( + test_blocking_mode_default_paths + test_blocking_mode_app_path + test_blocking_mode_ctl_path + test_blocking_mode_with_same_paths + test_blocking_mode_with_different_paths + test_blocking_mode_app_path_is_default_ctl_path + test_blocking_mode_ctl_path_is_default_app_path +) + +plan_tests "${NUM_TESTS}" +print_test_banner "${TEST_DESC}" + +for TEST in "${TESTS[@]}" ; do + "${TEST}" +done diff --git a/tests/regression/ust/ust-app-ctl-paths/test_path_separators b/tests/regression/ust/ust-app-ctl-paths/test_path_separators new file mode 100755 index 000000000..07a081d86 --- /dev/null +++ b/tests/regression/ust/ust-app-ctl-paths/test_path_separators @@ -0,0 +1,101 @@ +#!/bin/bash +# +# Copyright (C) 2023 Kienan Stewart +# +# SPDX-License-Identifier: LGPL-2.1-only +# + +TEST_DESC="Verifies the behaviour of the sessiond and applications with multiple LTTNG_UST_APP_PATHs and multiple LTTNG_UST_CTL_PATHS, including the verification oPython agents" + +CURDIR="$(dirname "${0}")" +TESTDIR="${CURDIR}/../../../" + +# shellcheck source=../../../utils/utils.sh +source "${TESTDIR}/utils/utils.sh" + +TESTAPP="${TESTDIR}/utils/testapp/gen-ust-events/gen-ust-events" +EVENT_NAMES="tp:tptest" +SESSION_NAME="ust-app-ctl-path-separator" +CHANNEL_NAME="ust-app-ctl-path-separator" + +NUM_TESTS=20 + +# +# There is no escaping of the path separator +# + +function test_ctl_path_with_separators +{ + CTL_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.ctl.XXXXXX")" + CTL_PATH2="$(mktemp -d -t "tmp.${FUNCNAME[0]}.ctl2.XXXXXX")" + TRACE_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.trace.XXXXXX")" + + # The current implementation should ignore paths other than the first + env_vars=( + LTTNG_UST_CTL_PATH="${CTL_PATH}:${CTL_PATH2}" + ) + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars[*]}" start_lttng_sessiond + create_lttng_session_ok "${SESSION_NAME}" "${TRACE_PATH}" + enable_ust_lttng_channel_ok "${SESSION_NAME}" "${CHANNEL_NAME}" + enable_ust_lttng_event_ok "${SESSION_NAME}" "${EVENT_NAMES}" "${CHANNEL_NAME}" + start_lttng_tracing_ok "${SESSION_NAME}" + + LTTNG_UST_APP_PATH="${CTL_PATH}" "${TESTAPP}" -i 100 -w 0 + LTTNG_UST_APP_PATH="${CTL_PATH2}" "${TESTAPP}" -i 100 -w 0 + + stop_lttng_tracing_ok "${SESSION_NAME}" + destroy_lttng_session_ok "${SESSION_NAME}" --no-wait + + validate_trace_count "${EVENT_NAMES}" "${TRACE_PATH}" 100 + + # shellcheck disable=SC2119 + stop_lttng_sessiond + + # Cleanup + rm -rf "${CTL_PATH}" "${CTL_PATH2}" "${TRACE_PATH}" +} + +function test_app_path_with_separators +{ + # The current implementation should ignore paths other than the first + CTL_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.ctl.XXXXXX")" + CTL_PATH2="$(mktemp -d -t "tmp.${FUNCNAME[0]}.ctl2.XXXXXX")" + TRACE_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.trace.XXXXXX")" + + env_vars=( + LTTNG_UST_CTL_PATH="${CTL_PATH}" + ) + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars[*]}" start_lttng_sessiond + create_lttng_session_ok "${SESSION_NAME}" "${TRACE_PATH}" + enable_ust_lttng_channel_ok "${SESSION_NAME}" "${CHANNEL_NAME}" + enable_ust_lttng_event_ok "${SESSION_NAME}" "${EVENT_NAMES}" "${CHANNEL_NAME}" + start_lttng_tracing_ok "${SESSION_NAME}" + + LTTNG_UST_APP_PATH="${CTL_PATH}:${CTL_PATH2}" "${TESTAPP}" -i 100 -w 0 + + stop_lttng_tracing_ok "${SESSION_NAME}" + destroy_lttng_session_ok "${SESSION_NAME}" --no-wait + + validate_trace_count "${EVENT_NAMES}" "${TRACE_PATH}" 100 + + # shellcheck disable=SC2119 + stop_lttng_sessiond + + # Cleanup + rm -rf "${CTL_PATH}" "${CTL_PATH2}" "${TRACE_PATH}" +} + +plan_tests "${NUM_TESTS}" +print_test_banner "${TEST_DESC}" +bail_out_if_no_babeltrace + +TESTS=( + test_app_path_with_separators + test_ctl_path_with_separators +) + +for TEST in "${TESTS[@]}" ; do + "${TEST}" +done diff --git a/tests/regression/ust/ust-app-ctl-paths/test_ust_app_ctl_paths b/tests/regression/ust/ust-app-ctl-paths/test_ust_app_ctl_paths new file mode 100755 index 000000000..d5c43870f --- /dev/null +++ b/tests/regression/ust/ust-app-ctl-paths/test_ust_app_ctl_paths @@ -0,0 +1,363 @@ +#!/bin/bash +# +# Copyright (C) 2023 Kienan Stewart +# +# SPDX-License-Identifier: LGPL-2.1-only +# + +TEST_DESC="Verifies the sessiond and traced applications with different combinations of LTTNG_UST_APP_PATH and LTTNG_UST_CTL_PATH settings." + +CURDIR="$(dirname "${0}")" +TESTDIR="${CURDIR}/../../../" + +NUM_TESTS=98 + +# shellcheck source=../../../utils/utils.sh +source "${TESTDIR}/utils/utils.sh" + +TESTAPP="${TESTDIR}/utils/testapp/gen-ust-events/gen-ust-events" +EVENT_NAMES="tp:tptest" +SESSION_NAME="ust-app-ctl-path" +CHANNEL_NAME="ust-app-ctl-path" + +function test_sessiond_started_before_app() +{ + CTL_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.ctl.XXXXXX")" + TRACE_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.trace.XXXXXX")" + env_vars=( + LTTNG_UST_CTL_PATH="${CTL_PATH}" + ) + + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars[*]}" start_lttng_sessiond + create_lttng_session_ok "${SESSION_NAME}" "${TRACE_PATH}" + enable_ust_lttng_channel_ok "${SESSION_NAME}" "${CHANNEL_NAME}" + enable_ust_lttng_event_ok "${SESSION_NAME}" "--all" "${CHANNEL_NAME}" + start_lttng_tracing_ok "${SESSION_NAME}" + LTTNG_UST_APP_PATH="${CTL_PATH}" "${TESTAPP}" -i 100 -w 0 + stop_lttng_tracing_ok "${SESSION_NAME}" + destroy_lttng_session_ok "${SESSION_NAME}" --no-wait + # shellcheck disable=SC2119 + stop_lttng_sessiond + + validate_trace_count "${EVENT_NAMES}" "${TRACE_PATH}" 100 + rm -rf "${TRACE_PATH}" "${CTL_PATH}" +} + +function test_sessiond_started_after_app() +{ + CTL_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.ctl.XXXXXX")" + TRACE_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.trace.XXXXXX")" + SYNC_FILE=$(mktemp -d) + env_vars=( + LTTNG_UST_CTL_PATH="${CTL_PATH}" + ) + + LTTNG_UST_APP_PATH="${CTL_PATH}" "${TESTAPP}" -b "${SYNC_FILE}/a" & + APP_PID="${!}" + + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars[*]}" start_lttng_sessiond + create_lttng_session_ok "${SESSION_NAME}" "${TRACE_PATH}" + enable_ust_lttng_channel_ok "${SESSION_NAME}" "${CHANNEL_NAME}" + enable_ust_lttng_event_ok "${SESSION_NAME}" "--all" "${CHANNEL_NAME}" + start_lttng_tracing_ok "${SESSION_NAME}" + touch "${SYNC_FILE}/a" + wait "${APP_PID}" + stop_lttng_tracing_ok "${SESSION_NAME}" + destroy_lttng_session_ok "${SESSION_NAME}" --no-wait + # shellcheck disable=SC2119 + stop_lttng_sessiond + + validate_trace "${EVENT_NAMES}" "${TRACE_PATH}" + rm -rf "${TRACE_PATH}" "${CTL_PATH}" "${SYNC_FILE}" +} + +function test_multi_sessiond() +{ + # Multiple root sessionds cannot be started + if [ "${UID}" == "0" ] ; then + skip 0 "Multiple root sessionds aren't supported" 28 + return + fi + + N_SESSIOND=3 + CTL_PATH_BASE="$(mktemp -d -t "tmp.${FUNCNAME[0]}.ctl.XXXXXX")" + TRACE_PATH_BASE="$(mktemp -d -t "tmp.${FUNCNAME[0]}.trace.XXXXXX")" + LTTNG_HOME_BASE="$(mktemp -d -t "tmp.${FUNCNAME[0]}.lttng-home.XXXXXX")" + LTTNG_HOME_ORIG="${LTTNG_HOME}" + + for i in $(seq 1 "${N_SESSIOND}") ; do + CTL_PATH="${CTL_PATH_BASE}/$i" + TRACE_PATH="${TRACE_PATH_BASE}/$i" + LTTNG_HOME="${LTTNG_HOME_BASE}/$i" + mkdir -p "${CTL_PATH}" "${TRACE_PATH}" "${LTTNG_HOME}" + env_vars=( + LTTNG_HOME="${LTTNG_HOME}" + LTTNG_UST_CTL_PATH="${CTL_PATH}" + TEST_IGNORE_EXISTING_SESSIOND=1 + ) + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars[*]}" start_lttng_sessiond + export "${env_vars[@]}" + create_lttng_session_ok "${SESSION_NAME}" "${TRACE_PATH}" + enable_ust_lttng_channel_ok "${SESSION_NAME}" "${CHANNEL_NAME}" + enable_ust_lttng_event_ok "${SESSION_NAME}" "--all" "${CHANNEL_NAME}" + start_lttng_tracing_ok "${SESSION_NAME}" + unset LTTNG_HOME + unset LTTNG_UST_CTL_PATH + done + for i in $(seq 1 "${N_SESSIOND}") ; do + LTTNG_UST_APP_PATH="${CTL_PATH_BASE}/$i" "${TESTAPP}" -i 100 -w 0 + done + for i in $(seq 1 "${N_SESSIOND}") ; do + env_vars=( + LTTNG_HOME="${LTTNG_HOME_BASE}/$i" + ) + export "${env_vars[@]}" + stop_lttng_tracing_ok "${SESSION_NAME}" + destroy_lttng_session_ok "${SESSION_NAME}" --no-wait + unset LTTNG_HOME + validate_trace_count "${EVENT_NAMES}" "${TRACE_PATH_BASE}/$i" 100 + done + # shellcheck disable=SC2119 + stop_lttng_sessiond + + # Cleanup + rm -rf "${TRACE_PATH_BASE}" "${CTL_PATH_BASE}" "${LTTNG_HOME_BASE}" + unset TEST_IGNORE_EXISTING_SESSIOND LTTNG_UST_CTL_PATH + if [ "${LTTNG_HOME_ORIG}" != "" ] ; then + export LTTNG_HOME="${LTTNG_HOME_ORIG}" + fi +} + +function test_multi_sessiond_default() +{ + diag "Verifies that the lttng_session_daemon_alive()/set_session_daemon_path() in liblttng is coherent with LTTNG_UST_CTL_PATH" + + # Multiple root sessionds cannot be started + if [ "${UID}" == "0" ] ; then + skip 0 "Multiple root sessionds aren't supported" 11 + return + fi + + LTTNG_HOME_B="$(mktemp -d -t "tmp.${FUNCNAME[0]}.lttng-home.XXXXXX")" + TRACE_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.trace.XXXXXX")" + LTTNG_HOME_ORIG="${LTTNG_HOME}" + + # shellcheck disable=SC2119 + start_lttng_sessiond + + LTTNG_UST_APP_PATH="${LTTNG_HOME_B}/.lttng" + env_vars_b=( + LTTNG_HOME="${LTTNG_HOME_B}" + TEST_IGNORE_EXISTING_SESSIOND=1 + ) + export "${env_vars_b[@]}" + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars_b[*]}" start_lttng_sessiond + + create_lttng_session_ok "${SESSION_NAME}" "${TRACE_PATH}" + enable_ust_lttng_channel_ok "${SESSION_NAME}" "${CHANNEL_NAME}" + enable_ust_lttng_event_ok "${SESSION_NAME}" "--all" "${CHANNEL_NAME}" + start_lttng_tracing_ok "${SESSION_NAME}" + LTTNG_UST_APP_PATH="${LTTNG_UST_APP_PATH}" "${TESTAPP}" -i 100 -w 0 + stop_lttng_tracing_ok "${SESSION_NAME}" + destroy_lttng_session_ok "${SESSION_NAME}" --no-wait + unset LTTNG_HOME LTTNG_RUNDIR + validate_trace_count "${EVENT_NAMES}" "${TRACE_PATH}" 100 + + # shellcheck disable=SC2119 + stop_lttng_sessiond + + unset LTTNG_HOME TEST_IGNORE_EXISTING_SESSIOND + if [ "${LTTNG_HOME_ORIG}" != "" ] ; then + export LTTNG_HOME="${LTTNG_HOME_ORIG}" + fi + rm -rf "${LTTNG_HOME_B}" "${TRACE_PATH}" +} + +function test_trace_another_sessiond() +{ + if [ "${UID}" == "0" ] ; then + skip 0 "Multiple root sessionds aren't supported" 18 + return + fi + + CTL_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.ctl.XXXXXX")" + TRACE_PATH_A="$(mktemp -d -t "tmp.${FUNCNAME[0]}.trace_a.XXXXXX")" + TRACE_PATH_B="$(mktemp -d -t "tmp.${FUNCNAME[0]}.trace_b.XXXXXX")" + LTTNG_HOME_A="$(mktemp -d -t "tmp.${FUNCNAME[0]}.lttng-home.XXXXXX")" + LTTNG_HOME_ORIG="${LTTNG_HOME}" + + # This sessiond will trace a new one that will be started + env_vars_a=( + LTTNG_UST_CTL_PATH="${CTL_PATH}" + LTTNG_HOME="${LTTNG_HOME_A}" + TEST_IGNORE_EXISTING_SESSIOND=1 + ) + export "${env_vars_a[@]}" + + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars_a[*]}" start_lttng_sessiond + create_lttng_session_ok "${SESSION_NAME}" "${TRACE_PATH_A}" + enable_ust_lttng_channel_ok "${SESSION_NAME}" "${CHANNEL_NAME}" + enable_ust_lttng_event_ok "${SESSION_NAME}" "--all" "${CHANNEL_NAME}" + start_lttng_tracing_ok "${SESSION_NAME}" + unset LTTNG_HOME LTTNG_UST_CTL_PATH + + if [ "${LTTNG_HOME_ORIG}" != "" ] ; then + export LTTNG_HOME="${LTTNG_HOME_ORIG}" + fi + # This sessiond will be traced + env_vars_b=( + LTTNG_UST_APP_PATH="${CTL_PATH}" + TEST_IGNORE_EXISTING_SESSIOND=1 + LD_PRELOAD="liblttng-ust-fd.so:liblttng-ust-fork.so" + ) + + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars_b[*]}" start_lttng_sessiond + create_lttng_session_ok "${SESSION_NAME}" "${TRACE_PATH_B}" + enable_ust_lttng_channel_ok "${SESSION_NAME}" "${CHANNEL_NAME}" + enable_ust_lttng_event_ok "${SESSION_NAME}" "--all" "${CHANNEL_NAME}" + start_lttng_tracing_ok "${SESSION_NAME}" + + "${TESTAPP}" -i 100 -w 0 + + stop_lttng_tracing_ok "${SESSION_NAME}" + destroy_lttng_session_ok "${SESSION_NAME}" --no-wait + validate_trace_count "${EVENT_NAMES}" "${TRACE_PATH_B}" 100 + + # Confirm that we get traced data from the subordinate sessiond + export LTTNG_HOME="${LTTNG_HOME_A}" + stop_lttng_tracing_ok "${SESSION_NAME}" + destroy_lttng_session_ok "${SESSION_NAME}" --no-wait + EVENT_COUNT="$("${BABELTRACE_BIN}" "${TRACE_PATH_A}" | wc -l)" + isnt "${EVENT_COUNT}" "0" "More than zero events were expected" + + # shellcheck disable=SC2119 + stop_lttng_sessiond + + # Cleanup + rm -rf "${TRACE_PATH_A}" "{$TRACE_PATH_B}" "${LTTNG_HOME_A}" "${CTL_PATH}" + unset LTTNG_HOME LTTNG_UST_CTL_PATH TEST_IGNORE_EXISTING_SESSIOND + if [ "${LTTNG_HOME_ORIG}" != "" ] ; then + export LTTNG_HOME="${LTTNG_HOME_ORIG}" + fi +} + +function test_trace_self_default_paths() +{ + TRACE_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.trace.XXXXXX")" + + env_vars=( + LD_PRELOAD="liblttng-ust-fd.so:liblttng-ust-fork.so" + # Don't block during registration + LTTNG_UST_REGISTER_TIMEOUT=0 + ) + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars[*]}" start_lttng_sessiond + create_lttng_session_ok "${SESSION_NAME}" "${TRACE_PATH}" + enable_ust_lttng_channel_ok "${SESSION_NAME}" "${CHANNEL_NAME}" + add_context_ust_ok "${SESSION_NAME}" "${CHANNEL_NAME}" vpid -t procname + enable_ust_lttng_event_ok "${SESSION_NAME}" "--all" "${CHANNEL_NAME}" -x "${EVENT_NAMES}" + start_lttng_tracing_ok "${SESSION_NAME}" + stop_lttng_tracing_ok "${SESSION_NAME}" + destroy_lttng_session_ok "${SESSION_NAME}" + + LTTNG_UST_APP_PATH="${CTL_PATH}" \ + LTTNG_UST_WITHOUT_BADDR_STATEDUMP=1 \ + LTTNG_UST_WITHOUT_PROCNAME_STATEDUMP=1 \ + "${TESTAPP}" -i 100 -w 0 & + APP_PID="${!}" + + EVENT_COUNT="$("${BABELTRACE_BIN}" "${TRACE_PATH}" | grep -v "vpid = ${APP_PID}" -c)" + isnt "${EVENT_COUNT}" "0" "More than zero events were expected" + + # shellcheck disable=SC2119 + stop_lttng_sessiond + # Cleanup + rm -rf "${TRACE_PATH}" +} + +function test_trace_self_app_and_ctl_paths() +{ + CTL_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.ctl.XXXXXX")" + TRACE_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.trace.XXXXXX")" + + env_vars=( + LTTNG_UST_APP_PATH="${CTL_PATH}" + LTTNG_UST_CTL_PATH="${CTL_PATH}" + LD_PRELOAD="liblttng-ust-fd.so:liblttng-ust-fork.so" + # Don't block during registration + LTTNG_UST_REGISTER_TIMEOUT=0 + ) + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars[*]}" start_lttng_sessiond + create_lttng_session_ok "${SESSION_NAME}" "${TRACE_PATH}" + enable_ust_lttng_channel_ok "${SESSION_NAME}" "${CHANNEL_NAME}" + add_context_ust_ok "${SESSION_NAME}" "${CHANNEL_NAME}" vpid -t procname + enable_ust_lttng_event_ok "${SESSION_NAME}" "--all" "${CHANNEL_NAME}" -x "${EVENT_NAMES}" + start_lttng_tracing_ok "${SESSION_NAME}" + + LTTNG_UST_APP_PATH="${CTL_PATH}" \ + LTTNG_UST_WITHOUT_BADDR_STATEDUMP=1 \ + LTTNG_UST_WITHOUT_PROCNAME_STATEDUMP=1 \ + "${TESTAPP}" -i 100 -w 0 & + APP_PID="${!}" + + stop_lttng_tracing_ok "${SESSION_NAME}" + destroy_lttng_session_ok "${SESSION_NAME}" --no-wait + + EVENT_COUNT="$("${BABELTRACE_BIN}" "${TRACE_PATH}" | grep -v "vpid = ${APP_PID}" -c)" + isnt "${EVENT_COUNT}" "0" "More than zero events were expected" + + # shellcheck disable=SC2119 + stop_lttng_sessiond + # Cleanup + rm -rf "${TRACE_PATH}" "${CTL_PATH}" +} + +function test_sessiond_bad_ctl_path() { + diag "Test that starting a sessiond with a LTTNG_UST_CTL_PATH that doesn't exist fails" + CTL_PATH="$(mktemp -d -t "tmp.${FUNCNAME[0]}.ctl.XXXXXX")" + rm -rf "${CTL_PATH}" + + env_vars=( + LTTNG_UST_APP_PATH="${CTL_PATH}" + LTTNG_UST_CTL_PATH="${CTL_PATH}" + ) + # shellcheck disable=SC2119 + LTTNG_SESSIOND_ENV_VARS="${env_vars[*]}" start_lttng_sessiond_fail + LTTNG_UST_APP_PATH="${CTL_PATH}" \ + LTTNG_UST_WITHOUT_BADDR_STATEDUMP=1 \ + LTTNG_UST_WITHOUT_PROCNAME_STATEDUMP=1 \ + "${TESTAPP}" -i 100 -w 0 & + APP_PID="${!}" + wait "${APP_PID}" + ok "${?}" "Test application exited successfully" + + # shellcheck disable=SC2119 + stop_lttng_sessiond_cleanup +} + +plan_tests "${NUM_TESTS}" +print_test_banner "${TEST_DESC}" +bail_out_if_no_babeltrace + +TESTS=( + test_sessiond_started_before_app + test_sessiond_started_after_app + test_multi_sessiond + test_multi_sessiond_default + test_trace_another_sessiond + test_trace_self_default_paths + test_trace_self_app_and_ctl_paths + test_sessiond_bad_ctl_path +) + +for TEST in "${TESTS[@]}" ; do + "${TEST}" + lttng_pgrep "${SESSIOND_MATCH}" +done diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index f4b68089a..26cb3b26a 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -139,6 +139,14 @@ if [ -z "$PGREP" ]; then PGREP=pgrep fi +function lttng_default_rundir () { + if [ "${UID}" == "0" ] ; then + echo "/var/run/lttng" + else + echo "${LTTNG_HOME:-$HOME}/.lttng" + fi +} + function _lttng_client_log_file () { local output_dest="${1}" @@ -956,7 +964,7 @@ function start_lttng_sessiond_opt() : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/"}" export LTTNG_SESSION_CONFIG_XSD_PATH - if [ -z "$(lttng_pgrep "${SESSIOND_MATCH}")" ]; then + if [ -z "$(lttng_pgrep "${SESSIOND_MATCH}")" ] || [ -n "${TEST_IGNORE_EXISTING_SESSIOND}" ]; then # Have a load path ? if [ -n "$load_path" ]; then diag "env $env_vars --load $load_path --background $consumerd ${opts[*]}" @@ -994,6 +1002,8 @@ function start_lttng_sessiond_opt() gdb --batch-silent -ex "target remote localhost:${LTTNG_TEST_GDBSERVER_SESSIOND_PORT}" -ex "continue" -ex "disconnect" & fi fi + + return $status fi } @@ -1002,6 +1012,12 @@ function start_lttng_sessiond() start_lttng_sessiond_opt 1 "$@" } +function start_lttng_sessiond_fail() +{ + start_lttng_sessiond_opt 0 "$@" + isnt "${?}" "0" "start_lttng_sessiond_fail" +} + function start_lttng_sessiond_notap() { start_lttng_sessiond_opt 0 "$@" @@ -1510,6 +1526,13 @@ function enable_ust_lttng_event () local event_name="$4" local channel_name=$5 + # Any other arguments are passed to `lttng enable-event` without modification + local enable_event_args=() + if [ "${#}" -gt 5 ] ; then + enable_event_args=("${@:5}") + fi + echo "${enable_event_args[@]}" >&2 + if [ -z $channel_name ]; then # default channel if none specified chan="" @@ -1518,7 +1541,7 @@ function enable_ust_lttng_event () fi _run_lttng_cmd "$(lttng_client_log_file)" "$(lttng_client_err_file)" \ - enable-event "$event_name" $chan -s "$sess_name" -u + enable-event "$event_name" $chan -s "$sess_name" -u "${enable_event_args[@]}" ret=$? if [[ $expected_to_fail -eq "1" ]]; then test $ret -ne "0"