Add statedump regen and star globing for ust testing
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 31 Oct 2017 23:27:26 +0000 (19:27 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 31 Oct 2017 23:27:26 +0000 (19:27 -0400)
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
lttng_ivc/tests/ust_app_vs_ust_tools/test_ust_app_vs_ust_tools.py
lttng_ivc/utils/runtime.py
lttng_ivc/utils/utils.py

index e07670686065197d3b14e7afb2f4e72c1e86221e..5eb331fe75f9b453c6bfa04efa63533c36b1ea8d 100644 (file)
@@ -76,15 +76,46 @@ test_matrix_app_context = [
     ("lttng-ust-2.10", "lttng-tools-2.10", ""),
 ]
 
+"""
+Statedump are supported starting at lttng-ust >= 2.9.
+No need to test for prior lttng-ust givent that there is also a bump leading to
+loss of tracing for application running under lttng-ust < 2.9.
+"""
+test_matrix_regen_statedump = [
+        ("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.9",  True),
+        ("lttng-ust-2.10", "lttng-tools-2.10", True),
+]
+
+test_matrix_starglobing_enabler = [
+        ("lttng-ust-2.9", "lttng-tools-2.9",   "Unsupported by tools"),
+        ("lttng-ust-2.9", "lttng-tools-2.10",  "Unsupported by ust"),
+        ("lttng-ust-2.10", "lttng-tools-2.9",  "Unsupported by tools"),
+        ("lttng-ust-2.10", "lttng-tools-2.10", "Supported"),
+]
+
 runtime_matrix_tracing_available = []
+runtime_matrix_regen_statedump = []
+runtime_rix_starglobing_enabler = []
 
 if not Settings.test_only:
     runtime_matrix_tracing_available = test_matrix_tracing_available
+    runtime_matrix_regen_statedump = test_matrix_regen_statedump
+    runtime_matrix_starglobing_enabler = test_matrix_starglobing_enabler
 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_regen_statedump:
+        if (tup[0] in Settings.test_only or tup[1] in
+                Settings.test_only):
+            runtime_matrix_regen_statedump.append(tup)
+    for tup in test_matrix_starglobing_enabler:
+        if (tup[0] in Settings.test_only or tup[1] in
+                Settings.test_only):
+            runtime_matrix_starglobing_enabler.append(tup)
 
 
 @pytest.mark.parametrize("ust_label,tools_label, should_trace", runtime_matrix_tracing_available)
@@ -92,7 +123,7 @@ def test_ust_app_tracing_available(tmpdir, ust_label, tools_label, should_trace)
 
     if ((ust_label == "lttng-ust-2.7" and tools_label == "lttng-tools-2.8") or
             (ust_label == "lttng-ust-2.8" and tools_label == "lttng-tools-2.7")):
-        pytest.xfail("FAiling but should work, problem regarding the size of fields structure")
+        pytest.xfail("Failing but should work, problem regarding the size of fields structure")
 
     nb_events = 100
 
@@ -124,8 +155,6 @@ def test_ust_app_tracing_available(tmpdir, ust_label, tools_label, should_trace)
         # Create session using mi to get path and session name
         runtime_tools.run('lttng create trace --output={}'.format(trace_path))
 
-        # TODO: test with event present in listing
-
         runtime_tools.run('lttng enable-event -u tp:tptest')
         runtime_tools.run('lttng start')
 
@@ -135,7 +164,9 @@ def test_ust_app_tracing_available(tmpdir, ust_label, tools_label, should_trace)
 
         # Stop tracing
         runtime_tools.run('lttng destroy -a')
-        runtime_tools.subprocess_terminate(sessiond)
+        cp = runtime_tools.subprocess_terminate(sessiond)
+        if cp.returncode != 0:
+            pytest.fail("Sessiond return code")
 
         try:
             # Read trace with babeltrace and check for event count via number of line
@@ -147,3 +178,140 @@ def test_ust_app_tracing_available(tmpdir, ust_label, tools_label, should_trace)
             if should_trace:
                 # Something happened
                 raise e
+
+
+@pytest.mark.parametrize("ust_label,tools_label, success", runtime_matrix_regen_statedump)
+def test_ust_app_regen_statedump(tmpdir, ust_label, tools_label, success):
+    nb_events = 100
+
+    if success:
+        expected_events = 4
+    else:
+        expected_events = 2
+
+    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")
+
+
+    app_sync_start = os.path.join(app_path, 'sync_start')
+    app_sync_end = os.path.join(app_path, 'sync_end')
+
+    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_gen_events_folder, app_path)
+        runtime_app.run("make V=1", cwd=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 -u lttng_ust_statedump:start,lttng_ust_statedump:end')
+        runtime_tools.run('lttng start')
+
+        # Run application
+        cmd = './app {} 0 {} {}'.format(nb_events, app_sync_start, app_sync_end)
+        runtime_app.spawn_subprocess(cmd, cwd=app_path)
+
+        utils.wait_for_file(app_sync_start)
+
+        if not success:
+            with pytest.raises(subprocess.CalledProcessError):
+                runtime_tools.run('lttng regenerate statedump')
+        else:
+            runtime_tools.run('lttng regenerate statedump')
+
+        utils.create_empty_file(app_sync_end)
+
+        # 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)
+        cp_process, cp_out, cp_err = runtime_tools.run(cmd)
+        assert(utils.line_count(cp_out) == expected_events)
+
+@pytest.mark.parametrize("ust_label,tools_label, scenario", runtime_matrix_starglobing_enabler)
+def test_ust_app_starglobing_enabler(tmpdir, ust_label, tools_label, scenario):
+
+    nb_events = 100
+
+    if scenario == "Unsupported by ust":
+        expected_events = 0
+    else:
+        expected_events = nb_events
+
+    # 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_gen_events_folder, app_path)
+        runtime_app.run("make V=1", cwd=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))
+
+        # If unsupported by tools simply finish early
+        if scenario == "Unsupported by tools":
+            with pytest.raises(subprocess.CalledProcessError):
+                runtime_tools.run('lttng enable-event -u "tp:*te*"')
+
+            # TODO move this to internal runtime...
+            cp = runtime_tools.subprocess_terminate(sessiond)
+            if cp.returncode != 0:
+                pytest.fail("Sessiond return code")
+            return
+        else:
+            runtime_tools.run('lttng enable-event -u "tp:*te*"')
+
+        runtime_tools.run('lttng start')
+
+        # Run application
+        cmd = './app {}'.format(nb_events)
+        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)
+        cp_process, cp_out, cp_err = runtime_tools.run(cmd)
+        assert(utils.line_count(cp_out) == expected_events)
index f272d6571481c90f9d7ced410420a84392fd6015..b74beee2cad32432a6c87be33063dac2ba4698b6 100644 (file)
@@ -114,7 +114,7 @@ class Runtime(object):
         with open(env_path, 'w') as env_out:
             pprint.pprint(env, stream=env_out)
 
