3 # Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 # SPDX-License-Identifier: GPL-2.0-only
14 test_path
= os
.path
.dirname(os
.path
.abspath(__file__
)) + "/"
15 test_utils_path
= test_path
17 test_utils_path
= os
.path
.dirname(test_utils_path
)
18 test_utils_path
= test_utils_path
+ "/utils"
19 sys
.path
.append(test_utils_path
)
20 from test_utils
import *
25 print("1..{0}".format(NR_TESTS
))
27 # Check if a sessiond is running... bail out if none found.
28 if session_daemon_alive() == 0:
30 '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.'
33 session_info
= create_session()
34 enable_ust_tracepoint_event(session_info
, "*")
35 start_session(session_info
)
40 daemon_process
= subprocess
.Popen(test_path
+ "daemon", stdout
=subprocess
.PIPE
)
41 for line
in daemon_process
.stdout
:
42 name
, pid
= line
.decode("utf-8").split()
43 if name
== "child_pid":
45 if name
== "parent_pid":
48 daemon_process_return_code
= daemon_process
.wait()
50 if parent_pid
is None or daemon_pid
is None:
52 "Unexpected output received from daemon test executable."
53 + str(daemon_process_output
)
57 daemon_process_return_code
== 0,
59 "Successful call to daemon() and normal exit",
63 if daemon_process_return_code
!= 0:
64 bail("Could not trigger tracepoints successfully. Abandoning test.")
66 stop_session(session_info
)
69 babeltrace_process
= subprocess
.Popen(
70 [BABELTRACE_BIN
, session_info
.trace_path
], stdout
=subprocess
.PIPE
72 except FileNotFoundError
:
73 bail("Could not open {}. Please make sure it is installed.".format(BABELTRACE_BIN
))
75 before_daemon_event_found
= False
76 before_daemon_event_pid
= -1
77 after_daemon_event_found
= False
78 after_daemon_event_pid
= -1
80 for event_line
in babeltrace_process
.stdout
:
81 event_line
= event_line
.decode("utf-8").replace("\n", "")
83 if re
.search(r
"before_daemon", event_line
) is not None:
84 if before_daemon_event_found
:
86 "Multiple instances of the before_daemon event found. Please make sure only one instance of this test is runnning."
88 before_daemon_event_found
= True
89 match
= re
.search(r
"(?<=pid = )\d+", event_line
)
92 before_daemon_event_pid
= int(match
.group(0))
94 if re
.search(r
"after_daemon", event_line
) is not None:
95 if after_daemon_event_found
:
97 "Multiple instances of the after_daemon event found. Please make sure only one instance of this test is runnning."
99 after_daemon_event_found
= True
100 match
= re
.search(r
"(?<=pid = )\d+", event_line
)
102 if match
is not None:
103 after_daemon_event_pid
= int(match
.group(0))
104 babeltrace_process
.wait()
107 babeltrace_process
.returncode
== 0, current_test
, "Resulting trace is readable"
111 if babeltrace_process
.returncode
!= 0:
112 bail("Unreadable trace; can't proceed with analysis.")
115 before_daemon_event_found
,
117 "before_daemon event found in resulting trace",
121 before_daemon_event_pid
== parent_pid
,
123 "Parent pid reported in trace is correct",
127 before_daemon_event_found
,
129 "after_daemon event found in resulting trace",
133 after_daemon_event_pid
== daemon_pid
,
135 "Daemon pid reported in trace is correct",
139 shutil
.rmtree(session_info
.tmp_directory
)