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