Commit | Line | Data |
---|---|---|
e93e3f39 JR |
1 | import pytest |
2 | import os | |
3 | import shutil | |
4 | import signal | |
5 | import subprocess | |
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 | ||
14 | FC: Fully Compatible | |
15 | BC: Feature of the smallest version number will works. | |
16 | TU: Tracing unavailable | |
17 | ||
18 | +------------------------------------------------------------------------------+ | |
19 | | LTTng UST control protocol compatibility matrix | | |
20 | | (between applications and tools linked on LTTng UST and liblttng-ust-ctl) | | |
21 | +--------------------------+------------+------------+------------+------------+ | |
22 | | LTTng UST / LTTng Tools | 2.7 (6.0) | 2.8 (6.1) | 2.9 (7.1) | 2.10 (7.2) | | |
23 | +--------------------------+------------+------------+------------+------------+ | |
24 | | 2.7 (6.0) | FC | BC | TU | TU | | |
25 | | 2.8 (6.1) | BC | FC | TU | TU | | |
26 | | 2.9 (7.1) | TU | TU | FC | BC | | |
27 | | 2.10 (7.2) | TU | TU | BC | FC | | |
28 | +--------------------------+------------+------------+------------+------------+ | |
29 | ||
30 | Version number of this API is defined in include/lttng/ust-abi.h of lttng-ust project | |
31 | ||
32 | """ | |
33 | ||
34 | """ | |
35 | First tuple member: lttng-ust label | |
36 | Second tuple member: lttng-tool label | |
37 | Third tuple member: expected scenario | |
38 | """ | |
39 | ||
40 | test_matrix_tracing_available = [ | |
41 | ("lttng-ust-2.7", "lttng-tools-2.7", True), | |
42 | ("lttng-ust-2.7", "lttng-tools-2.8", True), | |
43 | ("lttng-ust-2.7", "lttng-tools-2.9", False), | |
44 | ("lttng-ust-2.7", "lttng-tools-2.10", False), | |
45 | ("lttng-ust-2.8", "lttng-tools-2.7", True), | |
46 | ("lttng-ust-2.8", "lttng-tools-2.8", True), | |
47 | ("lttng-ust-2.8", "lttng-tools-2.9", False), | |
48 | ("lttng-ust-2.8", "lttng-tools-2.10", False), | |
49 | ("lttng-ust-2.9", "lttng-tools-2.7", False), | |
50 | ("lttng-ust-2.9", "lttng-tools-2.8", False), | |
51 | ("lttng-ust-2.9", "lttng-tools-2.9", True), | |
52 | ("lttng-ust-2.9", "lttng-tools-2.10", True), | |
53 | ("lttng-ust-2.10", "lttng-tools-2.7", False), | |
54 | ("lttng-ust-2.10", "lttng-tools-2.8", False), | |
55 | ("lttng-ust-2.10", "lttng-tools-2.9", True), | |
56 | ("lttng-ust-2.10", "lttng-tools-2.10", True), | |
57 | ] | |
58 | ||
59 | # Only consider test case for which tracing is valid | |
60 | test_matrix_other = [ | |
61 | ("lttng-ust-2.7", "lttng-tools-2.7", ""), | |
62 | ("lttng-ust-2.7", "lttng-tools-2.8", ""), | |
63 | ("lttng-ust-2.7", "lttng-tools-2.9", ""), | |
64 | ("lttng-ust-2.7", "lttng-tools-2.10", ""), | |
65 | ("lttng-ust-2.8", "lttng-tools-2.7", ""), | |
66 | ("lttng-ust-2.8", "lttng-tools-2.8", ""), | |
67 | ("lttng-ust-2.8", "lttng-tools-2.9", ""), | |
68 | ("lttng-ust-2.8", "lttng-tools-2.10", ""), | |
69 | ("lttng-ust-2.9", "lttng-tools-2.7", ""), | |
70 | ("lttng-ust-2.9", "lttng-tools-2.8", ""), | |
71 | ("lttng-ust-2.9", "lttng-tools-2.9", ""), | |
72 | ("lttng-ust-2.9", "lttng-tools-2.10", ""), | |
73 | ("lttng-ust-2.10", "lttng-tools-2.7", ""), | |
74 | ("lttng-ust-2.10", "lttng-tools-2.8", ""), | |
75 | ("lttng-ust-2.10", "lttng-tools-2.9", ""), | |
76 | ("lttng-ust-2.10", "lttng-tools-2.10", ""), | |
77 | ] | |
78 | ||
79 | runtime_matrix_tracing_available = [] | |
80 | ||
81 | if not Settings.test_only: | |
82 | runtime_matrix_tracing_available = test_matrix_tracing_available | |
83 | else: | |
84 | for tup in test_matrix_tracing_available: | |
85 | if (tup[0] in Settings.test_only or tup[1] in | |
86 | Settings.test_only): | |
87 | runtime_matrix_tracing_available.append(tup) | |
88 | ||
89 | ||
90 | def lttng_sessiond_ready(): | |
91 | print("lttng sessiond is ready ! FFS") | |
92 | ||
93 | @pytest.mark.parametrize("ust_label,tools_label, should_trace", runtime_matrix_tracing_available) | |
94 | def test_ust_app_tracing_available(tmpdir, ust_label, tools_label, should_trace): | |
95 | ||
96 | nb_events = 100 | |
97 | ||
98 | # Prepare environment | |
99 | ust = ProjectFactory.get_precook(ust_label) | |
100 | tools = ProjectFactory.get_precook(tools_label) | |
101 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) | |
102 | ||
103 | tools_runtime_path = os.path.join(str(tmpdir), "tools") | |
104 | ust_runtime_path = os.path.join(str(tmpdir), "ust") | |
105 | app_path = os.path.join(str(tmpdir), "app") | |
106 | ||
107 | with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools: | |
108 | runtime_tools.add_project(tools) | |
109 | runtime_tools.add_project(babeltrace) | |
110 | ||
111 | runtime_app.add_project(ust) | |
112 | runtime_app.lttng_home = runtime_tools.lttng_home | |
113 | ||
114 | trace_path = os.path.join(runtime_tools.lttng_home, 'trace') | |
115 | ||
116 | # Make application using the ust runtime | |
117 | shutil.copytree(Settings.apps_gen_events_folder, app_path) | |
118 | runtime_app.run("make V=1", cwd=app_path) | |
119 | ||
120 | # Start lttng-sessiond | |
121 | # TODO: extract to utils function with a runtime as parameter | |
122 | previous_handler = signal.signal(signal.SIGUSR1, lttng_sessiond_ready) | |
123 | runtime_tools.spawn_subprocess("lttng-sessiond -vvv -S") | |
124 | signal.sigtimedwait({signal.SIGUSR1}, 60) | |
125 | previous_handler = signal.signal(signal.SIGUSR1, previous_handler) | |
126 | ||
127 | # Create session using mi to get path and session name | |
128 | runtime_tools.run('lttng create trace --output={}'.format(trace_path)) | |
129 | ||
130 | # TODO: test with event present in listing | |
131 | ||
132 | runtime_tools.run('lttng enable-event -u tp:tptest') | |
133 | runtime_tools.run('lttng start') | |
134 | ||
135 | # Run application | |
136 | cmd = './app {}'.format(nb_events) | |
137 | runtime_app.run(cmd, cwd=app_path) | |
138 | ||
139 | # Stop tracing | |
140 | runtime_tools.run('lttng destroy -a') | |
141 | ||
142 | try: | |
143 | # Read trace with babeltrace and check for event count via number of line | |
144 | cmd = 'babeltrace {}'.format(trace_path) | |
145 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) | |
146 | assert(utils.line_count(cp_out) == nb_events) | |
147 | except subprocess.CalledProcessError as e: | |
148 | # Check if we expected a problem here | |
149 | if should_trace: | |
150 | # Something happened | |
151 | raise e |