| 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 4 | # Copyright (C) 2015 Antoine Busque <abusque@efficios.com> |
| 5 | # |
| 6 | # SPDX-License-Identifier: GPL-2.0-only |
| 7 | |
| 8 | import os |
| 9 | import subprocess |
| 10 | import re |
| 11 | import shutil |
| 12 | import sys |
| 13 | |
| 14 | test_path = os.path.dirname(os.path.abspath(__file__)) + "/" |
| 15 | test_utils_path = test_path |
| 16 | for i in range(4): |
| 17 | test_utils_path = os.path.dirname(test_utils_path) |
| 18 | test_utils_path = test_utils_path + "/utils" |
| 19 | sys.path.append(test_utils_path) |
| 20 | from test_utils import * |
| 21 | |
| 22 | |
| 23 | NR_TESTS = 7 |
| 24 | current_test = 1 |
| 25 | print("1..{0}".format(NR_TESTS)) |
| 26 | |
| 27 | # Check if a sessiond is running... bail out if none found. |
| 28 | if session_daemon_alive() == 0: |
| 29 | bail("""No sessiond running. Please make sure you are running this test |
| 30 | with the "run" shell script and verify that the lttng tools are |
| 31 | properly installed.""") |
| 32 | |
| 33 | session_info = create_session() |
| 34 | enable_ust_tracepoint_event(session_info, "*") |
| 35 | start_session(session_info) |
| 36 | |
| 37 | test_process = subprocess.Popen(test_path + "prog.strip", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 38 | test_process.wait() |
| 39 | |
| 40 | print_test_result(test_process.returncode == 0, current_test, "Test application exited normally") |
| 41 | current_test += 1 |
| 42 | |
| 43 | stop_session(session_info) |
| 44 | |
| 45 | # Check for statedump events in the resulting trace |
| 46 | try: |
| 47 | babeltrace_process = subprocess.Popen(["babeltrace", session_info.trace_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 48 | except FileNotFoundError: |
| 49 | bail("Could not open babeltrace. Please make sure it is installed.", session_info) |
| 50 | |
| 51 | start_event_found = False |
| 52 | bin_info_event_found = False |
| 53 | build_id_event_found = False |
| 54 | debug_link_event_found = False |
| 55 | end_event_found = False |
| 56 | |
| 57 | for event_line in babeltrace_process.stdout: |
| 58 | # Let babeltrace finish to get the return code |
| 59 | if start_event_found and bin_info_event_found and build_id_event_found and \ |
| 60 | debug_link_event_found and end_event_found: |
| 61 | continue |
| 62 | |
| 63 | event_line = event_line.decode('utf-8').replace("\n", "") |
| 64 | if re.search(r".*lttng_ust_statedump:start.*", event_line) is not None: |
| 65 | start_event_found = True |
| 66 | elif re.search(r".*lttng_ust_statedump:bin_info.*", event_line) is not None: |
| 67 | bin_info_event_found = True |
| 68 | elif re.search(r".*lttng_ust_statedump:build_id.*", event_line) is not None: |
| 69 | build_id_event_found = True |
| 70 | elif re.search(r".*lttng_ust_statedump:debug_link.*", event_line) is not None: |
| 71 | debug_link_event_found = True |
| 72 | elif re.search(r".*lttng_ust_statedump:end.*", event_line) is not None: |
| 73 | end_event_found = True |
| 74 | |
| 75 | babeltrace_process.wait() |
| 76 | |
| 77 | print_test_result(babeltrace_process.returncode == 0, current_test, "Resulting trace is readable") |
| 78 | current_test += 1 |
| 79 | |
| 80 | print_test_result(start_event_found, current_test, "lttng_ust_statedump:start event found in resulting trace") |
| 81 | current_test += 1 |
| 82 | |
| 83 | print_test_result(bin_info_event_found, current_test, "lttng_ust_statedump:bin_info event found in resulting trace") |
| 84 | current_test += 1 |
| 85 | |
| 86 | print_test_result(build_id_event_found, current_test, "lttng_ust_statedump:build_id event found in resulting trace") |
| 87 | current_test += 1 |
| 88 | |
| 89 | print_test_result(debug_link_event_found, current_test, "lttng_ust_statedump:debug_link event found in resulting trace") |
| 90 | current_test += 1 |
| 91 | |
| 92 | print_test_result(end_event_found, current_test, "lttng_ust_statedump:end event found in resulting trace") |
| 93 | current_test += 1 |
| 94 | |
| 95 | shutil.rmtree(session_info.tmp_directory) |