Fix: English syntax errors in 'lttng status'
[lttng-tools.git] / tests / regression / ust / type-declarations / test_type_declarations.py
CommitLineData
10b56aef
MD
1#!/usr/bin/env python3
2#
3# Copyright (C) - 2014 Geneviève Bastien <gbastien@versatic.net>
4#
5# This program is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License, version 2 only, as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful, but WITHOUT
10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12# more details.
13#
14# You should have received a copy of the GNU General Public License along with
15# this program; if not, write to the Free Software Foundation, Inc., 51
16# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18import os
19import subprocess
20import re
21import shutil
22import sys
23
24test_path = os.path.dirname(os.path.abspath(__file__)) + "/"
25test_utils_path = test_path
26for i in range(4):
27 test_utils_path = os.path.dirname(test_utils_path)
28test_utils_path = test_utils_path + "/utils"
29sys.path.append(test_utils_path)
30from test_utils import *
31
32NR_TESTS = 9
33current_test = 1
34print("1..{0}".format(NR_TESTS))
35
36# Check if a sessiond is running... bail out if none found.
37if session_daemon_alive() == 0:
38 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.")
39
40session_info = create_session()
41enable_ust_tracepoint_event(session_info, "ust_tests_td*")
42start_session(session_info)
43
44test_env = os.environ.copy()
45test_env["LTTNG_UST_REGISTER_TIMEOUT"] = "-1"
46
47td_process = subprocess.Popen(test_path + "type-declarations", stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=test_env)
48
49if sys.version_info >= (3, 3):
50 try:
51 td_process.wait(5)
52 except TimeoutExpired:
53 td_process.kill()
54 bail("Failed to run type-declarations test application.")
55else:
56 td_process.wait()
57
58print_test_result(td_process.returncode == 0, current_test, "Test application exited normally")
59current_test += 1
60
61stop_session(session_info)
62
63# Check event fields using type declarations are present
64try:
65 babeltrace_process = subprocess.Popen(["babeltrace", session_info.trace_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
66except FileNotFoundError:
67 bail("Could not open babeltrace. Please make sure it is installed.")
68
69event_lines = []
70for event_line in babeltrace_process.stdout:
71 event_line = event_line.decode('utf-8').replace("\n", "")
72 event_lines.append(event_line)
73babeltrace_process.wait()
74
75print_test_result(babeltrace_process.returncode == 0, current_test, "Resulting trace is readable")
76current_test += 1
77
78if babeltrace_process.returncode != 0:
79 bail("Unreadable trace; can't proceed with analysis.")
80
81print_test_result(len(event_lines) == 4, current_test, "Correct number of events found in resulting trace")
82current_test += 1
83
84if len(event_lines) != 4:
85 bail("Unexpected number of events found in resulting trace (" + session_info.trace_path + ")." )
86
87match = re.search(r".*ust_tests_td:(.*):.*enumfield = \( \"(.*)\" :.*enumfield_bis = \( \"(.*)\" :.*enumfield_third = .*:.*", event_lines[0])
88print_test_result(match is not None and match.group(1) == "tptest", current_test,\
89 "First tracepoint is present")
90current_test += 1
91
92print_test_result(match is not None and match.group(2) == "zero", current_test,\
93 "First tracepoint's enum value maps to zero")
94current_test += 1
95
96print_test_result(match is not None and match.group(3) == "one", current_test,\
97 "First tracepoint's second enum value maps to one")
98current_test += 1
99
100match = re.search(r".*ust_tests_td:(.*):.*enumfield = \( \"(.*)\" :.*", event_lines[1])
101print_test_result(match is not None and match.group(1) == "tptest_bis", current_test,\
102 "Second tracepoint is present")
103current_test += 1
104
105print_test_result(match is not None and match.group(2) == "zero", current_test,\
106 "Second tracepoint's enum value maps to zero")
107current_test += 1
108
109match = re.search(r".*ust_tests_td:(.*):.*enumfield = \( \"(.*)\" :.*enumfield_bis = \( \"(.*)\" .*", event_lines[2])
110
111print_test_result(match is not None and match.group(2) == "one", current_test,\
112 "Third tracepoint's enum value maps to one")
113
114shutil.rmtree(session_info.tmp_directory)
This page took 0.027035 seconds and 4 git commands to generate.