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:
50 match
= re
.search(r
".*seqfield1 = \[ \[0\] = (\d+), \[1\] = (\d+), \[2\] = (\d+), \[3\] = (\d+) \]", event_line
)
51 if match
is None or int(match
.group(1)) != 116 or int(match
.group(2)) != 101 or int(match
.group(3)) != 115 or int(match
.group(4)) != 116:
53 match
= re
.search(r
".*arrfield1 = \[ \[0\] = (\d), \[1\] = (\d), \[2\] = (\d) \]", event_line
)
54 if match
is None or int(match
.group(1)) != 1 or int(match
.group(2)) != 2 or int(match
.group(3)) != 3:
56 match
= re
.search(r
".*arrfield2 = \"([a
-z
]*)\"", event_line)
57 if match is None or match.group(1) != "test
":
59 match = re.search(r".*_seqfield2_length
= (\d
+)", event_line)
60 if match is None or int(match.group(1)) != 4:
62 match = re.search(r".*seqfield2
= \"([a
-z
]*)\"", event_line)
63 if match is None or match.group(1) != "test
":
65 match = re.search(r".*stringfield
= \"([a
-z
]*)\"", event_line)
66 if match is None or match.group(1) != "test
":
72 DYNAMIC_TEST_ENABLED = False
74 test_executables = [test_path + "demo_static
", test_path + "demo_builtin
"]
75 if os.path.exists(test_path + "demo
"):
76 test_executables.append(test_path + "demo_preload
")
78 DYNAMIC_TEST_ENABLED = True
80 # Only enable tests that were compiled successfully
81 test_executables = [executable for executable in test_executables if os.path.exists(executable)]
83 NR_TESTS += len(test_executables) * 10
86 print("1..{0}
".format(NR_TESTS))
89 print("# No test binary found")
92 # Check if a sessiond is running... bail out if none found.
93 if session_daemon_alive() == 0:
94 bail("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.")
96 if DYNAMIC_TEST_ENABLED
:
97 session_info
= create_session()
98 enable_ust_tracepoint_event(session_info
, "ust_tests_demo*")
99 start_session(session_info
)
101 # Dry run, no events should be logged
102 demo_process
= subprocess
.Popen(test_path
+ "demo", stdout
=subprocess
.DEVNULL
, stderr
=subprocess
.DEVNULL
)
104 stop_session(session_info
)
106 print_test_result(demo_process
.returncode
== 0, current_test
,\
107 "Running application dynamically linked to providers, no preload")
109 trace_path
= os
.path
.join(session_info
.trace_path
, "ust", "uid")
110 print_test_result(not os
.path
.exists(trace_path
), current_test
,\
111 "No events logged when running demo application without preloading providers")
114 shutil
.rmtree(session_info
.tmp_directory
)
116 for executable
in test_executables
:
117 executable_name
= os
.path
.basename(executable
)
118 session_info
= create_session()
119 enable_ust_tracepoint_event(session_info
, "ust_tests_demo*")
120 start_session(session_info
)
122 demo_process
= subprocess
.Popen(executable
, stdout
=subprocess
.DEVNULL
, stderr
=subprocess
.DEVNULL
)
124 stop_session(session_info
)
126 trace_found
= os
.path
.exists(session_info
.trace_path
)
127 print_test_result(trace_found
, current_test
,\
128 "{0}, resulting trace found".format(executable_name
))
132 print("# Skipping " + executable_name
+ " trace verification tests")
136 babeltrace_process
= subprocess
.Popen(["babeltrace", session_info
.trace_path
], stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
137 except FileNotFoundError
:
138 bail("Could not open babeltrace. Please make sure it is installed.")
140 # We should find 8 events in the resulting trace
142 for event_line
in babeltrace_process
.stdout
:
143 event_line
= event_line
.decode('utf-8').replace("\n", "")
144 event_entries
.append(event_line
)
146 if len(event_entries
) != 8:
147 bail("{0}, wrong number of events found in resulting trace.".format(executable_name
))
149 shutil
.rmtree(session_info
.tmp_directory
)
151 print_test_result(len(event_entries
) == 8, current_test
,\
152 "{0}, total number of events logged is correct".format(executable_name
))
155 # Check each loop event
156 match
= re
.search(r
".*ust_tests_demo:starting.*value = (\d+) ", event_entries
[0])
157 print_test_result(match
is not None and (int(match
.group(1)) == 123), current_test
,\
158 "{0}, ust_tests_demo:starting event found in trace with a correct integer argument".format(executable_name
))
162 print_test_result(check_ust_test_demo2_event(event_entries
[i
+1], i
), current_test
,\
163 "{0}, ust_tests_demo2:loop event found in trace and arguments are correct, iteration ".format(executable_name
)\
167 match
= re
.search(r
".*ust_tests_demo:done.*value = (\d+)", event_entries
[6])
168 print_test_result(match
is not None and (int(match
.group(1)) == 456), current_test
,\
169 "{0}, ust_tests_demo:done event found in resulting trace with a correct integer argument".format(executable_name
))
172 match
= re
.search(r
".*ust_tests_demo3:done.*value = (\d+)", event_entries
[7])
173 print_test_result(match
is not None and (int(match
.group(1)) == 42), current_test
,\
174 "{0}, ust_tests_demo3:done event found in resulting trace with a correct integer argument".format(executable_name
))
This page took 0.035143 seconds and 4 git commands to generate.