tests: Move to kernel style SPDX license identifiers
[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:
27 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.")
28
29session_info = create_session()
30enable_ust_tracepoint_event(session_info, "ust_tests_td*")
31start_session(session_info)
32
33test_env = os.environ.copy()
34test_env["LTTNG_UST_REGISTER_TIMEOUT"] = "-1"
35
5e7baece 36td_process = subprocess.Popen(test_path + "type-declarations", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, env=test_env)
b6e2447a 37td_process.wait()
10b56aef
MD
38
39print_test_result(td_process.returncode == 0, current_test, "Test application exited normally")
40current_test += 1
41
42stop_session(session_info)
43
44# Check event fields using type declarations are present
45try:
46 babeltrace_process = subprocess.Popen(["babeltrace", session_info.trace_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
47except FileNotFoundError:
48 bail("Could not open babeltrace. Please make sure it is installed.")
49
50event_lines = []
51for event_line in babeltrace_process.stdout:
52 event_line = event_line.decode('utf-8').replace("\n", "")
53 event_lines.append(event_line)
54babeltrace_process.wait()
55
56print_test_result(babeltrace_process.returncode == 0, current_test, "Resulting trace is readable")
57current_test += 1
58
59if babeltrace_process.returncode != 0:
60 bail("Unreadable trace; can't proceed with analysis.")
61
358f4691 62print_test_result(len(event_lines) == 5, current_test, "Correct number of events found in resulting trace")
10b56aef
MD
63current_test += 1
64
358f4691 65if len(event_lines) != 5:
10b56aef
MD
66 bail("Unexpected number of events found in resulting trace (" + session_info.trace_path + ")." )
67
68match = re.search(r".*ust_tests_td:(.*):.*enumfield = \( \"(.*)\" :.*enumfield_bis = \( \"(.*)\" :.*enumfield_third = .*:.*", event_lines[0])
69print_test_result(match is not None and match.group(1) == "tptest", current_test,\
70 "First tracepoint is present")
71current_test += 1
72
73print_test_result(match is not None and match.group(2) == "zero", current_test,\
74 "First tracepoint's enum value maps to zero")
75current_test += 1
76
77print_test_result(match is not None and match.group(3) == "one", current_test,\
78 "First tracepoint's second enum value maps to one")
79current_test += 1
80
81match = re.search(r".*ust_tests_td:(.*):.*enumfield = \( \"(.*)\" :.*", event_lines[1])
82print_test_result(match is not None and match.group(1) == "tptest_bis", current_test,\
83 "Second tracepoint is present")
84current_test += 1
85
86print_test_result(match is not None and match.group(2) == "zero", current_test,\
87 "Second tracepoint's enum value maps to zero")
88current_test += 1
89
90match = re.search(r".*ust_tests_td:(.*):.*enumfield = \( \"(.*)\" :.*enumfield_bis = \( \"(.*)\" .*", event_lines[2])
91
92print_test_result(match is not None and match.group(2) == "one", current_test,\
93 "Third tracepoint's enum value maps to one")
358f4691
PP
94current_test += 1
95
96print_test_result('{ zero = ( "zero" : container = 0 ), two = ( "two" : container = 2 ), three = ( "three" : container = 3 ), fifteen = ( "ten_to_twenty" : container = 15 ), twenty_one = ( "twenty_one" : container = 21 ) }' in event_lines[4],
97 current_test, 'Auto-incrementing enum values are correct')
10b56aef
MD
98
99shutil.rmtree(session_info.tmp_directory)
This page took 0.045309 seconds and 5 git commands to generate.