vscode: Add configurations to run the executables under the debugger
[lttng-tools.git] / tests / regression / ust / exit-fast / test_exit-fast.py
CommitLineData
ee28adfb
JG
1#!/usr/bin/env python3
2#
9d16b343 3# Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
ee28adfb 4#
9d16b343 5# SPDX-License-Identifier: GPL-2.0-only
ee28adfb
JG
6
7import os
8import subprocess
9import re
10import shutil
11import sys
12
13test_path = os.path.dirname(os.path.abspath(__file__)) + "/"
14test_utils_path = test_path
15for i in range(4):
16 test_utils_path = os.path.dirname(test_utils_path)
17test_utils_path = test_utils_path + "/utils"
18sys.path.append(test_utils_path)
19from test_utils import *
20
21
22normal_exit_message = "exit-fast tracepoint normal exit"
23suicide_exit_message = "exit-fast tracepoint suicide"
24NR_TESTS = 5
25current_test = 1
26print("1..{0}".format(NR_TESTS))
27
28# Check if a sessiond is running... bail out if none found.
29if session_daemon_alive() == 0:
6a871bbe
KS
30 bail(
31 '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.'
32 )
ee28adfb
JG
33
34session_info = create_session()
35enable_ust_tracepoint_event(session_info, "ust_tests_exitfast*")
36start_session(session_info)
37
38test_env = os.environ.copy()
39test_env["LTTNG_UST_REGISTER_TIMEOUT"] = "-1"
40
6a871bbe
KS
41exit_fast_process = subprocess.Popen(
42 test_path + "exit-fast",
43 stdout=subprocess.DEVNULL,
44 stderr=subprocess.DEVNULL,
45 env=test_env,
46)
b6e2447a 47exit_fast_process.wait()
ee28adfb 48
6a871bbe
KS
49print_test_result(
50 exit_fast_process.returncode == 0, current_test, "Test application exited normally"
51)
ee28adfb
JG
52current_test += 1
53
6a871bbe
KS
54exit_fast_process = subprocess.Popen(
55 [test_path + "exit-fast", "suicide"],
56 stdout=subprocess.DEVNULL,
57 stderr=subprocess.DEVNULL,
58 env=test_env,
59)
b6e2447a 60exit_fast_process.wait()
ee28adfb
JG
61
62stop_session(session_info)
63
64# Check both events (normal exit and suicide messages) are present in the resulting trace
65try:
6a871bbe
KS
66 babeltrace_process = subprocess.Popen(
67 [BABELTRACE_BIN, session_info.trace_path],
68 stdout=subprocess.PIPE,
69 stderr=subprocess.PIPE,
70 )
ee28adfb 71except FileNotFoundError:
c125de8f 72 bail("Could not open {}. Please make sure it is installed.".format(BABELTRACE_BIN))
ee28adfb
JG
73
74event_lines = []
75for event_line in babeltrace_process.stdout:
6a871bbe 76 event_line = event_line.decode("utf-8").replace("\n", "")
ee28adfb
JG
77 event_lines.append(event_line)
78babeltrace_process.wait()
79
6a871bbe
KS
80print_test_result(
81 babeltrace_process.returncode == 0, current_test, "Resulting trace is readable"
82)
ee28adfb
JG
83current_test += 1
84
85if babeltrace_process.returncode != 0:
86 bail("Unreadable trace; can't proceed with analysis.")
87
6a871bbe
KS
88print_test_result(
89 len(event_lines) == 2,
90 current_test,
91 "Correct number of events found in resulting trace",
92)
ee28adfb
JG
93current_test += 1
94
95if len(event_lines) != 2:
6a871bbe
KS
96 bail(
97 "Unexpected number of events found in resulting trace ("
98 + session_info.trace_path
99 + ")."
100 )
ee28adfb
JG
101
102match = re.search(r".*message = \"(.*)\"", event_lines[0])
6a871bbe
KS
103print_test_result(
104 match is not None and match.group(1) == normal_exit_message,
105 current_test,
106 "Tracepoint message generated during normal exit run is present in trace and has the expected value",
107)
ee28adfb
JG
108current_test += 1
109
110match = re.search(r".*message = \"(.*)\"", event_lines[1])
6a871bbe
KS
111print_test_result(
112 match is not None and match.group(1) == suicide_exit_message,
113 current_test,
114 "Tracepoint message generated during suicide run is present in trace and has the expected value",
115)
ee28adfb
JG
116current_test += 1
117
118shutil.rmtree(session_info.tmp_directory)
This page took 0.066687 seconds and 5 git commands to generate.