fix: relayd: unaligned access in trace_chunk_registry_ht_key_hash
[lttng-tools.git] / tests / regression / ust / daemon / test_daemon.py
1 #!/usr/bin/env python3
2 #
3 # Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 #
5 # SPDX-License-Identifier: GPL-2.0-only
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:
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 )
32
33 session_info = create_session()
34 enable_ust_tracepoint_event(session_info, "*")
35 start_session(session_info)
36
37
38 parent_pid = None
39 daemon_pid = None
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":
44 daemon_pid = int(pid)
45 if name == "parent_pid":
46 parent_pid = int(pid)
47
48 daemon_process_return_code = daemon_process.wait()
49
50 if parent_pid is None or daemon_pid is None:
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 )
61 current_test += 1
62
63 if daemon_process_return_code != 0:
64 bail("Could not trigger tracepoints successfully. Abandoning test.")
65
66 stop_session(session_info)
67
68 try:
69 babeltrace_process = subprocess.Popen(
70 [BABELTRACE_BIN, session_info.trace_path], stdout=subprocess.PIPE
71 )
72 except FileNotFoundError:
73 bail("Could not open {}. Please make sure it is installed.".format(BABELTRACE_BIN))
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:
81 event_line = event_line.decode("utf-8").replace("\n", "")
82
83 if re.search(r"before_daemon", event_line) is not None:
84 if before_daemon_event_found:
85 bail(
86 "Multiple instances of the before_daemon event found. Please make sure only one instance of this test is runnning."
87 )
88 before_daemon_event_found = True
89 match = re.search(r"(?<=pid = )\d+", event_line)
90
91 if match is not None:
92 before_daemon_event_pid = int(match.group(0))
93
94 if re.search(r"after_daemon", event_line) is not None:
95 if after_daemon_event_found:
96 bail(
97 "Multiple instances of the after_daemon event found. Please make sure only one instance of this test is runnning."
98 )
99 after_daemon_event_found = True
100 match = re.search(r"(?<=pid = )\d+", event_line)
101
102 if match is not None:
103 after_daemon_event_pid = int(match.group(0))
104 babeltrace_process.wait()
105
106 print_test_result(
107 babeltrace_process.returncode == 0, current_test, "Resulting trace is readable"
108 )
109 current_test += 1
110
111 if babeltrace_process.returncode != 0:
112 bail("Unreadable trace; can't proceed with analysis.")
113
114 print_test_result(
115 before_daemon_event_found,
116 current_test,
117 "before_daemon event found in resulting trace",
118 )
119 current_test += 1
120 print_test_result(
121 before_daemon_event_pid == parent_pid,
122 current_test,
123 "Parent pid reported in trace is correct",
124 )
125 current_test += 1
126 print_test_result(
127 before_daemon_event_found,
128 current_test,
129 "after_daemon event found in resulting trace",
130 )
131 current_test += 1
132 print_test_result(
133 after_daemon_event_pid == daemon_pid,
134 current_test,
135 "Daemon pid reported in trace is correct",
136 )
137 current_test += 1
138
139 shutil.rmtree(session_info.tmp_directory)
This page took 0.031547 seconds and 4 git commands to generate.