tests: Add test for missing short lived applications
authorKienan Stewart <kstewart@efficios.com>
Tue, 28 May 2024 14:33:07 +0000 (10:33 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 30 Aug 2024 21:09:42 +0000 (17:09 -0400)
Change-Id: I691b9fb2cfae7603e40ca4c668acaff752ba3f28
Signed-off-by: Kienan Stewart <kstewart@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests/regression/Makefile.am
tests/regression/tools/live/Makefile.am
tests/regression/tools/live/test_miss_short_lived_app.py [new file with mode: 0755]

index 1b790b706cc865ff8006021b14b79406146a7f15..5a8eebd9b8434953ceac5ddb2c680e0dcc74e061 100644 (file)
@@ -16,6 +16,7 @@ TESTS = tools/base-path/test_ust \
        tools/health/test_thread_ok \
        tools/live/test_kernel \
        tools/live/test_lttng_kernel \
+       tools/live/test_miss_short_lived_app.py \
        tools/live/test_per_application_leaks.py \
        tools/live/test_ust \
        tools/live/test_ust_tracefile_count \
index 3ad9b7ba35f23e4b5a296c3dc7391acbc6d7e430..a8042f67ddebf72e8b642fad0396497b3964f976 100644 (file)
@@ -9,7 +9,10 @@ noinst_PROGRAMS = live_test
 EXTRA_DIST = test_kernel test_lttng_kernel test_per_application_leaks.py
 
 if HAVE_LIBLTTNG_UST_CTL
-EXTRA_DIST += test_ust test_ust_tracefile_count test_lttng_ust
+EXTRA_DIST += test_lttng_ust \
+       test_miss_short_lived_app.py \
+       test_ust \
+       test_ust_tracefile_count
 endif
 
 live_test_SOURCES = live_test.cpp
diff --git a/tests/regression/tools/live/test_miss_short_lived_app.py b/tests/regression/tools/live/test_miss_short_lived_app.py
new file mode 100755 (executable)
index 0000000..a77bef9
--- /dev/null
@@ -0,0 +1,96 @@
+#!/usr/bin/env python3
+#
+# SPDX-FileCopyrightText: 2024 Kienan Stewart <kstewart@efficios.com>
+# SPDX-LicenseIdentifier: LGPL-2.1-only
+#
+"""
+Test that an attached live viewer doesn't miss streams created for a short lived
+application which ends before the live viewer sees the new streams.
+
+This test tries to mimic the race between destruction and a live viewer's
+GET_NEW_METADATA + GET_NEW_STREAMS commands by immediately destroying the session
+after the traced application terminates.
+
+This is more likely with per-PID buffer allocation, but the underlying mechanism
+also affects per-UID buffers if a new user is created and a short lived application
+run quickly.
+
+When the relayd/live connection isn't working properly, this test will fail only
+occasionally as the underlying mechanism is timing dependant. When working properly,
+the test should always pass when run in a loop.
+"""
+
+import os
+import pathlib
+import subprocess
+import sys
+
+test_utils_import_path = pathlib.Path(__file__).absolute().parents[3] / "utils"
+sys.path.append(str(test_utils_import_path))
+import lttngtest
+
+
+def test_short_lived_ust_app(tap, test_env, buffer_sharing_policy):
+    tap.diagnostic(
+        "test_short_lived_ust_app with buffer sharing policy `{}`".format(
+            buffer_sharing_policy
+        )
+    )
+
+    uid = None
+    user = None
+    if buffer_sharing_policy == lttngtest.lttngctl.BufferSharingPolicy.PerUID:
+        if not (os.getuid() == 0 and test_env.allows_destructive()):
+            tap.skip(
+                "Need to run PerUID test as root with `LTTNG_ENABLE_DESTRUCTIVE_TESTS` properly set to create a dummy user",
+                1,
+            )
+            return
+        (uid, user) = test_env.create_dummy_user()
+    client = lttngtest.LTTngClient(test_env, log=tap.diagnostic)
+    output = lttngtest.NetworkSessionOutputLocation(
+        "net://localhost:{}:{}/".format(
+            test_env.lttng_relayd_control_port, test_env.lttng_relayd_data_port
+        )
+    )
+    session = client.create_session(output=output, live=True)
+    channel = session.add_channel(
+        lttngtest.lttngctl.TracingDomain.User,
+        buffer_sharing_policy=buffer_sharing_policy,
+    )
+    channel.add_recording_rule(lttngtest.lttngctl.UserTracepointEventRule("tp:tptest"))
+    session.start()
+
+    # Connect live viewer
+    viewer = test_env.launch_live_viewer(session.name)
+    viewer.wait_until_connected()
+
+    late_app = test_env.launch_wait_trace_test_application(
+        10, wait_before_exit=False, run_as=user
+    )
+    late_app.trace()
+    late_app.wait_for_tracing_done()
+    late_app.wait_for_exit()
+
+    session.stop()
+    session.destroy()
+    viewer.wait()
+
+    tap.test(
+        len(viewer.messages) == 10,
+        "Live viewer got {} / 10 expected events add exited gracefully".format(
+            len(viewer.messages)
+        ),
+    )
+
+
+tap = lttngtest.TapGenerator(2)
+for buffer_sharing_policy in [
+    lttngtest.lttngctl.BufferSharingPolicy.PerUID,
+    lttngtest.lttngctl.BufferSharingPolicy.PerPID,
+]:
+    with lttngtest.test_environment(
+        log=tap.diagnostic, with_relayd=True, with_sessiond=True
+    ) as test_env:
+        test_short_lived_ust_app(tap, test_env, buffer_sharing_policy)
+sys.exit(0 if tap.is_successful else 1)
This page took 0.026833 seconds and 4 git commands to generate.