Tests: use babeltrace2 for all tests
[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:
30 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.")
31
32session_info = create_session()
33enable_ust_tracepoint_event(session_info, "ust_tests_exitfast*")
34start_session(session_info)
35
36test_env = os.environ.copy()
37test_env["LTTNG_UST_REGISTER_TIMEOUT"] = "-1"
38
5e7baece 39exit_fast_process = subprocess.Popen(test_path + "exit-fast", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, env=test_env)
b6e2447a 40exit_fast_process.wait()
ee28adfb
JG
41
42print_test_result(exit_fast_process.returncode == 0, current_test, "Test application exited normally")
43current_test += 1
44
5e7baece 45exit_fast_process = subprocess.Popen([test_path + "exit-fast", "suicide"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, env=test_env)
b6e2447a 46exit_fast_process.wait()
ee28adfb
JG
47
48stop_session(session_info)
49
50# Check both events (normal exit and suicide messages) are present in the resulting trace
51try:
c125de8f 52 babeltrace_process = subprocess.Popen([BABELTRACE_BIN, session_info.trace_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
ee28adfb 53except FileNotFoundError:
c125de8f 54 bail("Could not open {}. Please make sure it is installed.".format(BABELTRACE_BIN))
ee28adfb
JG
55
56event_lines = []
57for event_line in babeltrace_process.stdout:
58 event_line = event_line.decode('utf-8').replace("\n", "")
59 event_lines.append(event_line)
60babeltrace_process.wait()
61
62print_test_result(babeltrace_process.returncode == 0, current_test, "Resulting trace is readable")
63current_test += 1
64
65if babeltrace_process.returncode != 0:
66 bail("Unreadable trace; can't proceed with analysis.")
67
68print_test_result(len(event_lines) == 2, current_test, "Correct number of events found in resulting trace")
69current_test += 1
70
71if len(event_lines) != 2:
72 bail("Unexpected number of events found in resulting trace (" + session_info.trace_path + ")." )
73
74match = re.search(r".*message = \"(.*)\"", event_lines[0])
75print_test_result(match is not None and match.group(1) == normal_exit_message, current_test,\
76 "Tracepoint message generated during normal exit run is present in trace and has the expected value")
77current_test += 1
78
79match = re.search(r".*message = \"(.*)\"", event_lines[1])
80print_test_result(match is not None and match.group(1) == suicide_exit_message, current_test,\
81 "Tracepoint message generated during suicide run is present in trace and has the expected value")
82current_test += 1
83
84shutil.rmtree(session_info.tmp_directory)
This page took 0.042371 seconds and 4 git commands to generate.