Cleanup: run black on tree
[lttng-tools.git] / tests / regression / ust / daemon / test_daemon.py
... / ...
CommitLineData
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
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:
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
33session_info = create_session()
34enable_ust_tracepoint_event(session_info, "*")
35start_session(session_info)
36
37
38parent_pid = None
39daemon_pid = None
40daemon_process = subprocess.Popen(test_path + "daemon", stdout=subprocess.PIPE)
41for 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
48daemon_process_return_code = daemon_process.wait()
49
50if 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
56print_test_result(
57 daemon_process_return_code == 0,
58 current_test,
59 "Successful call to daemon() and normal exit",
60)
61current_test += 1
62
63if daemon_process_return_code != 0:
64 bail("Could not trigger tracepoints successfully. Abandoning test.")
65
66stop_session(session_info)
67
68try:
69 babeltrace_process = subprocess.Popen(
70 [BABELTRACE_BIN, session_info.trace_path], stdout=subprocess.PIPE
71 )
72except FileNotFoundError:
73 bail("Could not open {}. Please make sure it is installed.".format(BABELTRACE_BIN))
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:
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))
104babeltrace_process.wait()
105
106print_test_result(
107 babeltrace_process.returncode == 0, current_test, "Resulting trace is readable"
108)
109current_test += 1
110
111if babeltrace_process.returncode != 0:
112 bail("Unreadable trace; can't proceed with analysis.")
113
114print_test_result(
115 before_daemon_event_found,
116 current_test,
117 "before_daemon event found in resulting trace",
118)
119current_test += 1
120print_test_result(
121 before_daemon_event_pid == parent_pid,
122 current_test,
123 "Parent pid reported in trace is correct",
124)
125current_test += 1
126print_test_result(
127 before_daemon_event_found,
128 current_test,
129 "after_daemon event found in resulting trace",
130)
131current_test += 1
132print_test_result(
133 after_daemon_event_pid == daemon_pid,
134 current_test,
135 "Daemon pid reported in trace is correct",
136)
137current_test += 1
138
139shutil.rmtree(session_info.tmp_directory)
This page took 0.023772 seconds and 4 git commands to generate.