Cleanup: run black on tree
[lttng-tools.git] / tests / regression / ust / type-declarations / test_type_declarations.py
CommitLineData
10b56aef
MD
1#!/usr/bin/env python3
2#
9d16b343 3# Copyright (C) 2014 Geneviève Bastien <gbastien@versatic.net>
10b56aef 4#
9d16b343 5# SPDX-License-Identifier: GPL-2.0-only
10b56aef
MD
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
4881bba8 21NR_TESTS = 10
10b56aef
MD
22current_test = 1
23print("1..{0}".format(NR_TESTS))
24
25# Check if a sessiond is running... bail out if none found.
26if session_daemon_alive() == 0:
6a871bbe
KS
27 bail(
28 '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 )
10b56aef
MD
30
31session_info = create_session()
32enable_ust_tracepoint_event(session_info, "ust_tests_td*")
33start_session(session_info)
34
35test_env = os.environ.copy()
36test_env["LTTNG_UST_REGISTER_TIMEOUT"] = "-1"
37
6a871bbe
KS
38td_process = subprocess.Popen(
39 test_path + "type-declarations",
40 stdout=subprocess.DEVNULL,
41 stderr=subprocess.DEVNULL,
42 env=test_env,
43)
b6e2447a 44td_process.wait()
10b56aef 45
6a871bbe
KS
46print_test_result(
47 td_process.returncode == 0, current_test, "Test application exited normally"
48)
10b56aef
MD
49current_test += 1
50
51stop_session(session_info)
52
53# Check event fields using type declarations are present
54try:
6a871bbe
KS
55 babeltrace_process = subprocess.Popen(
56 [BABELTRACE_BIN, session_info.trace_path],
57 stdout=subprocess.PIPE,
58 stderr=subprocess.PIPE,
59 )
10b56aef 60except FileNotFoundError:
c125de8f 61 bail("Could not open {}. Please make sure it is installed.".format(BABELTRACE_BIN))
10b56aef
MD
62
63event_lines = []
64for event_line in babeltrace_process.stdout:
6a871bbe 65 event_line = event_line.decode("utf-8").replace("\n", "")
10b56aef
MD
66 event_lines.append(event_line)
67babeltrace_process.wait()
68
6a871bbe
KS
69print_test_result(
70 babeltrace_process.returncode == 0, current_test, "Resulting trace is readable"
71)
10b56aef
MD
72current_test += 1
73
74if babeltrace_process.returncode != 0:
75 bail("Unreadable trace; can't proceed with analysis.")
76
6a871bbe
KS
77print_test_result(
78 len(event_lines) == 5,
79 current_test,
80 "Correct number of events found in resulting trace",
81)
10b56aef
MD
82current_test += 1
83
358f4691 84if len(event_lines) != 5:
6a871bbe
KS
85 bail(
86 "Unexpected number of events found in resulting trace ("
87 + session_info.trace_path
88 + ")."
89 )
90
91match = re.search(
92 r".*ust_tests_td:(.*):.*enumfield = \( \"(.*)\" :.*enumfield_bis = \( \"(.*)\" :.*enumfield_third = .*:.*",
93 event_lines[0],
94)
95print_test_result(
96 match is not None and match.group(1) == "tptest",
97 current_test,
98 "First tracepoint is present",
99)
10b56aef
MD
100current_test += 1
101
6a871bbe
KS
102print_test_result(
103 match is not None and match.group(2) == "zero",
104 current_test,
105 "First tracepoint's enum value maps to zero",
106)
10b56aef
MD
107current_test += 1
108
6a871bbe
KS
109print_test_result(
110 match is not None and match.group(3) == "one",
111 current_test,
112 "First tracepoint's second enum value maps to one",
113)
10b56aef
MD
114current_test += 1
115
116match = re.search(r".*ust_tests_td:(.*):.*enumfield = \( \"(.*)\" :.*", event_lines[1])
6a871bbe
KS
117print_test_result(
118 match is not None and match.group(1) == "tptest_bis",
119 current_test,
120 "Second tracepoint is present",
121)
10b56aef
MD
122current_test += 1
123
6a871bbe
KS
124print_test_result(
125 match is not None and match.group(2) == "zero",
126 current_test,
127 "Second tracepoint's enum value maps to zero",
128)
10b56aef
MD
129current_test += 1
130
6a871bbe
KS
131match = re.search(
132 r".*ust_tests_td:(.*):.*enumfield = \( \"(.*)\" :.*enumfield_bis = \( \"(.*)\" .*",
133 event_lines[2],
134)
10b56aef 135
6a871bbe
KS
136print_test_result(
137 match is not None and match.group(2) == "one",
138 current_test,
139 "Third tracepoint's enum value maps to one",
140)
358f4691
PP
141current_test += 1
142
6a871bbe
KS
143print_test_result(
144 '{ zero = ( "zero" : container = 0 ), two = ( "two" : container = 2 ), three = ( "three" : container = 3 ), fifteen = ( "ten_to_twenty" : container = 15 ), twenty_one = ( "twenty_one" : container = 21 ) }'
145 in event_lines[4],
146 current_test,
147 "Auto-incrementing enum values are correct",
148)
10b56aef
MD
149
150shutil.rmtree(session_info.tmp_directory)
This page took 0.05723 seconds and 4 git commands to generate.