Licensing information
[deliverable/lttng-ivc.git] / lttng_ivc / tests / babeltrace / live / test_babeltrace_live.py
1 # Copyright (c) 2017 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
9 #
10 # The above copyright notice and this permission notice shall be included in all
11 # copies or substantial portions of the Software.
12 #
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 # SOFTWARE.
20
21 import pytest
22 import os
23 import shutil
24 import time
25 import socket
26
27 import lttng_ivc.utils.ProjectFactory as ProjectFactory
28 import lttng_ivc.utils.utils as utils
29 import lttng_ivc.utils.runtime as Run
30 import lttng_ivc.settings as Settings
31
32 """
33 TODO: Add Command header section
34 """
35
36 """
37 First member: babeltrace label
38 Second member: tools label
39 """
40 test_matrix_live = [
41 pytest.param("babeltrace-1.3", "lttng-tools-2.7", marks=pytest.mark.xfail(reason="Flaky test or Flaky babeltrace. Is under investigation")),
42 pytest.param("babeltrace-1.3", "lttng-tools-2.8", marks=pytest.mark.xfail(reason="Flaky test or Flaky babeltrace. Is under investigation")),
43 pytest.param("babeltrace-1.3", "lttng-tools-2.9", marks=pytest.mark.xfail(reason="Flaky test or Flaky babeltrace. Is under investigation")),
44 pytest.param("babeltrace-1.3", "lttng-tools-2.10", marks=pytest.mark.xfail(reason="Flaky test or Flaky babeltrace. Is under investigation")),
45 ("babeltrace-1.4", "lttng-tools-2.7"),
46 ("babeltrace-1.4", "lttng-tools-2.8"),
47 ("babeltrace-1.4", "lttng-tools-2.9"),
48 ("babeltrace-1.4", "lttng-tools-2.10"),
49 ("babeltrace-1.5", "lttng-tools-2.7"),
50 ("babeltrace-1.5", "lttng-tools-2.8"),
51 ("babeltrace-1.5", "lttng-tools-2.9"),
52 ("babeltrace-1.5", "lttng-tools-2.10"),
53 ]
54
55 runtime_matrix_live = []
56
57 if not Settings.test_only:
58 runtime_matrix_live = test_matrix_live
59 else:
60 for tup in test_matrix_live:
61 if (tup[0] in Settings.test_only or tup[1] in
62 Settings.test_only):
63 runtime_matrix_live.append(tup)
64
65
66 @pytest.mark.parametrize("babeltrace_l,tools_l", runtime_matrix_live)
67 def test_babeltrace_live(tmpdir, babeltrace_l, tools_l):
68
69 nb_loop = 100
70 nb_expected_events = 100
71
72 babeltrace = ProjectFactory.get_precook(babeltrace_l)
73 tools = ProjectFactory.get_precook(tools_l)
74
75 runtime_path = os.path.join(str(tmpdir), "runtime")
76 app_path = os.path.join(str(tmpdir), "app")
77 session_name = "trace"
78
79 with Run.get_runtime(runtime_path) as runtime:
80 runtime.add_project(tools)
81 runtime.add_project(babeltrace)
82
83 shutil.copytree(Settings.apps_gen_events_folder, app_path)
84 runtime.run("make V=1", cwd=app_path)
85
86 relayd, ctrl_port, data_port, live_port = utils.relayd_spawn(runtime)
87 sessiond = utils.sessiond_spawn(runtime)
88
89 hostname = socket.gethostname()
90 url_babeltrace = "net://localhost:{}/host/{}/{}".format(live_port, hostname, session_name)
91 url = "net://localhost:{}:{}".format(ctrl_port, data_port)
92
93 # Create session using mi to get path and session name
94 runtime.run('lttng create --set-url={} {} --live'.format(url, session_name))
95
96 runtime.run('lttng enable-event -u tp:tptest')
97
98 # From now on babeltrace should be able to hook itself up.
99 # Synchronization point is done via relayd log
100 p_babeltrace = runtime.spawn_subprocess("babeltrace -i lttng-live {}".format(url_babeltrace))
101
102 # TODO: Move to settings
103 timeout = 60
104 # TODO: Move to settings
105 # Make sure that babeltrace did hook itself or at least tried to.
106 synchro_text = "Version check done using protocol"
107 listening = False
108 for i in range(timeout):
109 log = runtime.get_subprocess_stderr_path(relayd)
110 if utils.file_contains(log, synchro_text):
111 listening = True
112 break
113 time.sleep(1)
114
115 if not listening:
116 raise Exception("Babeltrace live is not listening after timeout")
117
118 runtime.run('lttng start')
119
120 # Run application
121 cmd = './app {}'.format(nb_loop)
122 runtime.run(cmd, cwd=app_path)
123
124 # Stop tracing
125 runtime.run('lttng stop')
126 runtime.run('lttng destroy -a')
127
128 # Make sure babeltrace is done reading
129 runtime.subprocess_wait(p_babeltrace)
130
131 runtime.subprocess_terminate(sessiond)
132 runtime.subprocess_terminate(relayd)
133
134 # Check the output from babeltrace
135 cp_out = runtime.get_subprocess_stdout_path(p_babeltrace)
136 assert(utils.line_count(cp_out) == nb_expected_events)
This page took 0.03349 seconds and 5 git commands to generate.