Commit | Line | Data |
---|---|---|
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 | ||
18 | import os | |
19 | import subprocess | |
20 | import re | |
21 | import shutil | |
22 | import sys | |
23 | ||
24 | test_path = os.path.dirname(os.path.abspath(__file__)) + "/" | |
25 | test_utils_path = test_path | |
26 | for i in range(4): | |
27 | test_utils_path = os.path.dirname(test_utils_path) | |
28 | test_utils_path = test_utils_path + "/utils" | |
29 | sys.path.append(test_utils_path) | |
30 | from test_utils import * | |
31 | ||
4881bba8 | 32 | NR_TESTS = 10 |
10b56aef MD |
33 | current_test = 1 |
34 | print("1..{0}".format(NR_TESTS)) | |
35 | ||
36 | # Check if a sessiond is running... bail out if none found. | |
37 | if 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 | ||
40 | session_info = create_session() | |
41 | enable_ust_tracepoint_event(session_info, "ust_tests_td*") | |
42 | start_session(session_info) | |
43 | ||
44 | test_env = os.environ.copy() | |
45 | test_env["LTTNG_UST_REGISTER_TIMEOUT"] = "-1" | |
46 | ||
5e7baece | 47 | td_process = subprocess.Popen(test_path + "type-declarations", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, env=test_env) |
b6e2447a | 48 | td_process.wait() |
10b56aef MD |
49 | |
50 | print_test_result(td_process.returncode == 0, current_test, "Test application exited normally") | |
51 | current_test += 1 | |
52 | ||
53 | stop_session(session_info) | |
54 | ||
55 | # Check event fields using type declarations are present | |
56 | try: | |
57 | babeltrace_process = subprocess.Popen(["babeltrace", session_info.trace_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
58 | except FileNotFoundError: | |
59 | bail("Could not open babeltrace. Please make sure it is installed.") | |
60 | ||
61 | event_lines = [] | |
62 | for event_line in babeltrace_process.stdout: | |
63 | event_line = event_line.decode('utf-8').replace("\n", "") | |
64 | event_lines.append(event_line) | |
65 | babeltrace_process.wait() | |
66 | ||
67 | print_test_result(babeltrace_process.returncode == 0, current_test, "Resulting trace is readable") | |
68 | current_test += 1 | |
69 | ||
70 | if babeltrace_process.returncode != 0: | |
71 | bail("Unreadable trace; can't proceed with analysis.") | |
72 | ||
358f4691 | 73 | print_test_result(len(event_lines) == 5, current_test, "Correct number of events found in resulting trace") |
10b56aef MD |
74 | current_test += 1 |
75 | ||
358f4691 | 76 | if len(event_lines) != 5: |
10b56aef MD |
77 | bail("Unexpected number of events found in resulting trace (" + session_info.trace_path + ")." ) |
78 | ||
79 | match = re.search(r".*ust_tests_td:(.*):.*enumfield = \( \"(.*)\" :.*enumfield_bis = \( \"(.*)\" :.*enumfield_third = .*:.*", event_lines[0]) | |
80 | print_test_result(match is not None and match.group(1) == "tptest", current_test,\ | |
81 | "First tracepoint is present") | |
82 | current_test += 1 | |
83 | ||
84 | print_test_result(match is not None and match.group(2) == "zero", current_test,\ | |
85 | "First tracepoint's enum value maps to zero") | |
86 | current_test += 1 | |
87 | ||
88 | print_test_result(match is not None and match.group(3) == "one", current_test,\ | |
89 | "First tracepoint's second enum value maps to one") | |
90 | current_test += 1 | |
91 | ||
92 | match = re.search(r".*ust_tests_td:(.*):.*enumfield = \( \"(.*)\" :.*", event_lines[1]) | |
93 | print_test_result(match is not None and match.group(1) == "tptest_bis", current_test,\ | |
94 | "Second tracepoint is present") | |
95 | current_test += 1 | |
96 | ||
97 | print_test_result(match is not None and match.group(2) == "zero", current_test,\ | |
98 | "Second tracepoint's enum value maps to zero") | |
99 | current_test += 1 | |
100 | ||
101 | match = re.search(r".*ust_tests_td:(.*):.*enumfield = \( \"(.*)\" :.*enumfield_bis = \( \"(.*)\" .*", event_lines[2]) | |
102 | ||
103 | print_test_result(match is not None and match.group(2) == "one", current_test,\ | |
104 | "Third tracepoint's enum value maps to one") | |
358f4691 PP |
105 | current_test += 1 |
106 | ||
107 | print_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], | |
108 | current_test, 'Auto-incrementing enum values are correct') | |
10b56aef MD |
109 | |
110 | shutil.rmtree(session_info.tmp_directory) |