3 # Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 # SPDX-License-Identifier: GPL-2.0-only
13 test_path
= os
.path
.dirname(os
.path
.abspath(__file__
)) + "/"
14 test_utils_path
= test_path
16 test_utils_path
= os
.path
.dirname(test_utils_path
)
17 test_utils_path
= test_utils_path
+ "/utils"
18 sys
.path
.append(test_utils_path
)
19 from test_utils
import *
22 def check_ust_test_demo2_event(event_line
, expected_int_field_value
):
23 match
= re
.search(r
".*ust_tests_demo2:loop.*", event_line
)
26 match
= re
.search(r
".*intfield = (\d+)", event_line
)
27 if match
is None or int(match
.group(1)) != expected_int_field_value
:
29 match
= re
.search(r
".*longfield = (\d+)", event_line
)
30 if match
is None or int(match
.group(1)) != expected_int_field_value
:
32 match
= re
.search(r
".*netintfield = (\d+)", event_line
)
33 if match
is None or int(match
.group(1)) != expected_int_field_value
:
35 match
= re
.search(r
".*intfield2 = 0x(\d+)", event_line
)
36 if match
is None or int(match
.group(1)) != expected_int_field_value
:
38 match
= re
.search(r
".*netintfieldhex = 0x(\d+)", event_line
)
39 if match
is None or int(match
.group(1)) != expected_int_field_value
:
41 match
= re
.search(r
".*floatfield = (\d+)", event_line
)
42 if match
is None or int(match
.group(1)) != 2222:
44 match
= re
.search(r
".*doublefield = (\d+)", event_line
)
45 if match
is None or int(match
.group(1)) != 2:
47 match
= re
.search(r
".*_seqfield1_length = (\d+)", event_line
)
48 if match
is None or int(match
.group(1)) != 4:
51 r
".*seqfield1 = \[ \[0\] = (\d+), \[1\] = (\d+), \[2\] = (\d+), \[3\] = (\d+) \]",
56 or int(match
.group(1)) != 116
57 or int(match
.group(2)) != 101
58 or int(match
.group(3)) != 115
59 or int(match
.group(4)) != 116
63 r
".*arrfield1 = \[ \[0\] = (\d), \[1\] = (\d), \[2\] = (\d) \]", event_line
67 or int(match
.group(1)) != 1
68 or int(match
.group(2)) != 2
69 or int(match
.group(3)) != 3
72 match
= re
.search(r
".*arrfield2 = \"([a
-z
]*)\"", event_line)
73 if match is None or match.group(1) != "test
":
75 match = re.search(r".*_seqfield2_length
= (\d
+)", event_line)
76 if match is None or int(match.group(1)) != 4:
78 match = re.search(r".*seqfield2
= \"([a
-z
]*)\"", event_line)
79 if match is None or match.group(1) != "test
":
81 match = re.search(r".*stringfield
= \"([a
-z
]*)\"", event_line)
82 if match is None or match.group(1) != "test
":
89 DYNAMIC_TEST_ENABLED = False
91 test_executables = [test_path + "demo_static
", test_path + "demo_builtin
"]
92 if os.path.exists(test_path + "demo
"):
93 test_executables.append(test_path + "demo_preload
")
95 DYNAMIC_TEST_ENABLED = True
97 # Only enable tests that were compiled successfully
99 executable for executable in test_executables if os.path.exists(executable)
102 NR_TESTS += len(test_executables) * 10
105 print("1..{0}
".format(NR_TESTS))
108 print("# No test binary found")
111 # Check if a sessiond is running... bail out if none found.
112 if session_daemon_alive() == 0:
114 'No sessiond running. Please make sure you are running this test with the "run" shell script and verify that the lttng tools are properly installed.'
117 if DYNAMIC_TEST_ENABLED
:
118 session_info
= create_session()
119 enable_ust_tracepoint_event(session_info
, "ust_tests_demo*")
120 start_session(session_info
)
122 # Dry run, no events should be logged
123 demo_process
= subprocess
.Popen(
124 test_path
+ "demo", stdout
=subprocess
.DEVNULL
, stderr
=subprocess
.DEVNULL
127 stop_session(session_info
)
130 demo_process
.returncode
== 0,
132 "Running application dynamically linked to providers, no preload",
135 trace_path
= os
.path
.join(session_info
.trace_path
, "ust", "uid")
137 not os
.path
.exists(trace_path
),
139 "No events logged when running demo application without preloading providers",
143 shutil
.rmtree(session_info
.tmp_directory
)
145 for executable
in test_executables
:
146 executable_name
= os
.path
.basename(executable
)
147 session_info
= create_session()
148 enable_ust_tracepoint_event(session_info
, "ust_tests_demo*")
149 start_session(session_info
)
151 demo_process
= subprocess
.Popen(
152 executable
, stdout
=subprocess
.DEVNULL
, stderr
=subprocess
.DEVNULL
155 stop_session(session_info
)
157 trace_found
= os
.path
.exists(session_info
.trace_path
)
159 trace_found
, current_test
, "{0}, resulting trace found".format(executable_name
)
164 print("# Skipping " + executable_name
+ " trace verification tests")
168 babeltrace_process
= subprocess
.Popen(
169 [BABELTRACE_BIN
, session_info
.trace_path
],
170 stdout
=subprocess
.PIPE
,
171 stderr
=subprocess
.PIPE
,
173 except FileNotFoundError
:
175 "Could not open {}. Please make sure it is installed.".format(
180 # We should find 8 events in the resulting trace
182 for event_line
in babeltrace_process
.stdout
:
183 event_line
= event_line
.decode("utf-8").replace("\n", "")
184 event_entries
.append(event_line
)
186 if len(event_entries
) != 8:
188 "{0}, wrong number of events found in resulting trace.".format(
193 shutil
.rmtree(session_info
.tmp_directory
)
196 len(event_entries
) == 8,
198 "{0}, total number of events logged is correct".format(executable_name
),
202 # Check each loop event
203 match
= re
.search(r
".*ust_tests_demo:starting.*value = (\d+) ", event_entries
[0])
205 match
is not None and (int(match
.group(1)) == 123),
207 "{0}, ust_tests_demo:starting event found in trace with a correct integer argument".format(
215 check_ust_test_demo2_event(event_entries
[i
+ 1], i
),
217 "{0}, ust_tests_demo2:loop event found in trace and arguments are correct, iteration ".format(
224 match
= re
.search(r
".*ust_tests_demo:done.*value = (\d+)", event_entries
[6])
226 match
is not None and (int(match
.group(1)) == 456),
228 "{0}, ust_tests_demo:done event found in resulting trace with a correct integer argument".format(
234 match
= re
.search(r
".*ust_tests_demo3:done.*value = (\d+)", event_entries
[7])
236 match
is not None and (int(match
.group(1)) == 42),
238 "{0}, ust_tests_demo3:done event found in resulting trace with a correct integer argument".format(
This page took 0.041994 seconds and 4 git commands to generate.