Introduce test_ust_python_agent_vs_tools.py
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Wed, 8 Nov 2017 21:49:28 +0000 (16:49 -0500)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Wed, 8 Nov 2017 21:49:28 +0000 (16:49 -0500)
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
lttng_ivc/apps/python/app.py [new file with mode: 0644]
lttng_ivc/settings.py
lttng_ivc/tests/ust_python_agent_vs_tools/__init__.py [new file with mode: 0644]
lttng_ivc/tests/ust_python_agent_vs_tools/test_ust_python_agent_vs_tools.py [new file with mode: 0644]
lttng_ivc/utils/project.py
lttng_ivc/utils/runtime.py
lttng_ivc/utils/utils.py

diff --git a/lttng_ivc/apps/python/app.py b/lttng_ivc/apps/python/app.py
new file mode 100644 (file)
index 0000000..f8b3081
--- /dev/null
@@ -0,0 +1,28 @@
+import lttngust
+import logging
+import time
+import argparse
+
+parser = argparse.ArgumentParser(description='Python tracing example.')
+parser.add_argument('-i', '--iterations', type=int, help='The number of loop iterations', required=True)
+
+args = parser.parse_args()
+args.iterations
+
+def example(iteration):
+    ch = logging.StreamHandler()
+    ch.setLevel(logging.DEBUG)
+
+    logger = logging.getLogger('pello')
+    logger.addHandler(ch)
+
+    for i in range(iteration):
+        logger.debug('debug message')
+        logger.info('info message')
+        logger.warn('warn message')
+        logger.error('error message')
+        logger.critical('critical message')
+
+
+if __name__ == '__main__':
+    example(args.iterations)
index 7f1785aac6de85bf95374769fdce8ec2222f8b9e..55d0a1c796d2bb78746e9b360ceeada3eafcfbd0 100644 (file)
@@ -16,6 +16,7 @@ apps_gen_events_folder = os.path.join(apps_folder, "gen_ust_events")
 apps_preload_provider_folder = os.path.join(apps_folder, "preload_provider")
 apps_jul_1 = os.path.join(apps_folder, "jul-1.0")
 apps_jul_2 = os.path.join(apps_folder, "jul-2.0")
+apps_python = os.path.join(apps_folder, "python")
 
 # Used for checksum validation
 project_py_file_location = os.path.join(base_dir, "utils/project.py")
