Commit | Line | Data |
---|---|---|
43c28d50 JG |
1 | #!/usr/bin/env python3 |
2 | # | |
3 | # Copyright (C) - 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
4 | # | |
5 | # This program is free software; you can redistribute it and/or modify it | |
6 | # under the terms of the GNU General Public License, version 2 only, as | |
7 | # published by the Free Software Foundation. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, but WITHOUT | |
10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | # more details. | |
13 | # | |
14 | # You should have received a copy of the GNU General Public License along with | |
15 | # this program; if not, write to the Free Software Foundation, Inc., 51 | |
16 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 | ||
18 | import uuid | |
19 | import os | |
20 | import subprocess | |
21 | import re | |
22 | import shutil | |
23 | import sys | |
24 | ||
25 | test_path = os.path.dirname(os.path.abspath(__file__)) + "/" | |
26 | test_utils_path = test_path | |
27 | for i in range(4): | |
28 | test_utils_path = os.path.dirname(test_utils_path) | |
29 | test_utils_path = test_utils_path + "/utils" | |
30 | sys.path.append(test_utils_path) | |
31 | from test_utils import * | |
32 | ||
33 | ||
34 | NR_TESTS = 6 | |
35 | current_test = 1 | |
36 | print("1..{0}".format(NR_TESTS)) | |
37 | ||
38 | # Check if a sessiond is running... bail out if none found. | |
39 | if session_daemon_alive() == 0: | |
40 | 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.") | |
41 | ||
42 | session_info = create_session() | |
43 | enable_ust_tracepoint_event(session_info, "*") | |
44 | start_session(session_info) | |
45 | ||
46 | daemon_process = subprocess.Popen(test_path + "daemon", stdout=subprocess.PIPE) | |
47 | if sys.version_info >= (3, 3): | |
48 | try: | |
49 | daemon_process_return_code = daemon_process.wait(5) | |
50 | except TimeoutExpired: | |
51 | daemon_process.kill() | |
52 | daemon_process_return_code = -1 | |
53 | else: | |
54 | daemon_process_return_code = daemon_process.wait() | |
55 | ||
56 | daemon_process_output = daemon_process.communicate()[0] | |
57 | daemon_process_output = daemon_process_output.decode('utf-8').splitlines() | |
58 | ||
59 | print_test_result(daemon_process_return_code == 0, current_test, "Successful call to daemon() and normal exit") | |
60 | current_test += 1 | |
61 | ||
62 | if daemon_process_return_code != 0: | |
63 | bail("Could not trigger tracepoints successfully. Abondoning test.") | |
64 | ||
65 | stop_session(session_info) | |
66 | ||
67 | if len(daemon_process_output) != 2: | |
68 | bail("Unexpected output received from daemon test executable." + str(daemon_process_output)) | |
69 | ||
70 | parent_pid = re.search(r"\d+", daemon_process_output[0]).group(0) | |
71 | daemon_pid = re.search(r"\d+", daemon_process_output[1]).group(0) | |
72 | ||
73 | try: | |
74 | babeltrace_process = subprocess.Popen(["babeltrace", session_info.trace_path], stdout=subprocess.PIPE) | |
75 | except FileNotFoundError: | |
76 | bail("Could not open babeltrace. Please make sure it is installed.") | |
77 | ||
78 | before_daemon_event_found = False | |
79 | before_daemon_event_pid = -1 | |
80 | after_daemon_event_found = False | |
81 | after_daemon_event_pid = -1 | |
82 | ||
83 | for event_line in babeltrace_process.stdout: | |
84 | event_line = event_line.decode('utf-8').replace("\n", "") | |
85 | ||
86 | if re.search(r"before_daemon", event_line) is not None: | |
87 | if before_daemon_event_found: | |
88 | bail("Multiple instances of the before_daemon event found. Please make sure only one instance of this test is runnning.") | |
89 | before_daemon_event_found = True | |
90 | match = re.search(r"(?<=pid = )\d+", event_line) | |
91 | ||
92 | if match is not None: | |
93 | before_daemon_event_pid = match.group(0) | |
94 | ||
95 | if re.search(r"after_daemon", event_line) is not None: | |
96 | if after_daemon_event_found: | |
97 | bail("Multiple instances of the after_daemon event found. Please make sure only one instance of this test is runnning.") | |
98 | after_daemon_event_found = True | |
99 | match = re.search(r"(?<=pid = )\d+", event_line) | |
100 | ||
101 | if match is not None: | |
102 | after_daemon_event_pid = match.group(0) | |
103 | babeltrace_process.wait() | |
104 | ||
105 | print_test_result(babeltrace_process.returncode == 0, current_test, "Resulting trace is readable") | |
106 | current_test += 1 | |
107 | ||
108 | if babeltrace_process.returncode != 0: | |
109 | bail("Unreadable trace; can't proceed with analysis.") | |
110 | ||
111 | print_test_result(before_daemon_event_found, current_test, "before_daemon event found in resulting trace") | |
112 | current_test += 1 | |
113 | print_test_result(before_daemon_event_pid == parent_pid, current_test, "Parent pid reported in trace is correct") | |
114 | current_test += 1 | |
115 | print_test_result(before_daemon_event_found, current_test, "after_daemon event found in resulting trace") | |
116 | current_test += 1 | |
117 | print_test_result(after_daemon_event_pid == daemon_pid, current_test, "Daemon pid reported in trace is correct") | |
118 | current_test += 1 | |
119 | ||
120 | shutil.rmtree(session_info.tmp_directory) |