docs: Add supported versions and fix-backport policy
[lttng-tools.git] / tests / regression / ust / libc-wrapper / test_libc-wrapper.py
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("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()
31 enable_ust_tracepoint_event(session_info, "lttng_ust_libc*")
32 start_session(session_info)
33
34 malloc_process = subprocess.Popen(test_path + "prog", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
35 malloc_process.wait()
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:
44 babeltrace_process = subprocess.Popen([BABELTRACE_BIN, session_info.trace_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
45 except FileNotFoundError:
46 bail("Could not open {}. Please make sure it is installed.".format(BABELTRACE_BIN), session_info)
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", "")
57 if re.search(r".*lttng_ust_libc:malloc.*", event_line) is not None:
58 malloc_event_found = True
59
60 if re.search(r".*lttng_ust_libc:free.*", event_line) is not None:
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
68 print_test_result(malloc_event_found, current_test, "lttng_ust_libc:malloc event found in resulting trace")
69 current_test += 1
70
71 print_test_result(free_event_found, current_test, "lttng_ust_libc:free event found in resulting trace")
72 current_test += 1
73
74 shutil.rmtree(session_info.tmp_directory)
This page took 0.031597 seconds and 4 git commands to generate.