diff --git a/lttng_ivc/tests/ust_python_agent_vs_tools/__init__.py b/lttng_ivc/tests/ust_python_agent_vs_tools/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/lttng_ivc/tests/ust_python_agent_vs_tools/test_ust_python_agent_vs_tools.py b/lttng_ivc/tests/ust_python_agent_vs_tools/test_ust_python_agent_vs_tools.py
new file mode 100644 (file)
index 0000000..a39c009
--- /dev/null
@@ -0,0 +1,213 @@
+import pytest
+import os
+import shutil
+import signal
+import subprocess
+
+import lttng_ivc.utils.ProjectFactory as ProjectFactory
+import lttng_ivc.utils.utils as utils
+import lttng_ivc.utils.runtime as Run
+import lttng_ivc.settings as Settings
+
+"""
+
+FC: Fully Compatible
+BC: Feature of the smallest version number will works.
+TU: Tracing unavailable
+
+Note: actual testing is limited by lttng-ust and lttng-tools abi/api.
+
++----------------------------------------------------------------------------------+
+|             LTTng UST Python agent protocol vs LTTng session daemon              |
++--------------------------+------------+------------+------------+----------------+
+| LTTng UST Java/ LTTng Tools  | 2.7 (1.0)  | 2.8 (2.0)  | 2.9 (2.0)  | 2.10 (2.0) |
++--------------------------+------------+------------+------------+----------------+
+| 2.7                          | NA         | NA         | NA         | NA         |
+| 2.8 (2.0)                    | TU         | FC         | BC         | BC         |
+| 2.9 (2.0)                    | TU         | BC         | FC         | BC         |
+| 2.10 (2.0)                   | TU         | BC         | BC         | FC         |
++--------------------------+------------+------------+------------+----------------+
+
+"""
+
+"""
+First tuple member: lttng-ust label
+Second tuple member: lttng-tool label
+Thirdd tuple member: expected scenario
+"""
+
+test_matrix_tracing_available = [
+    ("lttng-ust-2.7", "lttng-tools-2.7",   True),
+    ("lttng-ust-2.7", "lttng-tools-2.8",   False),
+    ("lttng-ust-2.7", "lttng-tools-2.9",   False),
+    ("lttng-ust-2.7", "lttng-tools-2.10",  False),
+    ("lttng-ust-2.8", "lttng-tools-2.7",   False),
+    ("lttng-ust-2.8", "lttng-tools-2.8",   True),
+    ("lttng-ust-2.8", "lttng-tools-2.9",   False),
+    ("lttng-ust-2.8", "lttng-tools-2.10",  False),
+    ("lttng-ust-2.9", "lttng-tools-2.7",   False),
+    ("lttng-ust-2.9", "lttng-tools-2.8",   False),
+    ("lttng-ust-2.9", "lttng-tools-2.9",   True),
+    ("lttng-ust-2.9", "lttng-tools-2.10",  True),
+    ("lttng-ust-2.10", "lttng-tools-2.7",  False),
+    ("lttng-ust-2.10", "lttng-tools-2.8",  False),
+    ("lttng-ust-2.10", "lttng-tools-2.9",  True),
+    ("lttng-ust-2.10", "lttng-tools-2.10", True),
+]
+
+test_matrix_agent_interface = [
+    ("lttng-ust-2.7", "lttng-tools-2.7",    "Success"),
+    ("lttng-ust-2.7", "lttng-tools-2.8",    "Unsupported protocol"),
+    ("lttng-ust-2.7", "lttng-tools-2.9",    "Unsupported protocol"),
+    ("lttng-ust-2.7", "lttng-tools-2.10",   "Unsupported protocol"),
+    ("lttng-ust-2.8", "lttng-tools-2.7",    "Unsupported protocol"),
+    ("lttng-ust-2.8", "lttng-tools-2.8",    "Success"),
+    ("lttng-ust-2.8", "lttng-tools-2.9",    "Success"),
+    ("lttng-ust-2.8", "lttng-tools-2.10",   "Success"),
+    ("lttng-ust-2.9", "lttng-tools-2.7",    "Unsupported protocol"),
+    ("lttng-ust-2.9", "lttng-tools-2.8",    "Success"),
+    ("lttng-ust-2.9", "lttng-tools-2.9",    "Success"),
+    ("lttng-ust-2.9", "lttng-tools-2.10",   "Success"),
+    ("lttng-ust-2.10", "lttng-tools-2.7",   "Unsupported protocol"),
+    ("lttng-ust-2.10", "lttng-tools-2.8",   "Success"),
+    ("lttng-ust-2.10", "lttng-tools-2.9",   "Success"),
+    ("lttng-ust-2.10", "lttng-tools-2.10",  "Success"),
+]
+
+runtime_matrix_tracing_available = []
+runtime_matrix_agent_interface = []
+
+if not Settings.test_only:
+    runtime_matrix_tracing_available = test_matrix_tracing_available
+    runtime_matrix_agent_interface = test_matrix_agent_interface
+else:
+    for tup in test_matrix_tracing_available:
+        if (tup[0] in Settings.test_only or tup[1] in
+                Settings.test_only):
+            runtime_matrix_tracing_available.append(tup)
+    for tup in test_matrix_agent_interface:
+        if (tup[0] in Settings.test_only or tup[1] in
+                Settings.test_only):
+            runtime_matrix_agent_interface.append(tup)
+
+
+@pytest.mark.parametrize("ust_label,tools_label,should_trace", runtime_matrix_tracing_available)
+def test_ust_python_agent_tracing_available(tmpdir, ust_label, tools_label, should_trace):
+
+    nb_iter = 100
+    nb_events = 5 * nb_iter
+
+    # Prepare environment
+    ust = ProjectFactory.get_precook(ust_label)
+    tools = ProjectFactory.get_precook(tools_label)
+    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)
+
+    tools_runtime_path = os.path.join(str(tmpdir), "tools")
+    ust_runtime_path = os.path.join(str(tmpdir), "ust")
+    app_path = os.path.join(str(tmpdir), "app")
+
+    with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools:
+        runtime_tools.add_project(tools)
+        runtime_tools.add_project(babeltrace)
+
+        runtime_app.add_project(ust)
+        runtime_app.lttng_home = runtime_tools.lttng_home
+
+        trace_path = os.path.join(runtime_tools.lttng_home, 'trace')
+
+        # Copy the python app
+        shutil.copytree(Settings.apps_python, app_path)
+
+        # Start lttng-sessiond
+        sessiond = utils.sessiond_spawn(runtime_tools)
+
+        # Create session using mi to get path and session name
+        runtime_tools.run('lttng create trace --output={}'.format(trace_path))
+
+        runtime_tools.run('lttng enable-event -p pello')
+        runtime_tools.run('lttng start')
+
+        # Run application
+        cmd = 'python app.py -i {}'.format(nb_iter)
+        runtime_app.run(cmd, cwd=app_path)
+
+        # Stop tracing
+        runtime_tools.run('lttng destroy -a')
+        cp = runtime_tools.subprocess_terminate(sessiond)
+        if cp.returncode != 0:
+            pytest.fail("Sessiond return code")
+
+        # Read trace with babeltrace and check for event count via number of line
+        cmd = 'babeltrace {}'.format(trace_path)
+        if should_trace:
+            cp_process, cp_out, cp_err = runtime_tools.run(cmd)
+            assert(utils.line_count(cp_out) == nb_events)
+        else:
+            with pytest.raises(subprocess.CalledProcessError):
+                cp_process, cp_out, cp_err = runtime_tools.run(cmd)
+
+@pytest.mark.parametrize("ust_label,tools_label,outcome", runtime_matrix_agent_interface)
+def test_ust_python_agent_interface(tmpdir, ust_label, tools_label, outcome):
+    """
+    Use the agent coming from ust_label, but run app under tools_version runtime using ust agent.
+    """
+
+    nb_iter = 100
+    nb_events = 5 * nb_iter
+
+    # Prepare environment
+    ust = ProjectFactory.get_precook(ust_label)
+    tools = ProjectFactory.get_precook(tools_label)
+    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)
+
+    tools_runtime_path = os.path.join(str(tmpdir), "tools")
+    ust_runtime_path = os.path.join(str(tmpdir), "ust")
+    app_path = os.path.join(str(tmpdir), "app")
+
+    with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools:
+        runtime_tools.add_project(tools)
+        runtime_tools.add_project(babeltrace)
+
+        runtime_app.add_project(ust)
+        runtime_app.lttng_home = runtime_tools.lttng_home
+
+        trace_path = os.path.join(runtime_tools.lttng_home, 'trace')
+
+        # Make application using the ust runtime
+        shutil.copytree(Settings.apps_python, app_path)
+
+        # Start lttng-sessiond
+        sessiond = utils.sessiond_spawn(runtime_tools)
+
+        # Create session using mi to get path and session name
+        runtime_tools.run('lttng create trace --output={}'.format(trace_path))
+
+        runtime_tools.run('lttng enable-event -p pello')
+        runtime_tools.run('lttng start')
+
+        # Steal the PYTHONPATH from ust project and force it on the tools
+        # project
+        python_path = ust.special_env_variables['PYTHONPATH']
+        tools.special_env_variables['PYTHONPATH'] = python_path
+
+        # Run application with tools runtime
+        cmd = 'python app.py -i {}'.format(nb_iter)
+        runtime_tools.run(cmd, cwd=app_path)
+
+        # Stop tracing
+        runtime_tools.run('lttng destroy -a')
+        cp = runtime_tools.subprocess_terminate(sessiond)
+        if cp.returncode != 0:
+            pytest.fail("Sessiond return code")
+
+        # Read trace with babeltrace and check for event count via number of line
+        cmd = 'babeltrace {}'.format(trace_path)
+        if outcome == "Success":
+            assert(utils.file_contains(runtime_tools.get_subprocess_stderr_path(sessiond),["New registration for pid"]))
+            cp_process, cp_out, cp_err = runtime_tools.run(cmd)
+            assert(utils.line_count(cp_out) == nb_events)
+        else:
+            if outcome == "Unsupported protocol":
+                assert(not(utils.file_contains(runtime_tools.get_subprocess_stderr_path(sessiond),["New registration for pid"])))
+                cp_process, cp_out, cp_err = runtime_tools.run(cmd)
+                assert(utils.line_count(cp_out) == 0)
index 71d17e2a14d79c48c3b790be177b5305a8257d1c..bd389a59b4fb6b7257f63757b6074390fc098dad 100644 (file)
@@ -6,6 +6,7 @@ import logging
 import lttng_ivc.settings as Settings
 
 from lttng_ivc.utils.utils import sha256_checksum
