Introduce babeltrace live test
[deliverable/lttng-ivc.git] / lttng_ivc / tests / babeltrace / live / test_babeltrace_live.py
1 import pytest
2 import os
3 import shutil
4 import signal
5 import subprocess
6 import time
7 import socket
8
9 import lttng_ivc.utils.ProjectFactory as ProjectFactory
10 import lttng_ivc.utils.utils as utils
11 import lttng_ivc.utils.runtime as Run
12 import lttng_ivc.settings as Settings
13
14 """
15 TODO: Add Command header section
16 """
17
18 """
19 First member: babeltrace label
20 Second member: tools label
21 """
22 test_matrix_live = [
23 #pytest.param("babeltrace-1.3", "lttng-tools-2.7", marks=pytest.mark.xfail(reason="Flaky test or Flaky babeltrace. Is under investigation")),
24 #pytest.param("babeltrace-1.3", "lttng-tools-2.8", marks=pytest.mark.xfail(reason="Flaky test or Flaky babeltrace. Is under investigation")) ),
25 #pytest.param("babeltrace-1.3", "lttng-tools-2.9", marks=pytest.mark.xfail(reason="Flaky test or Flaky babeltrace. Is under investigation")) ),
26 #pytest.param("babeltrace-1.3", "lttng-tools-2.10", marks=pytest.mark.xfail(reason="Flaky test or Flaky babeltrace. Is under investigation"))),
27 ("babeltrace-1.4", "lttng-tools-2.7"),
28 ("babeltrace-1.4", "lttng-tools-2.8"),
29 ("babeltrace-1.4", "lttng-tools-2.9"),
30 ("babeltrace-1.4", "lttng-tools-2.10"),
31 ("babeltrace-1.5", "lttng-tools-2.7"),
32 ("babeltrace-1.5", "lttng-tools-2.8"),
33 ("babeltrace-1.5", "lttng-tools-2.9"),
34 ("babeltrace-1.5", "lttng-tools-2.10"),
35 ]
36
37 runtime_matrix_live = []
38
39 if not Settings.test_only:
40 runtime_matrix_live = test_matrix_live
41 else:
42 for tup in test_matrix_live:
43 if (tup[0] in Settings.test_only or tup[1] in
44 Settings.test_only):
45 runtime_matrix_live.append(tup)
46
47
48
49 @pytest.mark.parametrize("babeltrace_l,tools_l", runtime_matrix_live)
50 def test_babeltrace_live(tmpdir, babeltrace_l, tools_l):
51
52 nb_loop = 100
53 nb_expected_events = 100
54
55 babeltrace = ProjectFactory.get_precook(babeltrace_l)
56 tools = ProjectFactory.get_precook(tools_l)
57
58 runtime_path = os.path.join(str(tmpdir), "runtime")
59 app_path = os.path.join(str(tmpdir), "app")
60 session_name = "trace"
61
62 with Run.get_runtime(runtime_path) as runtime:
63 runtime.add_project(tools)
64 runtime.add_project(babeltrace)
65
66 shutil.copytree(Settings.apps_gen_events_folder, app_path)
67 runtime.run("make V=1", cwd=app_path)
68
69 relayd, ctrl_port, data_port, live_port = utils.relayd_spawn(runtime)
70 sessiond = utils.sessiond_spawn(runtime)
71
72 hostname = socket.gethostname()
73 url_babeltrace = "net://localhost:{}/host/{}/{}".format(live_port, hostname, session_name)
74 url = "net://localhost:{}:{}".format(ctrl_port, data_port)
75
76 # Create session using mi to get path and session name
77 runtime.run('lttng create --set-url={} {} --live'.format(url, session_name))
78
79 runtime.run('lttng enable-event -u tp:tptest')
80
81 # From now on babeltrace should be able to hook itself up.
82 # Synchronization point is done via relayd log
83 p_babeltrace = runtime.spawn_subprocess("babeltrace -i lttng-live {}".format(url_babeltrace))
84
85 # TODO: Move to settings
86 timeout = 60
87 # TODO: Move to settings
88 # Make sure that babeltrace did hook itself or at least tried to.
89 synchro_text = "Version check done using protocol"
90 listening = False
91 for i in range(timeout):
92 log = runtime.get_subprocess_stderr_path(relayd)
93 if utils.file_contains(log, synchro_text):
94 listening = True
95 break
96 time.sleep(1)
97
98 if not listening:
99 raise Exception("Babeltrace live is not listening after timeout")
100
101 runtime.run('lttng start')
102
103 # Run application
104 cmd = './app {}'.format(nb_loop)
105 runtime.run(cmd, cwd=app_path)
106
107 # Stop tracing
108 runtime.run('lttng stop')
109 runtime.run('lttng destroy -a')
110
111 # Make sure babeltrace is done reading
112 runtime.subprocess_wait(p_babeltrace)
113
114 runtime.subprocess_terminate(sessiond)
115 runtime.subprocess_terminate(relayd)
116
117 # Check the output from babeltrace
118 cp_out = runtime.get_subprocess_stdout_path(p_babeltrace)
119 assert(utils.line_count(cp_out) == nb_expected_events)
This page took 0.032509 seconds and 5 git commands to generate.