Tests: add hidden trigger visibility test
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 9 Jul 2021 17:00:48 +0000 (13:00 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 12 Jul 2021 21:38:52 +0000 (17:38 -0400)
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 <jeremie.galarneau@efficios.com>
Change-Id: I1b8fca648953b8cba49a9888593b3486457d01b2

configure.ac
tests/regression/Makefile.am
tests/regression/tools/trigger/Makefile.am
tests/regression/tools/trigger/hidden/Makefile.am [new file with mode: 0644]
tests/regression/tools/trigger/hidden/hidden_trigger.c [new file with mode: 0644]
tests/regression/tools/trigger/hidden/test_hidden_trigger [new file with mode: 0755]

index 9326151508aeca0a383830d2c2cb623897d780e3..ecc5ce4292257382f03e4dc3a0f19e83fbc70079 100644 (file)
@@ -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
index 58269d15dfb295ec31cb46144ab078782bb6c9b3..dac6f84e6ca192f533ebd736c018c04975d53f05 100644 (file)
@@ -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
index fe5dd974445a62581b05cacddd4da03ffd4e3ce9..110f86cc95512a3384a9b02bf84e58056700a652 100644 (file)
@@ -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 (file)
index 0000000..ef383fd
--- /dev/null
@@ -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 (file)
index 0000000..3ff1265
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+ * trigger_name.c
+ *
+ * Test that hidden triggers are not visible to liblttng-ctl.
+ *
+ * Copyright (C) 2021 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ */
+
+#include <assert.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <tap/tap.h>
+
+#include <common/macros.h>
+#include <lttng/lttng.h>
+
+#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 (executable)
index 0000000..0adce61
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/bash
+#
+# Copyright (C) 2021 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+#
+# 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"
This page took 0.029651 seconds and 4 git commands to generate.