Commit | Line | Data |
---|---|---|
5836cdc2 JG |
1 | #!/usr/bin/env python3 |
2 | # | |
9d16b343 | 3 | # Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
5836cdc2 | 4 | # |
9d16b343 | 5 | # SPDX-License-Identifier: GPL-2.0-only |
5836cdc2 JG |
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("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.") | |
29 | ||
30 | session_info = create_session() | |
50a74617 | 31 | enable_ust_tracepoint_event(session_info, "lttng_ust_libc*") |
5836cdc2 JG |
32 | start_session(session_info) |
33 | ||
5e7baece | 34 | malloc_process = subprocess.Popen(test_path + "prog", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
b6e2447a | 35 | malloc_process.wait() |
5836cdc2 JG |
36 | |
37 | print_test_result(malloc_process.returncode == 0, current_test, "Test application exited normally") | |
38 | current_test += 1 | |
39 | ||
40 | stop_session(session_info) | |
41 | ||
42 | # Check for malloc events in the resulting trace | |
43 | try: | |
c125de8f | 44 | babeltrace_process = subprocess.Popen([BABELTRACE_BIN, session_info.trace_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
5836cdc2 | 45 | except FileNotFoundError: |
c125de8f | 46 | bail("Could not open {}. Please make sure it is installed.".format(BABELTRACE_BIN), session_info) |
5836cdc2 JG |
47 | |
48 | malloc_event_found = False | |
49 | free_event_found = False | |
50 | ||
51 | for event_line in babeltrace_process.stdout: | |
52 | # Let babeltrace finish to get the return code | |
53 | if malloc_event_found and free_event_found: | |
54 | continue | |
55 | ||
56 | event_line = event_line.decode('utf-8').replace("\n", "") | |
50a74617 | 57 | if re.search(r".*lttng_ust_libc:malloc.*", event_line) is not None: |
5836cdc2 JG |
58 | malloc_event_found = True |
59 | ||
50a74617 | 60 | if re.search(r".*lttng_ust_libc:free.*", event_line) is not None: |
5836cdc2 JG |
61 | free_event_found = True |
62 | ||
63 | babeltrace_process.wait() | |
64 | ||
65 | print_test_result(babeltrace_process.returncode == 0, current_test, "Resulting trace is readable") | |
66 | current_test += 1 | |
67 | ||
72615c1f | 68 | print_test_result(malloc_event_found, current_test, "lttng_ust_libc:malloc event found in resulting trace") |
5836cdc2 JG |
69 | current_test += 1 |
70 | ||
50a74617 | 71 | print_test_result(free_event_found, current_test, "lttng_ust_libc:free event found in resulting trace") |
5836cdc2 JG |
72 | current_test += 1 |
73 | ||
74 | shutil.rmtree(session_info.tmp_directory) |