Commit | Line | Data |
---|---|---|
002db623 MD |
1 | #!/bin/bash |
2 | # | |
9d16b343 MJ |
3 | # Copyright (C) 2013 Christian Babeux <christian.babeux@efficios.com> |
4 | # Copyright (C) 2014, 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
002db623 | 5 | # |
9d16b343 | 6 | # SPDX-License-Identifier: GPL-2.0-only |
002db623 | 7 | # |
002db623 MD |
8 | |
9 | TEST_DESC="Kernel tracer - Clock override plugin" | |
10 | ||
11 | CURDIR=$(dirname $0)/ | |
12 | TESTDIR=$CURDIR/../.. | |
13 | SESSION_NAME="clock_override" | |
14 | ||
15 | NUM_TESTS=30 | |
16 | EVENT_NAME="lttng_test_filter_event" | |
17 | ||
18 | TESTCMD="echo -n 10 > /proc/lttng-test-filter-event" | |
19 | ||
20 | METADATA_CLOCK_START_TOKEN="clock {" | |
21 | METADATA_CLOCK_END_TOKEN="};" | |
22 | ||
23 | METADATA_TOKEN_LIST=( | |
24 | "name" | |
25 | "uuid" | |
26 | "description" | |
27 | "freq" | |
28 | ) | |
29 | ||
30 | CLOCK_TOKEN_VALUE=( | |
31 | "lttng_test_clock_override" | |
32 | "83c63deb-7aa4-48fb-abda-946f400d76e6" | |
33 | "Freeze time with 1KHz for regression test" | |
34 | "1000" | |
35 | ) | |
36 | ||
37 | source $TESTDIR/utils/utils.sh | |
38 | ||
39 | function signal_cleanup() | |
40 | { | |
41 | diag "*** Exiting ***" | |
002db623 | 42 | stop_lttng_sessiond |
d0e263e7 | 43 | modprobe --remove lttng-test lttng-clock-plugin-test lttng-clock |
3be453c9 | 44 | full_cleanup |
002db623 MD |
45 | } |
46 | ||
47 | function extract_clock_metadata() | |
48 | { | |
49 | local metadata_file=$1 | |
50 | local clock_metadata_file_destination=$2 | |
51 | cat $metadata_file \ | |
52 | | sed -n "/$METADATA_CLOCK_START_TOKEN/,/$METADATA_CLOCK_END_TOKEN/p" \ | |
53 | > $clock_metadata_file_destination | |
54 | ok $? "Clock metadata extraction" | |
55 | } | |
56 | ||
57 | function extract_clock_metadata_token() | |
58 | { | |
59 | local clock_metadata_file=$1 | |
60 | local token=$2 | |
61 | # Look for token and get value between "" | |
62 | cat $clock_metadata_file | grep $token | awk -F"= |;" '{print $2}' | tr -d '"' | |
63 | } | |
64 | ||
65 | function test_clock_override_metadata() | |
66 | { | |
33e55711 FD |
67 | local ctf_metadata_file=$(mktemp --tmpdir -p $TRACE_PATH ctf-metadata.XXXXXX) |
68 | local clock_metadata_file=$(mktemp --tmpdir -p $TRACE_PATH clock-metadata.XXXXXX) | |
002db623 MD |
69 | local result="" |
70 | ||
71 | diag "Clock override plugin metadata test" | |
72 | ||
73 | modprobe lttng-clock-plugin-test | |
74 | start_lttng_sessiond | |
75 | modprobe lttng-test | |
76 | ||
77 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
78 | enable_kernel_lttng_event_ok $SESSION_NAME "$EVENT_NAME" | |
79 | start_lttng_tracing_ok $SESSION_NAME | |
80 | eval ${TESTCMD} | |
81 | stop_lttng_tracing_ok $SESSION_NAME | |
82 | destroy_lttng_session_ok $SESSION_NAME | |
83 | ||
002db623 | 84 | stop_lttng_sessiond |
d0e263e7 | 85 | modprobe --remove lttng-test lttng-clock-plugin-test lttng-clock |
002db623 | 86 | |
3d2deead JG |
87 | local TRACE_METADATA_FILE_PATH="$(find "$TRACE_PATH" -name metadata -type f)" |
88 | local TRACE_METADATA_DIR="$(dirname "$TRACE_METADATA_FILE_PATH")" | |
89 | ||
90 | $BABELTRACE_BIN -o ctf-metadata -w $ctf_metadata_file $TRACE_METADATA_DIR | |
002db623 MD |
91 | ok $? "Metadata extraction from babeltrace" |
92 | ||
93 | extract_clock_metadata $ctf_metadata_file $clock_metadata_file | |
94 | ||
95 | test ${#METADATA_TOKEN_LIST[@]} -eq ${#CLOCK_TOKEN_VALUE[@]} | |
96 | ok $? "Tokens to check(${#METADATA_TOKEN_LIST[@]}) and provided values(${#CLOCK_TOKEN_VALUE[@]}) count is equal" | |
97 | ||
98 | local counter=0 | |
99 | while [ "$counter" -lt "${#METADATA_TOKEN_LIST[@]}" ]; do | |
100 | result=$(extract_clock_metadata_token $clock_metadata_file \ | |
101 | ${METADATA_TOKEN_LIST[$counter]}) | |
102 | test "$result" == "${CLOCK_TOKEN_VALUE[$counter]}" | |
103 | ok $? "Token \"${METADATA_TOKEN_LIST[$counter]}\" expect:${CLOCK_TOKEN_VALUE[$counter]} got:$result" | |
104 | let "counter++" | |
105 | done | |
106 | rm -rf $ctf_metadata_file | |
107 | rm -rf $clock_metadata_file | |
108 | } | |
109 | ||
110 | function test_clock_override_timestamp() | |
111 | { | |
112 | diag "Clock override test" | |
113 | ||
114 | # Test without the plugin | |
115 | diag "Plugin disabled" | |
116 | ||
117 | start_lttng_sessiond | |
118 | modprobe lttng-test | |
119 | ||
120 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
121 | enable_kernel_lttng_event_ok $SESSION_NAME "$EVENT_NAME" | |
122 | start_lttng_tracing_ok $SESSION_NAME | |
123 | eval ${TESTCMD} | |
124 | stop_lttng_tracing_ok $SESSION_NAME | |
125 | destroy_lttng_session_ok $SESSION_NAME | |
126 | ||
127 | # Use Babeltrace with "-n all" to give a comma separated list for | |
128 | # easy extraction of timestamps. | |
129 | unique_timestamps_count=$($BABELTRACE_BIN -n all $TRACE_PATH | \ | |
130 | cut -d, -f1 | uniq | wc -l) | |
131 | test $unique_timestamps_count -gt 1 | |
132 | ok $? "Unique event timestamps without clock override: $unique_timestamps_count expect >1" | |
d0e263e7 | 133 | modprobe --remove lttng-test |
002db623 MD |
134 | stop_lttng_sessiond |
135 | ||
136 | # Test with clock override plugin. | |
137 | diag "Plugin enabled" | |
138 | ||
139 | modprobe lttng-clock-plugin-test | |
140 | start_lttng_sessiond | |
141 | modprobe lttng-test | |
142 | ||
143 | start_lttng_sessiond | |
144 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
145 | enable_kernel_lttng_event_ok $SESSION_NAME "$EVENT_NAME" | |
146 | start_lttng_tracing_ok $SESSION_NAME | |
147 | eval ${TESTCMD} | |
148 | stop_lttng_tracing_ok $SESSION_NAME | |
149 | destroy_lttng_session_ok $SESSION_NAME | |
150 | ||
002db623 | 151 | stop_lttng_sessiond |
d0e263e7 | 152 | modprobe --remove lttng-clock-plugin-test lttng-clock lttng-test |
002db623 MD |
153 | |
154 | # Use Babeltrace with "-n all" to give a comma separated list for | |
155 | # easy extraction of timestamps. | |
156 | unique_timestamps_count=$($BABELTRACE_BIN -n all $TRACE_PATH | \ | |
157 | cut -d, -f1 | uniq | wc -l) | |
158 | test $unique_timestamps_count -eq 1 | |
159 | ok $? "Unique event timestamps with clock override: $unique_timestamps_count expect 1" | |
160 | } | |
161 | ||
162 | # MUST set TESTDIR before calling those functions | |
163 | plan_tests $NUM_TESTS | |
164 | ||
165 | print_test_banner "$TEST_DESC" | |
166 | ||
c125de8f FD |
167 | bail_out_if_no_babeltrace |
168 | ||
002db623 MD |
169 | TESTS=( |
170 | "test_clock_override_metadata" | |
171 | "test_clock_override_timestamp" | |
172 | ) | |
173 | ||
174 | TEST_COUNT=${#TESTS[@]} | |
175 | i=0 | |
176 | ||
177 | if [ "$(id -u)" == "0" ]; then | |
178 | isroot=1 | |
179 | else | |
180 | isroot=0 | |
181 | fi | |
182 | ||
183 | skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || | |
184 | { | |
185 | trap signal_cleanup SIGTERM SIGINT | |
186 | ||
187 | while [ "$i" -lt "$TEST_COUNT" ]; do | |
188 | ||
33e55711 | 189 | TRACE_PATH=$(mktemp --tmpdir -d tmp.test_clock_override_trace_path.XXXXXX) |
002db623 MD |
190 | |
191 | # Execute test | |
192 | ${TESTS[$i]} | |
193 | ||
194 | rm -rf $TRACE_PATH | |
195 | ||
196 | let "i++" | |
197 | done | |
198 | } |