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 normal_exit_message
= "exit-fast tracepoint normal exit"
23 suicide_exit_message
= "exit-fast tracepoint suicide"
26 print("1..{0}".format(NR_TESTS
))
28 # Check if a sessiond is running... bail out if none found.
29 if session_daemon_alive() == 0:
30 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.")
32 session_info
= create_session()
33 enable_ust_tracepoint_event(session_info
, "ust_tests_exitfast*")
34 start_session(session_info
)
36 test_env
= os
.environ
.copy()
37 test_env
["LTTNG_UST_REGISTER_TIMEOUT"] = "-1"
39 exit_fast_process
= subprocess
.Popen(test_path
+ "exit-fast", stdout
=subprocess
.DEVNULL
, stderr
=subprocess
.DEVNULL
, env
=test_env
)
40 exit_fast_process
.wait()
42 print_test_result(exit_fast_process
.returncode
== 0, current_test
, "Test application exited normally")
45 exit_fast_process
= subprocess
.Popen([test_path
+ "exit-fast", "suicide"], stdout
=subprocess
.DEVNULL
, stderr
=subprocess
.DEVNULL
, env
=test_env
)
46 exit_fast_process
.wait()
48 stop_session(session_info
)
50 # Check both events (normal exit and suicide messages) are present in the resulting trace
52 babeltrace_process
= subprocess
.Popen(["babeltrace", session_info
.trace_path
], stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
53 except FileNotFoundError
:
54 bail("Could not open babeltrace. Please make sure it is installed.")
57 for event_line
in babeltrace_process
.stdout
:
58 event_line
= event_line
.decode('utf-8').replace("\n", "")
59 event_lines
.append(event_line
)
60 babeltrace_process
.wait()
62 print_test_result(babeltrace_process
.returncode
== 0, current_test
, "Resulting trace is readable")
65 if babeltrace_process
.returncode
!= 0:
66 bail("Unreadable trace; can't proceed with analysis.")
68 print_test_result(len(event_lines
) == 2, current_test
, "Correct number of events found in resulting trace")
71 if len(event_lines
) != 2:
72 bail("Unexpected number of events found in resulting trace (" + session_info
.trace_path
+ ")." )
74 match
= re
.search(r
".*message = \"(.*)\"", event_lines[0])
75 print_test_result(match is not None and match.group(1) == normal_exit_message, current_test,\
76 "Tracepoint message generated during normal exit run
is present
in trace
and has the expected value
")
79 match = re.search(r".*message
= \"(.*)\"", event_lines[1])
80 print_test_result(match is not None and match.group(1) == suicide_exit_message, current_test,\
81 "Tracepoint message generated during suicide run
is present
in trace
and has the expected value
")
84 shutil.rmtree(session_info.tmp_directory)