| 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 os |
| 8 | import subprocess |
| 9 | import re |
| 10 | import shutil |
| 11 | import sys |
| 12 | |
| 13 | test_path = os.path.dirname(os.path.abspath(__file__)) + "/" |
| 14 | test_utils_path = test_path |
| 15 | for i in range(4): |
| 16 | test_utils_path = os.path.dirname(test_utils_path) |
| 17 | test_utils_path = test_utils_path + "/utils" |
| 18 | sys.path.append(test_utils_path) |
| 19 | from test_utils import * |
| 20 | |
| 21 | |
| 22 | NR_TESTS = 4 |
| 23 | current_test = 1 |
| 24 | print("1..{0}".format(NR_TESTS)) |
| 25 | |
| 26 | # Check if a sessiond is running... bail out if none found. |
| 27 | if session_daemon_alive() == 0: |
| 28 | bail( |
| 29 | '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 | |
| 32 | session_info = create_session() |
| 33 | enable_ust_tracepoint_event(session_info, "lttng_ust_libc*") |
| 34 | start_session(session_info) |
| 35 | |
| 36 | malloc_process = subprocess.Popen( |
| 37 | test_path + "prog", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL |
| 38 | ) |
| 39 | malloc_process.wait() |
| 40 | |
| 41 | print_test_result( |
| 42 | malloc_process.returncode == 0, current_test, "Test application exited normally" |
| 43 | ) |
| 44 | current_test += 1 |
| 45 | |
| 46 | stop_session(session_info) |
| 47 | |
| 48 | # Check for malloc events in the resulting trace |
| 49 | try: |
| 50 | babeltrace_process = subprocess.Popen( |
| 51 | [BABELTRACE_BIN, session_info.trace_path], |
| 52 | stdout=subprocess.PIPE, |
| 53 | stderr=subprocess.PIPE, |
| 54 | ) |
| 55 | except FileNotFoundError: |
| 56 | bail( |
| 57 | "Could not open {}. Please make sure it is installed.".format(BABELTRACE_BIN), |
| 58 | session_info, |
| 59 | ) |
| 60 | |
| 61 | malloc_event_found = False |
| 62 | free_event_found = False |
| 63 | |
| 64 | for event_line in babeltrace_process.stdout: |
| 65 | # Let babeltrace finish to get the return code |
| 66 | if malloc_event_found and free_event_found: |
| 67 | continue |
| 68 | |
| 69 | event_line = event_line.decode("utf-8").replace("\n", "") |
| 70 | if re.search(r".*lttng_ust_libc:malloc.*", event_line) is not None: |
| 71 | malloc_event_found = True |
| 72 | |
| 73 | if re.search(r".*lttng_ust_libc:free.*", event_line) is not None: |
| 74 | free_event_found = True |
| 75 | |
| 76 | babeltrace_process.wait() |
| 77 | |
| 78 | print_test_result( |
| 79 | babeltrace_process.returncode == 0, current_test, "Resulting trace is readable" |
| 80 | ) |
| 81 | current_test += 1 |
| 82 | |
| 83 | print_test_result( |
| 84 | malloc_event_found, |
| 85 | current_test, |
| 86 | "lttng_ust_libc:malloc event found in resulting trace", |
| 87 | ) |
| 88 | current_test += 1 |
| 89 | |
| 90 | print_test_result( |
| 91 | free_event_found, current_test, "lttng_ust_libc:free event found in resulting trace" |
| 92 | ) |
| 93 | current_test += 1 |
| 94 | |
| 95 | shutil.rmtree(session_info.tmp_directory) |