3 # Copyright (C) - 2013 Christian Babeux <christian.babeux@efficios.com>
4 # Copyright (C) - 2014, 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License, version 2 only, as
8 # published by the Free Software Foundation.
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 # You should have received a copy of the GNU General Public License along with
16 # this program; if not, write to the Free Software Foundation, Inc., 51
17 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 TEST_DESC
="Kernel tracer - Clock override plugin"
23 SESSION_NAME
="clock_override"
26 EVENT_NAME
="lttng_test_filter_event"
28 TESTCMD
="echo -n 10 > /proc/lttng-test-filter-event"
30 METADATA_CLOCK_START_TOKEN
="clock {"
31 METADATA_CLOCK_END_TOKEN
="};"
41 "lttng_test_clock_override"
42 "83c63deb-7aa4-48fb-abda-946f400d76e6"
43 "Freeze time with 1KHz for regression test"
47 source $TESTDIR/utils
/utils.sh
49 function signal_cleanup
()
51 diag
"*** Exiting ***"
53 modprobe
-r lttng-test lttng-clock-plugin-test lttng-clock
57 function extract_clock_metadata
()
59 local metadata_file
=$1
60 local clock_metadata_file_destination
=$2
62 |
sed -n "/$METADATA_CLOCK_START_TOKEN/,/$METADATA_CLOCK_END_TOKEN/p" \
63 > $clock_metadata_file_destination
64 ok $?
"Clock metadata extraction"
67 function extract_clock_metadata_token
()
69 local clock_metadata_file
=$1
71 # Look for token and get value between ""
72 cat $clock_metadata_file |
grep $token |
awk -F"= |;" '{print $2}' |
tr -d '"'
75 function test_clock_override_metadata
()
77 local ctf_metadata_file
=$
(mktemp
-p $TRACE_PATH ctf-metadata.XXXXXX
)
78 local clock_metadata_file
=$
(mktemp
-p $TRACE_PATH clock-metadata.XXXXXX
)
81 diag
"Clock override plugin metadata test"
83 modprobe lttng-clock-plugin-test
87 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
88 enable_kernel_lttng_event_ok
$SESSION_NAME "$EVENT_NAME"
89 start_lttng_tracing_ok
$SESSION_NAME
91 stop_lttng_tracing_ok
$SESSION_NAME
92 destroy_lttng_session_ok
$SESSION_NAME
95 modprobe
-r lttng-test lttng-clock-plugin-test lttng-clock
97 local TRACE_METADATA_FILE_PATH
="$(find "$TRACE_PATH" -name metadata -type f)"
98 local TRACE_METADATA_DIR
="$(dirname "$TRACE_METADATA_FILE_PATH")"
100 $BABELTRACE_BIN -o ctf-metadata
-w $ctf_metadata_file $TRACE_METADATA_DIR
101 ok $?
"Metadata extraction from babeltrace"
103 extract_clock_metadata
$ctf_metadata_file $clock_metadata_file
105 test ${#METADATA_TOKEN_LIST[@]} -eq ${#CLOCK_TOKEN_VALUE[@]}
106 ok $?
"Tokens to check(${#METADATA_TOKEN_LIST[@]}) and provided values(${#CLOCK_TOKEN_VALUE[@]}) count is equal"
109 while [ "$counter" -lt "${#METADATA_TOKEN_LIST[@]}" ]; do
110 result
=$
(extract_clock_metadata_token
$clock_metadata_file \
111 ${METADATA_TOKEN_LIST[$counter]})
112 test "$result" == "${CLOCK_TOKEN_VALUE[$counter]}"
113 ok $?
"Token \"${METADATA_TOKEN_LIST[$counter]}\" expect:${CLOCK_TOKEN_VALUE[$counter]} got:$result"
116 rm -rf $ctf_metadata_file
117 rm -rf $clock_metadata_file
120 function test_clock_override_timestamp
()
122 diag
"Clock override test"
124 # Test without the plugin
125 diag
"Plugin disabled"
130 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
131 enable_kernel_lttng_event_ok
$SESSION_NAME "$EVENT_NAME"
132 start_lttng_tracing_ok
$SESSION_NAME
134 stop_lttng_tracing_ok
$SESSION_NAME
135 destroy_lttng_session_ok
$SESSION_NAME
137 # Use Babeltrace with "-n all" to give a comma separated list for
138 # easy extraction of timestamps.
139 unique_timestamps_count
=$
($BABELTRACE_BIN -n all
$TRACE_PATH | \
140 cut
-d, -f1 |
uniq |
wc -l)
141 test $unique_timestamps_count -gt 1
142 ok $?
"Unique event timestamps without clock override: $unique_timestamps_count expect >1"
146 # Test with clock override plugin.
147 diag
"Plugin enabled"
149 modprobe lttng-clock-plugin-test
154 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
155 enable_kernel_lttng_event_ok
$SESSION_NAME "$EVENT_NAME"
156 start_lttng_tracing_ok
$SESSION_NAME
158 stop_lttng_tracing_ok
$SESSION_NAME
159 destroy_lttng_session_ok
$SESSION_NAME
163 rmmod lttng-clock-plugin-test
166 # Use Babeltrace with "-n all" to give a comma separated list for
167 # easy extraction of timestamps.
168 unique_timestamps_count
=$
($BABELTRACE_BIN -n all
$TRACE_PATH | \
169 cut
-d, -f1 |
uniq |
wc -l)
170 test $unique_timestamps_count -eq 1
171 ok $?
"Unique event timestamps with clock override: $unique_timestamps_count expect 1"
174 # MUST set TESTDIR before calling those functions
175 plan_tests
$NUM_TESTS
177 print_test_banner
"$TEST_DESC"
180 "test_clock_override_metadata"
181 "test_clock_override_timestamp"
184 TEST_COUNT
=${#TESTS[@]}
187 if [ "$(id -u)" == "0" ]; then
193 skip
$isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
195 trap signal_cleanup SIGTERM SIGINT
197 while [ "$i" -lt "$TEST_COUNT" ]; do
199 TRACE_PATH
=$
(mktemp
-d)