Test fix: test_daemon can hang while waiting for child pids
[lttng-tools.git] / tests / regression / ust / daemon / test_daemon.py
CommitLineData
43c28d50
JG
1#!/usr/bin/env python3
2#
3# Copyright (C) - 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4#
5# This program is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License, version 2 only, as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful, but WITHOUT
10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12# more details.
13#
14# You should have received a copy of the GNU General Public License along with
15# this program; if not, write to the Free Software Foundation, Inc., 51
16# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18import uuid
19import os
20import subprocess
21import re
22import shutil
23import sys
24
25test_path = os.path.dirname(os.path.abspath(__file__)) + "/"
26test_utils_path = test_path
27for i in range(4):
28 test_utils_path = os.path.dirname(test_utils_path)
29test_utils_path = test_utils_path + "/utils"
30sys.path.append(test_utils_path)
31from test_utils import *
32
33
34NR_TESTS = 6
35current_test = 1
36print("1..{0}".format(NR_TESTS))
37
38# Check if a sessiond is running... bail out if none found.
39if session_daemon_alive() == 0:
40 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.")
41
42session_info = create_session()
43enable_ust_tracepoint_event(session_info, "*")
44start_session(session_info)
45
e47784ba
JG
46
47parent_pid = None
48daemon_pid = None
43c28d50 49daemon_process = subprocess.Popen(test_path + "daemon", stdout=subprocess.PIPE)
e47784ba
JG
50for line in daemon_process.stdout:
51 name, pid = line.decode('utf-8').split()
52 if name == "child_pid":
53 daemon_pid = int(pid)
54 if name == "parent_pid":
55 parent_pid = int(pid)
56
b6e2447a 57daemon_process_return_code = daemon_process.wait()
43c28d50 58
e47784ba
JG
59if parent_pid is None or daemon_pid is None:
60 bail("Unexpected output received from daemon test executable." + str(daemon_process_output))
43c28d50
JG
61
62print_test_result(daemon_process_return_code == 0, current_test, "Successful call to daemon() and normal exit")
63current_test += 1
64
65if daemon_process_return_code != 0:
e47784ba 66 bail("Could not trigger tracepoints successfully. Abandoning test.")
43c28d50
JG
67
68stop_session(session_info)
69
43c28d50
JG
70try:
71 babeltrace_process = subprocess.Popen(["babeltrace", session_info.trace_path], stdout=subprocess.PIPE)
72except FileNotFoundError:
73 bail("Could not open babeltrace. Please make sure it is installed.")
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("Multiple instances of the before_daemon event found. Please make sure only one instance of this test is runnning.")
86 before_daemon_event_found = True
87 match = re.search(r"(?<=pid = )\d+", event_line)
88
89 if match is not None:
e47784ba 90 before_daemon_event_pid = int(match.group(0))
43c28d50
JG
91
92 if re.search(r"after_daemon", event_line) is not None:
93 if after_daemon_event_found:
94 bail("Multiple instances of the after_daemon event found. Please make sure only one instance of this test is runnning.")
95 after_daemon_event_found = True
96 match = re.search(r"(?<=pid = )\d+", event_line)
97
98 if match is not None:
e47784ba 99 after_daemon_event_pid = int(match.group(0))
43c28d50
JG
100babeltrace_process.wait()
101
102print_test_result(babeltrace_process.returncode == 0, current_test, "Resulting trace is readable")
103current_test += 1
104
105if babeltrace_process.returncode != 0:
106 bail("Unreadable trace; can't proceed with analysis.")
107
108print_test_result(before_daemon_event_found, current_test, "before_daemon event found in resulting trace")
109current_test += 1
110print_test_result(before_daemon_event_pid == parent_pid, current_test, "Parent pid reported in trace is correct")
111current_test += 1
112print_test_result(before_daemon_event_found, current_test, "after_daemon event found in resulting trace")
113current_test += 1
114print_test_result(after_daemon_event_pid == daemon_pid, current_test, "Daemon pid reported in trace is correct")
115current_test += 1
116
117shutil.rmtree(session_info.tmp_directory)
This page took 0.044063 seconds and 5 git commands to generate.