tests: Move to kernel style SPDX license identifiers
[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("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
31 session_info = create_session()
32 enable_ust_tracepoint_event(session_info, "*")
33 start_session(session_info)
34
35
36 parent_pid = None
37 daemon_pid = None
38 daemon_process = subprocess.Popen(test_path + "daemon", stdout=subprocess.PIPE)
39 for line in daemon_process.stdout:
40 name, pid = line.decode('utf-8').split()
41 if name == "child_pid":
42 daemon_pid = int(pid)
43 if name == "parent_pid":
44 parent_pid = int(pid)
45
46 daemon_process_return_code = daemon_process.wait()
47
48 if parent_pid is None or daemon_pid is None:
49 bail("Unexpected output received from daemon test executable." + str(daemon_process_output))
50
51 print_test_result(daemon_process_return_code == 0, current_test, "Successful call to daemon() and normal exit")
52 current_test += 1
53
54 if daemon_process_return_code != 0:
55 bail("Could not trigger tracepoints successfully. Abandoning test.")
56
57 stop_session(session_info)
58
59 try:
60 babeltrace_process = subprocess.Popen(["babeltrace", session_info.trace_path], stdout=subprocess.PIPE)
61 except FileNotFoundError:
62 bail("Could not open babeltrace. Please make sure it is installed.")
63
64 before_daemon_event_found = False
65 before_daemon_event_pid = -1
66 after_daemon_event_found = False
67 after_daemon_event_pid = -1
68
69 for event_line in babeltrace_process.stdout:
70 event_line = event_line.decode('utf-8').replace("\n", "")
71
72 if re.search(r"before_daemon", event_line) is not None:
73 if before_daemon_event_found:
74 bail("Multiple instances of the before_daemon event found. Please make sure only one instance of this test is runnning.")
75 before_daemon_event_found = True
76 match = re.search(r"(?<=pid = )\d+", event_line)
77
78 if match is not None:
79 before_daemon_event_pid = int(match.group(0))
80
81 if re.search(r"after_daemon", event_line) is not None:
82 if after_daemon_event_found:
83 bail("Multiple instances of the after_daemon event found. Please make sure only one instance of this test is runnning.")
84 after_daemon_event_found = True
85 match = re.search(r"(?<=pid = )\d+", event_line)
86
87 if match is not None:
88 after_daemon_event_pid = int(match.group(0))
89 babeltrace_process.wait()
90
91 print_test_result(babeltrace_process.returncode == 0, current_test, "Resulting trace is readable")
92 current_test += 1
93
94 if babeltrace_process.returncode != 0:
95 bail("Unreadable trace; can't proceed with analysis.")
96
97 print_test_result(before_daemon_event_found, current_test, "before_daemon event found in resulting trace")
98 current_test += 1
99 print_test_result(before_daemon_event_pid == parent_pid, current_test, "Parent pid reported in trace is correct")
100 current_test += 1
101 print_test_result(before_daemon_event_found, current_test, "after_daemon event found in resulting trace")
102 current_test += 1
103 print_test_result(after_daemon_event_pid == daemon_pid, current_test, "Daemon pid reported in trace is correct")
104 current_test += 1
105
106 shutil.rmtree(session_info.tmp_directory)
This page took 0.031082 seconds and 4 git commands to generate.