Commit | Line | Data |
---|---|---|
37bd6c8e JG |
1 | #!/usr/bin/env python3 |
2 | # | |
9d16b343 | 3 | # Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
37bd6c8e | 4 | # |
9d16b343 | 5 | # SPDX-License-Identifier: GPL-2.0-only |
37bd6c8e JG |
6 | |
7 | import os | |
8 | import subprocess | |
9 | import re | |
10 | import shutil | |
11 | import sys | |
12 | ||
13 | test_path = os.path.dirname(os.path.abspath(__file__)) + "/" | |
14 | test_utils_path = test_path | |
15 | for i in range(4): | |
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 * | |
20 | ||
21 | ||
22 | NR_TESTS = 6 | |
23 | current_test = 1 | |
24 | print("1..{0}".format(NR_TESTS)) | |
25 | ||
26 | # Check if a sessiond is running... bail out if none found. | |
27 | if session_daemon_alive() == 0: | |
6a871bbe KS |
28 | bail( |
29 | '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.' | |
30 | ) | |
37bd6c8e JG |
31 | |
32 | session_info = create_session() | |
33 | enable_ust_tracepoint_event(session_info, "ust_tests_fork*") | |
34 | start_session(session_info) | |
35 | ||
6a871bbe KS |
36 | fork_process = subprocess.Popen( |
37 | [test_path + "fork", test_path + "fork2"], | |
38 | stdout=subprocess.PIPE, | |
39 | stderr=subprocess.PIPE, | |
40 | ) | |
37bd6c8e JG |
41 | parent_pid = -1 |
42 | child_pid = -1 | |
43 | for line in fork_process.stdout: | |
6a871bbe | 44 | line = line.decode("utf-8").replace("\n", "") |
37bd6c8e JG |
45 | match = re.search(r"child_pid (\d+)", line) |
46 | if match: | |
47 | child_pid = match.group(1) | |
48 | match = re.search(r"parent_pid (\d+)", line) | |
49 | if match: | |
50 | parent_pid = match.group(1) | |
51 | ||
3e198d90 JG |
52 | fork_process.wait() |
53 | ||
6a871bbe KS |
54 | print_test_result( |
55 | fork_process.returncode == 0, current_test, "Fork test application exited normally" | |
56 | ) | |
37bd6c8e JG |
57 | current_test += 1 |
58 | ||
59 | stop_session(session_info) | |
60 | ||
61 | # Check both events (normal exit and suicide messages) are present in the resulting trace | |
62 | try: | |
6a871bbe KS |
63 | babeltrace_process = subprocess.Popen( |
64 | [BABELTRACE_BIN, session_info.trace_path], | |
65 | stdout=subprocess.PIPE, | |
66 | stderr=subprocess.PIPE, | |
67 | ) | |
37bd6c8e | 68 | except FileNotFoundError: |
c125de8f | 69 | bail("Could not open {}. Please make sure it is installed.".format(BABELTRACE_BIN)) |
37bd6c8e JG |
70 | |
71 | event_lines = [] | |
72 | for event_line in babeltrace_process.stdout: | |
6a871bbe KS |
73 | event_line = event_line.decode("utf-8").replace("\n", "") |
74 | if ( | |
75 | re.search(r"warning", event_line) is not None | |
76 | or re.search(r"error", event_line) is not None | |
77 | ): | |
78 | print("# " + event_line) | |
37bd6c8e JG |
79 | else: |
80 | event_lines.append(event_line) | |
81 | ||
82 | babeltrace_process.wait() | |
83 | ||
6a871bbe KS |
84 | print_test_result( |
85 | babeltrace_process.returncode == 0, current_test, "Resulting trace is readable" | |
86 | ) | |
37bd6c8e JG |
87 | current_test += 1 |
88 | ||
89 | if babeltrace_process.returncode != 0: | |
90 | bail("Unreadable trace; can't proceed with analysis.", session_info) | |
91 | ||
92 | event_before_fork = False | |
93 | event_after_fork_parent = False | |
94 | event_after_fork_child = False | |
95 | event_after_exec = False | |
96 | ||
97 | for event_line in event_lines: | |
98 | match = re.search(r".*pid = (\d+)", event_line) | |
99 | if match is not None: | |
100 | event_pid = match.group(1) | |
101 | else: | |
102 | continue | |
103 | ||
104 | if re.search(r"before_fork", event_line): | |
6a871bbe | 105 | event_before_fork = event_pid == parent_pid |
37bd6c8e | 106 | if re.search(r"after_fork_parent", event_line): |
6a871bbe | 107 | event_after_fork_parent = event_pid == parent_pid |
37bd6c8e | 108 | if re.search(r"after_fork_child", event_line): |
6a871bbe | 109 | event_after_fork_child = event_pid == child_pid |
37bd6c8e | 110 | if re.search(r"after_exec", event_line): |
6a871bbe | 111 | event_after_exec = event_pid == child_pid |
37bd6c8e | 112 | |
6a871bbe KS |
113 | print_test_result( |
114 | event_before_fork, | |
115 | current_test, | |
116 | "before_fork event logged by parent process found in trace", | |
117 | ) | |
37bd6c8e | 118 | current_test += 1 |
6a871bbe KS |
119 | print_test_result( |
120 | event_after_fork_parent, | |
121 | current_test, | |
122 | "after_fork_parent event logged by parent process found in trace", | |
123 | ) | |
37bd6c8e | 124 | current_test += 1 |
6a871bbe KS |
125 | print_test_result( |
126 | event_after_fork_child, | |
127 | current_test, | |
128 | "after_fork_child event logged by child process found in trace", | |
129 | ) | |
37bd6c8e | 130 | current_test += 1 |
6a871bbe KS |
131 | print_test_result( |
132 | event_after_exec, | |
133 | current_test, | |
134 | "after_exec event logged by child process found in trace", | |
135 | ) | |
37bd6c8e JG |
136 | current_test += 1 |
137 | ||
138 | shutil.rmtree(session_info.tmp_directory) |