Commit | Line | Data |
---|---|---|
43c28d50 JG |
1 | #!/usr/bin/env python3 |
2 | # | |
9d16b343 | 3 | # Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
43c28d50 | 4 | # |
9d16b343 | 5 | # SPDX-License-Identifier: GPL-2.0-only |
43c28d50 JG |
6 | |
7 | import uuid | |
8 | import os | |
9 | import subprocess | |
10 | import re | |
11 | import shutil | |
12 | import sys | |
13 | ||
14 | test_path = os.path.dirname(os.path.abspath(__file__)) + "/" | |
15 | test_utils_path = test_path | |
16 | for i in range(4): | |
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 * | |
21 | ||
22 | ||
23 | NR_TESTS = 6 | |
24 | current_test = 1 | |
25 | print("1..{0}".format(NR_TESTS)) | |
26 | ||
27 | # Check if a sessiond is running... bail out if none found. | |
28 | if session_daemon_alive() == 0: | |
6a871bbe KS |
29 | bail( |
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.' | |
31 | ) | |
43c28d50 JG |
32 | |
33 | session_info = create_session() | |
34 | enable_ust_tracepoint_event(session_info, "*") | |
35 | start_session(session_info) | |
36 | ||
e47784ba JG |
37 | |
38 | parent_pid = None | |
39 | daemon_pid = None | |
43c28d50 | 40 | daemon_process = subprocess.Popen(test_path + "daemon", stdout=subprocess.PIPE) |
e47784ba | 41 | for line in daemon_process.stdout: |
6a871bbe | 42 | name, pid = line.decode("utf-8").split() |
e47784ba JG |
43 | if name == "child_pid": |
44 | daemon_pid = int(pid) | |
45 | if name == "parent_pid": | |
46 | parent_pid = int(pid) | |
47 | ||
b6e2447a | 48 | daemon_process_return_code = daemon_process.wait() |
43c28d50 | 49 | |
e47784ba | 50 | if parent_pid is None or daemon_pid is None: |
6a871bbe KS |
51 | bail( |
52 | "Unexpected output received from daemon test executable." | |
53 | + str(daemon_process_output) | |
54 | ) | |
55 | ||
56 | print_test_result( | |
57 | daemon_process_return_code == 0, | |
58 | current_test, | |
59 | "Successful call to daemon() and normal exit", | |
60 | ) | |
43c28d50 JG |
61 | current_test += 1 |
62 | ||
63 | if daemon_process_return_code != 0: | |
e47784ba | 64 | bail("Could not trigger tracepoints successfully. Abandoning test.") |
43c28d50 JG |
65 | |
66 | stop_session(session_info) | |
67 | ||
43c28d50 | 68 | try: |
6a871bbe KS |
69 | babeltrace_process = subprocess.Popen( |
70 | [BABELTRACE_BIN, session_info.trace_path], stdout=subprocess.PIPE | |
71 | ) | |
43c28d50 | 72 | except FileNotFoundError: |
c125de8f | 73 | bail("Could not open {}. Please make sure it is installed.".format(BABELTRACE_BIN)) |
43c28d50 JG |
74 | |
75 | before_daemon_event_found = False | |
76 | before_daemon_event_pid = -1 | |
77 | after_daemon_event_found = False | |
78 | after_daemon_event_pid = -1 | |
79 | ||
80 | for event_line in babeltrace_process.stdout: | |
6a871bbe | 81 | event_line = event_line.decode("utf-8").replace("\n", "") |
43c28d50 JG |
82 | |
83 | if re.search(r"before_daemon", event_line) is not None: | |
84 | if before_daemon_event_found: | |
6a871bbe KS |
85 | bail( |
86 | "Multiple instances of the before_daemon event found. Please make sure only one instance of this test is runnning." | |
87 | ) | |
43c28d50 JG |
88 | before_daemon_event_found = True |
89 | match = re.search(r"(?<=pid = )\d+", event_line) | |
90 | ||
91 | if match is not None: | |
e47784ba | 92 | before_daemon_event_pid = int(match.group(0)) |
43c28d50 JG |
93 | |
94 | if re.search(r"after_daemon", event_line) is not None: | |
95 | if after_daemon_event_found: | |
6a871bbe KS |
96 | bail( |
97 | "Multiple instances of the after_daemon event found. Please make sure only one instance of this test is runnning." | |
98 | ) | |
43c28d50 JG |
99 | after_daemon_event_found = True |
100 | match = re.search(r"(?<=pid = )\d+", event_line) | |
101 | ||
102 | if match is not None: | |
e47784ba | 103 | after_daemon_event_pid = int(match.group(0)) |
43c28d50 JG |
104 | babeltrace_process.wait() |
105 | ||
6a871bbe KS |
106 | print_test_result( |
107 | babeltrace_process.returncode == 0, current_test, "Resulting trace is readable" | |
108 | ) | |
43c28d50 JG |
109 | current_test += 1 |
110 | ||
111 | if babeltrace_process.returncode != 0: | |
112 | bail("Unreadable trace; can't proceed with analysis.") | |
113 | ||
6a871bbe KS |
114 | print_test_result( |
115 | before_daemon_event_found, | |
116 | current_test, | |
117 | "before_daemon event found in resulting trace", | |
118 | ) | |
43c28d50 | 119 | current_test += 1 |
6a871bbe KS |
120 | print_test_result( |
121 | before_daemon_event_pid == parent_pid, | |
122 | current_test, | |
123 | "Parent pid reported in trace is correct", | |
124 | ) | |
43c28d50 | 125 | current_test += 1 |
6a871bbe KS |
126 | print_test_result( |
127 | before_daemon_event_found, | |
128 | current_test, | |
129 | "after_daemon event found in resulting trace", | |
130 | ) | |
43c28d50 | 131 | current_test += 1 |
6a871bbe KS |
132 | print_test_result( |
133 | after_daemon_event_pid == daemon_pid, | |
134 | current_test, | |
135 | "Daemon pid reported in trace is correct", | |
136 | ) | |
43c28d50 JG |
137 | current_test += 1 |
138 | ||
139 | shutil.rmtree(session_info.tmp_directory) |