Cleanup: run black on tree
[lttng-tools.git] / tests / regression / ust / daemon / test_daemon.py
CommitLineData
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
7import uuid
8import os
9import subprocess
10import re
11import shutil
12import sys
13
14test_path = os.path.dirname(os.path.abspath(__file__)) + "/"
15test_utils_path = test_path
16for i in range(4):
17 test_utils_path = os.path.dirname(test_utils_path)
18test_utils_path = test_utils_path + "/utils"
19sys.path.append(test_utils_path)
20from test_utils import *
21
22
23NR_TESTS = 6
24current_test = 1
25print("1..{0}".format(NR_TESTS))
26
27# Check if a sessiond is running... bail out if none found.
28if 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
33session_info = create_session()
34enable_ust_tracepoint_event(session_info, "*")
35start_session(session_info)
36
e47784ba
JG
37
38parent_pid = None
39daemon_pid = None
43c28d50 40daemon_process = subprocess.Popen(test_path + "daemon", stdout=subprocess.PIPE)
e47784ba 41for 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 48daemon_process_return_code = daemon_process.wait()
43c28d50 49
e47784ba 50if 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
56print_test_result(
57 daemon_process_return_code == 0,
58 current_test,
59 "Successful call to daemon() and normal exit",
60)
43c28d50
JG
61current_test += 1
62
63if daemon_process_return_code != 0:
e47784ba 64 bail("Could not trigger tracepoints successfully. Abandoning test.")
43c28d50
JG
65
66stop_session(session_info)
67
43c28d50 68try:
6a871bbe
KS
69 babeltrace_process = subprocess.Popen(
70 [BABELTRACE_BIN, session_info.trace_path], stdout=subprocess.PIPE
71 )
43c28d50 72except FileNotFoundError:
c125de8f 73 bail("Could not open {}. Please make sure it is installed.".format(BABELTRACE_BIN))
43c28d50
JG
74
75before_daemon_event_found = False
76before_daemon_event_pid = -1
77after_daemon_event_found = False
78after_daemon_event_pid = -1
79
80for 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
104babeltrace_process.wait()
105
6a871bbe
KS
106print_test_result(
107 babeltrace_process.returncode == 0, current_test, "Resulting trace is readable"
108)
43c28d50
JG
109current_test += 1
110
111if babeltrace_process.returncode != 0:
112 bail("Unreadable trace; can't proceed with analysis.")
113
6a871bbe
KS
114print_test_result(
115 before_daemon_event_found,
116 current_test,
117 "before_daemon event found in resulting trace",
118)
43c28d50 119current_test += 1
6a871bbe
KS
120print_test_result(
121 before_daemon_event_pid == parent_pid,
122 current_test,
123 "Parent pid reported in trace is correct",
124)
43c28d50 125current_test += 1
6a871bbe
KS
126print_test_result(
127 before_daemon_event_found,
128 current_test,
129 "after_daemon event found in resulting trace",
130)
43c28d50 131current_test += 1
6a871bbe
KS
132print_test_result(
133 after_daemon_event_pid == daemon_pid,
134 current_test,
135 "Daemon pid reported in trace is correct",
136)
43c28d50
JG
137current_test += 1
138
139shutil.rmtree(session_info.tmp_directory)
This page took 0.060827 seconds and 4 git commands to generate.