From: Jérémie Galarneau Date: Fri, 9 Jul 2021 17:00:48 +0000 (-0400) Subject: Tests: add hidden trigger visibility test X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=1cc00241a01b1f3a1ed54fc43457bb798724f36e;p=lttng-tools.git Tests: add hidden trigger visibility test Add a regression test for the previous commit that verifies that internal triggers used by the session daemon to implement various features (automatic session rotations based on their consumed size, in this instance) are not visible to users of liblttng-ctl. The test is written in C to use the library directly. This is needed since the `lttng` client filters-out anonymous triggers and thus, would not allow us to see those triggers since they are anonymous by default. Signed-off-by: Jérémie Galarneau Change-Id: I1b8fca648953b8cba49a9888593b3486457d01b2 --- diff --git a/configure.ac b/configure.ac index 102a1d0f4..b175ef52b 100644 --- a/configure.ac +++ b/configure.ac @@ -1151,6 +1151,7 @@ AC_CONFIG_FILES([ tests/regression/tools/trigger/start-stop/Makefile tests/regression/tools/trigger/utils/Makefile tests/regression/tools/trigger/name/Makefile + tests/regression/tools/trigger/hidden/Makefile tests/regression/ust/Makefile tests/regression/ust/nprocesses/Makefile tests/regression/ust/high-throughput/Makefile diff --git a/tests/regression/Makefile.am b/tests/regression/Makefile.am index 58269d15d..dac6f84e6 100644 --- a/tests/regression/Makefile.am +++ b/tests/regression/Makefile.am @@ -54,7 +54,8 @@ TESTS = tools/base-path/test_ust \ tools/trigger/test_add_trigger_cli \ tools/trigger/test_list_triggers_cli \ tools/trigger/test_remove_trigger_cli \ - tools/trigger/name/test_trigger_name_backwards_compat + tools/trigger/name/test_trigger_name_backwards_compat \ + tools/trigger/hidden/test_hidden_trigger if HAVE_LIBLTTNG_UST_CTL SUBDIRS += ust diff --git a/tests/regression/tools/trigger/Makefile.am b/tests/regression/tools/trigger/Makefile.am index fe5dd9744..110f86cc9 100644 --- a/tests/regression/tools/trigger/Makefile.am +++ b/tests/regression/tools/trigger/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS=utils start-stop rate-policy name +SUBDIRS=utils start-stop rate-policy name hidden noinst_SCRIPTS = test_add_trigger_cli \ test_list_triggers_cli \ diff --git a/tests/regression/tools/trigger/hidden/Makefile.am b/tests/regression/tools/trigger/hidden/Makefile.am new file mode 100644 index 000000000..ef383fde9 --- /dev/null +++ b/tests/regression/tools/trigger/hidden/Makefile.am @@ -0,0 +1,28 @@ +# SPDX-License-Identifier: GPL-2.0-only + +AM_CPPFLAGS += -I$(top_srcdir)/tests/utils/ -I$(srcdir) + +LIBTAP=$(top_builddir)/tests/utils/tap/libtap.la +LIBLTTNG_CTL=$(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la + +noinst_PROGRAMS = hidden_trigger +hidden_trigger_CFLAGS = $(AM_CFLAGS) +hidden_trigger_SOURCES = hidden_trigger.c +hidden_trigger_LDADD = $(LIBTAP) $(LIBLTTNG_CTL) + +noinst_SCRIPTS = test_hidden_trigger +EXTRA_DIST = test_hidden_trigger + +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/trigger/hidden/hidden_trigger.c b/tests/regression/tools/trigger/hidden/hidden_trigger.c new file mode 100644 index 000000000..3ff126562 --- /dev/null +++ b/tests/regression/tools/trigger/hidden/hidden_trigger.c @@ -0,0 +1,181 @@ +/* + * trigger_name.c + * + * Test that hidden triggers are not visible to liblttng-ctl. + * + * Copyright (C) 2021 Jérémie Galarneau + * + * SPDX-License-Identifier: MIT + * + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#define TEST_COUNT 1 + +#define TEST_SESSION_NAME "test_session" +#define TEST_CHANNEL_NAME "test_channel" + +static +int get_registered_triggers_count(void) +{ + int ret; + enum lttng_error_code ret_code; + enum lttng_trigger_status trigger_status; + struct lttng_triggers *triggers = NULL; + unsigned int trigger_count; + + ret_code = lttng_list_triggers(&triggers); + if (ret_code != LTTNG_OK) { + fail("Failed to list triggers"); + ret = -1; + goto end; + } + + trigger_status = lttng_triggers_get_count(triggers, &trigger_count); + if (trigger_status != LTTNG_TRIGGER_STATUS_OK) { + fail("Failed to get count of triggers returned by listing"); + ret = -1; + goto end; + } + + ret = (int) trigger_count; + +end: + lttng_triggers_destroy(triggers); + return ret; +} + +static +int setup_session_with_size_rotation_schedule(const char *session_output_path) +{ + int ret; + struct lttng_session_descriptor *session_desriptor = NULL; + enum lttng_error_code ret_code; + struct lttng_handle ust_channel_handle = { + .session_name = TEST_SESSION_NAME, + .domain.type = LTTNG_DOMAIN_UST, + .domain.buf_type = LTTNG_BUFFER_PER_UID, + }; + struct lttng_channel channel_cfg = { + .name = TEST_CHANNEL_NAME, + .enabled = 1, + .attr.overwrite = -1, + .attr.subbuf_size = sysconf(_SC_PAGESIZE) * 8, + .attr.num_subbuf = 8, + .attr.output = LTTNG_EVENT_MMAP, + }; + enum lttng_rotation_status rotation_status; + struct lttng_rotation_schedule *rotation_schedule = NULL; + + session_desriptor = lttng_session_descriptor_local_create( + TEST_SESSION_NAME, session_output_path); + if (!session_desriptor) { + fail("Failed to create session descriptor for session `%s`", + TEST_SESSION_NAME); + ret = -1; + goto end; + } + + ret_code = lttng_create_session_ext(session_desriptor); + if (ret_code != LTTNG_OK) { + fail("Failed to create session `%s`: %s", TEST_SESSION_NAME, + lttng_strerror(-ret_code)); + ret = -1; + goto end; + } + + ret = lttng_enable_channel(&ust_channel_handle, &channel_cfg); + if (ret) { + fail("Failed to enable channel `%s`: %s", TEST_CHANNEL_NAME, + lttng_strerror(ret)); + ret = -1; + goto end; + } + + ret = lttng_start_tracing(TEST_SESSION_NAME); + if (ret) { + fail("Failed to start session `%s`: %s", TEST_SESSION_NAME, + lttng_strerror(ret)); + ret = -1; + goto end; + } + + rotation_schedule = lttng_rotation_schedule_size_threshold_create(); + if (!rotation_schedule) { + fail("Failed to create rotation schedule descriptor"); + ret = -1; + goto end; + } + + /* + * The rotation schedule size threshold doesn't matter; no event rules + * were specified so the session consumed size should not grow over + * time. + */ + rotation_status = lttng_rotation_schedule_size_threshold_set_threshold( + rotation_schedule, sysconf(_SC_PAGESIZE) * 4096); + if (rotation_status != LTTNG_ROTATION_STATUS_OK) { + fail("Failed to set size threshold of session rotation schedule"); + ret = -1; + goto end; + } + + rotation_status = lttng_session_add_rotation_schedule( + TEST_SESSION_NAME, rotation_schedule); + if (rotation_status != LTTNG_ROTATION_STATUS_OK) { + fail("Failed to set size-based rotation schedule on session `%s`", + TEST_SESSION_NAME); + ret = -1; + goto end; + } + + ret = 0; +end: + lttng_session_descriptor_destroy(session_desriptor); + lttng_rotation_schedule_destroy(rotation_schedule); + return ret; +} + +int main(int argc, const char **argv) +{ + int ret; + + if (argc != 2) { + fail("Missing trace path"); + goto end; + } + + plan_tests(TEST_COUNT); + + if (get_registered_triggers_count() != 0) { + fail("Session daemon already has registered triggers, bailing out"); + goto end; + } + + ret = setup_session_with_size_rotation_schedule(argv[1]); + if (ret) { + goto end; + } + + ok(get_registered_triggers_count() == 0, + "No triggers visible while session has an enabled size-based rotation schedule"); + + ret = lttng_destroy_session(TEST_SESSION_NAME); + if (ret) { + fail("Failed to destroy session `%s`", TEST_SESSION_NAME); + goto end; + } +end: + return exit_status(); +} diff --git a/tests/regression/tools/trigger/hidden/test_hidden_trigger b/tests/regression/tools/trigger/hidden/test_hidden_trigger new file mode 100755 index 000000000..0adce61eb --- /dev/null +++ b/tests/regression/tools/trigger/hidden/test_hidden_trigger @@ -0,0 +1,26 @@ +#!/bin/bash +# +# Copyright (C) 2021 Jérémie Galarneau +# +# SPDX-License-Identifier: LGPL-2.1-only + +TEST_DESC="Triggers - Hidden internal triggers" + +CURDIR=$(dirname "$0")/ +TESTDIR=${CURDIR}/../../../.. +TRACE_PATH=$(mktemp --tmpdir -d -t tmp.test_trigger_hidden.XXXXXX) + +# shellcheck source=../../../../utils/utils.sh +source "$TESTDIR/utils/utils.sh" + +HIDDEN_TRIGGER_BIN="$CURDIR/hidden_trigger" + +# MUST set TESTDIR before calling those functions + +start_lttng_sessiond_notap + +$HIDDEN_TRIGGER_BIN "$TRACE_PATH" + +stop_lttng_sessiond_notap + +rm -rf "$TRACE_PATH"