Tests: Add test to check shared-memory FD leaks after relayd dies
[lttng-tools.git] / tests / regression / ust / libc-wrapper / test_libc-wrapper.py
CommitLineData
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
7import os
8import subprocess
9import re
10import shutil
11import sys
12
13test_path = os.path.dirname(os.path.abspath(__file__)) + "/"
14test_utils_path = test_path
15for i in range(4):
16 test_utils_path = os.path.dirname(test_utils_path)
17test_utils_path = test_utils_path + "/utils"
18sys.path.append(test_utils_path)
19from test_utils import *
20
21
22NR_TESTS = 4
23current_test = 1
24print("1..{0}".format(NR_TESTS))
25
26# Check if a sessiond is running... bail out if none found.
27if 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
32session_info = create_session()
50a74617 33enable_ust_tracepoint_event(session_info, "lttng_ust_libc*")
5836cdc2
JG
34start_session(session_info)
35
6a871bbe
KS
36malloc_process = subprocess.Popen(
37 test_path + "prog", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
38)
b6e2447a 39malloc_process.wait()
5836cdc2 40
6a871bbe
KS
41print_test_result(
42 malloc_process.returncode == 0, current_test, "Test application exited normally"
43)
5836cdc2
JG
44current_test += 1
45
46stop_session(session_info)
47
48# Check for malloc events in the resulting trace
49try:
6a871bbe
KS
50 babeltrace_process = subprocess.Popen(
51 [BABELTRACE_BIN, session_info.trace_path],
52 stdout=subprocess.PIPE,
53 stderr=subprocess.PIPE,
54 )
5836cdc2 55except 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
61malloc_event_found = False
62free_event_found = False
63
64for 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
76babeltrace_process.wait()
77
6a871bbe
KS
78print_test_result(
79 babeltrace_process.returncode == 0, current_test, "Resulting trace is readable"
80)
5836cdc2
JG
81current_test += 1
82
6a871bbe
KS
83print_test_result(
84 malloc_event_found,
85 current_test,
86 "lttng_ust_libc:malloc event found in resulting trace",
87)
5836cdc2
JG
88current_test += 1
89
6a871bbe
KS
90print_test_result(
91 free_event_found, current_test, "lttng_ust_libc:free event found in resulting trace"
92)
5836cdc2
JG
93current_test += 1
94
95shutil.rmtree(session_info.tmp_directory)
This page took 0.061346 seconds and 4 git commands to generate.