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