-        p = subprocess.Popen(args, stdout=stdout, stderr=stderr, env=env)
+        p = subprocess.Popen(args, stdout=stdout, stderr=stderr, env=env, cwd=cwd)
         self.__subprocess[tmp_id] = p
         self.__stdout_stderr[tmp_id] = (stdout, stderr)
         _logger.debug("Spawned sub pid: {} args: {} stdout: {} stderr{}".format(p.pid, p.args, out_path, err_path))
index b2de919301768f1748489b1222d1336ae77d9047..ec8d75b7cae87949fcb4cd4fbb9b4301bc2a396d 100644 (file)
@@ -1,5 +1,7 @@
 import signal
 import hashlib
+import os
+import time
 
 def line_count(file_path):
     line_count = 0
@@ -17,6 +19,25 @@ def sha256_checksum(filename, block_size=65536):
     return sha256.hexdigest()
 
 
+# TODO: timeout as a parameter or Settings
+# TODO: Custom exception
+def wait_for_file(path):
+    i = 0
+    timeout = 60
+    while not os.path.exists(path):
+        time.sleep(1)
+        i = i + 1
+        if i > timeout:
+            raise Exception("File still does not exists. Timeout expired")
+
+
+# TODO: find better exception
+def create_empty_file(path):
+    if os.path.exists(path):
+        raise Exception("Path already exist")
+    open(path, 'w').close()
+
+
 def __dummy_sigusr1_handler():
     pass
 
This page took 0.027082 seconds and 5 git commands to generate.