+from lttng_ivc.utils.utils import find_dir
 
 _logger = logging.getLogger('project')
 
@@ -321,6 +322,15 @@ class Lttng_ust(Project):
         classpath = ":".join([jul_path, Settings.log4j_class_path, '.'])
         self.add_special_env_variable("CLASSPATH", classpath)
 
+    def install(self):
+        super(Lttng_ust, self).install()
+        python_path = find_dir(self.installation_path, "lttngust")
+        if python_path:
+            # Fetch the parent of lttngust folder
+            python_path = os.path.dirname(python_path)
+            self.add_special_env_variable("PYTHONPATH", python_path)
+
+
 
 class Lttng_tools(Project):
     def __init__(self, label, git_path, sha1, tmpdir):
index 52258e8388b589f4d85bc13a61408f8381dcaca1..ca49b35b792feca294fa6295f679060993a6f798 100644 (file)
@@ -259,4 +259,3 @@ class Runtime(object):
         # Copy the lttng_home used at runtime using hardlink to prevent useless
         # data duplication
         shutil.copytree(self.lttng_home, self.__post_runtime_lttng_home_path, copy_function=os.link)
-
index 9bc9d8c8a47515b6488c382ec12eaed88dacf275..c174b44e192b17d5b45fff99fe43638adf15bf8d 100644 (file)
@@ -68,3 +68,16 @@ def file_contains(stderr_file, list_of_string):
             for s in list_of_string:
                 if s in line:
                     return True
+
+
+def find_dir(root, name):
+    """
+    Returns the absolute path or None.
+    """
+    abs_path = None
+    for base, dirs, files in os.walk(root):
+        for tmp in dirs:
+            print(tmp)
+            if tmp.endswith(name):
+                abs_path = os.path.abspath(os.path.join(base, tmp))
+    return abs_path
This page took 0.027798 seconds and 5 git commands to generate.