| 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 | |
| 18 | import os |
| 19 | import subprocess |
| 20 | import re |
| 21 | import shutil |
| 22 | import sys |
| 23 | |
| 24 | test_path = os.path.dirname(os.path.abspath(__file__)) + "/" |
| 25 | test_utils_path = test_path |
| 26 | for i in range(4): |
| 27 | test_utils_path = os.path.dirname(test_utils_path) |
| 28 | test_utils_path = test_utils_path + "/utils" |
| 29 | sys.path.append(test_utils_path) |
| 30 | from test_utils import * |
| 31 | |
| 32 | |
| 33 | normal_exit_message = "exit-fast tracepoint normal exit" |
| 34 | suicide_exit_message = "exit-fast tracepoint suicide" |
| 35 | NR_TESTS = 5 |
| 36 | current_test = 1 |
| 37 | print("1..{0}".format(NR_TESTS)) |
| 38 | |
| 39 | # Check if a sessiond is running... bail out if none found. |
| 40 | if session_daemon_alive() == 0: |
| 41 | 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.") |
| 42 | |
| 43 | session_info = create_session() |
| 44 | enable_ust_tracepoint_event(session_info, "ust_tests_exitfast*") |
| 45 | start_session(session_info) |
| 46 | |
| 47 | test_env = os.environ.copy() |
| 48 | test_env["LTTNG_UST_REGISTER_TIMEOUT"] = "-1" |
| 49 | |
| 50 | exit_fast_process = subprocess.Popen(test_path + "exit-fast", stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=test_env) |
| 51 | |
| 52 | if sys.version_info >= (3, 3): |
| 53 | try: |
| 54 | exit_fast_process.wait(5) |
| 55 | except subprocess.TimeoutExpired: |
| 56 | exit_fast_process.kill() |
| 57 | bail("Failed to run exit-fast test application.") |
| 58 | else: |
| 59 | exit_fast_process.wait() |
| 60 | |
| 61 | print_test_result(exit_fast_process.returncode == 0, current_test, "Test application exited normally") |
| 62 | current_test += 1 |
| 63 | |
| 64 | exit_fast_process = subprocess.Popen([test_path + "exit-fast", "suicide"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=test_env) |
| 65 | |
| 66 | if sys.version_info >= (3, 3): |
| 67 | try: |
| 68 | exit_fast_process.wait(5) |
| 69 | except subprocess.TimeoutExpired: |
| 70 | exit_fast_process.kill() |
| 71 | bail("Failed to run exit-fast test application in suicide mode.") |
| 72 | else: |
| 73 | exit_fast_process.wait() |
| 74 | |
| 75 | stop_session(session_info) |
| 76 | |
| 77 | # Check both events (normal exit and suicide messages) are present in the resulting trace |
| 78 | try: |
| 79 | babeltrace_process = subprocess.Popen(["babeltrace", session_info.trace_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 80 | except FileNotFoundError: |
| 81 | bail("Could not open babeltrace. Please make sure it is installed.") |
| 82 | |
| 83 | event_lines = [] |
| 84 | for event_line in babeltrace_process.stdout: |
| 85 | event_line = event_line.decode('utf-8').replace("\n", "") |
| 86 | event_lines.append(event_line) |
| 87 | babeltrace_process.wait() |
| 88 | |
| 89 | print_test_result(babeltrace_process.returncode == 0, current_test, "Resulting trace is readable") |
| 90 | current_test += 1 |
| 91 | |
| 92 | if babeltrace_process.returncode != 0: |
| 93 | bail("Unreadable trace; can't proceed with analysis.") |
| 94 | |
| 95 | print_test_result(len(event_lines) == 2, current_test, "Correct number of events found in resulting trace") |
| 96 | current_test += 1 |
| 97 | |
| 98 | if len(event_lines) != 2: |
| 99 | bail("Unexpected number of events found in resulting trace (" + session_info.trace_path + ")." ) |
| 100 | |
| 101 | match = re.search(r".*message = \"(.*)\"", event_lines[0]) |
| 102 | print_test_result(match is not None and match.group(1) == normal_exit_message, current_test,\ |
| 103 | "Tracepoint message generated during normal exit run is present in trace and has the expected value") |
| 104 | current_test += 1 |
| 105 | |
| 106 | match = re.search(r".*message = \"(.*)\"", event_lines[1]) |
| 107 | print_test_result(match is not None and match.group(1) == suicide_exit_message, current_test,\ |
| 108 | "Tracepoint message generated during suicide run is present in trace and has the expected value") |
| 109 | current_test += 1 |
| 110 | |
| 111 | shutil.rmtree(session_info.tmp_directory) |