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: | |
6a871bbe KS |
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 | ) | |
5836cdc2 JG |
31 | |
32 | session_info = create_session() | |
50a74617 | 33 | enable_ust_tracepoint_event(session_info, "lttng_ust_libc*") |
5836cdc2 JG |
34 | start_session(session_info) |
35 | ||
6a871bbe KS |
36 | malloc_process = subprocess.Popen( |
37 | test_path + "prog", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL | |
38 | ) | |
b6e2447a | 39 | malloc_process.wait() |
5836cdc2 | 40 | |
6a871bbe KS |
41 | print_test_result( |
42 | malloc_process.returncode == 0, current_test, "Test application exited normally" | |
43 | ) | |
5836cdc2 JG |
44 | current_test += 1 |
45 | ||
46 | stop_session(session_info) | |
47 | ||
48 | # Check for malloc events in the resulting trace | |
49 | try: | |
6a871bbe KS |
50 | babeltrace_process = subprocess.Popen( |
51 | [BABELTRACE_BIN, session_info.trace_path], | |
52 | stdout=subprocess.PIPE, | |
53 | stderr=subprocess.PIPE, | |
54 | ) | |
5836cdc2 | 55 | except FileNotFoundError: |
6a871bbe KS |
56 | bail( |
57 | "Could not open {}. Please make sure it is installed.".format(BABELTRACE_BIN), | |
58 | session_info, | |
59 | ) | |
5836cdc2 JG |
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 | ||
6a871bbe | 69 | event_line = event_line.decode("utf-8").replace("\n", "") |
50a74617 | 70 | if re.search(r".*lttng_ust_libc:malloc.*", event_line) is not None: |
5836cdc2 JG |
71 | malloc_event_found = True |
72 | ||
50a74617 | 73 | if re.search(r".*lttng_ust_libc:free.*", event_line) is not None: |
5836cdc2 JG |
74 | free_event_found = True |
75 | ||
76 | babeltrace_process.wait() | |
77 | ||
6a871bbe KS |
78 | print_test_result( |
79 | babeltrace_process.returncode == 0, current_test, "Resulting trace is readable" | |
80 | ) | |
5836cdc2 JG |
81 | current_test += 1 |
82 | ||
6a871bbe KS |
83 | print_test_result( |
84 | malloc_event_found, | |
85 | current_test, | |
86 | "lttng_ust_libc:malloc event found in resulting trace", | |
87 | ) | |
5836cdc2 JG |
88 | current_test += 1 |
89 | ||
6a871bbe KS |
90 | print_test_result( |
91 | free_event_found, current_test, "lttng_ust_libc:free event found in resulting trace" | |
92 | ) | |
5836cdc2 JG |
93 | current_test += 1 |
94 | ||
95 | shutil.rmtree(session_info.tmp_directory) |