tests: Move to kernel style SPDX license identifiers
[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:
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
30session_info = create_session()
50a74617 31enable_ust_tracepoint_event(session_info, "lttng_ust_libc*")
5836cdc2
JG
32start_session(session_info)
33
5e7baece 34malloc_process = subprocess.Popen(test_path + "prog", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
b6e2447a 35malloc_process.wait()
5836cdc2
JG
36
37print_test_result(malloc_process.returncode == 0, current_test, "Test application exited normally")
38current_test += 1
39
40stop_session(session_info)
41
42# Check for malloc events in the resulting trace
43try:
44 babeltrace_process = subprocess.Popen(["babeltrace", session_info.trace_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
45except FileNotFoundError:
46 bail("Could not open babeltrace. Please make sure it is installed.", session_info)
47
48malloc_event_found = False
49free_event_found = False
50
51for 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
63babeltrace_process.wait()
64
65print_test_result(babeltrace_process.returncode == 0, current_test, "Resulting trace is readable")
66current_test += 1
67
72615c1f 68print_test_result(malloc_event_found, current_test, "lttng_ust_libc:malloc event found in resulting trace")
5836cdc2
JG
69current_test += 1
70
50a74617 71print_test_result(free_event_found, current_test, "lttng_ust_libc:free event found in resulting trace")
5836cdc2
JG
72current_test += 1
73
74shutil.rmtree(session_info.tmp_directory)
This page took 0.055276 seconds and 5 git commands to generate.