3 # Copyright (C) 2013 Christian Babeux <christian.babeux@efficios.com>
4 # Copyright (C) 2014, 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 # SPDX-License-Identifier: GPL-2.0-only
9 TEST_DESC
="Kernel tracer - Clock override plugin"
13 SESSION_NAME
="clock_override"
16 EVENT_NAME
="lttng_test_filter_event"
18 TESTCMD
="echo -n 10 > /proc/lttng-test-filter-event"
20 METADATA_CLOCK_START_TOKEN
="clock {"
21 METADATA_CLOCK_END_TOKEN
="};"
31 "lttng_test_clock_override"
32 "83c63deb-7aa4-48fb-abda-946f400d76e6"
33 "Freeze time with 1KHz for regression test"
37 source $TESTDIR/utils
/utils.sh
39 function signal_cleanup
()
41 diag
"*** Exiting ***"
43 modprobe
--remove lttng-test lttng-clock-plugin-test lttng-clock
47 function extract_clock_metadata
()
49 local metadata_file
=$1
50 local clock_metadata_file_destination
=$2
52 |
sed -n "/$METADATA_CLOCK_START_TOKEN/,/$METADATA_CLOCK_END_TOKEN/p" \
53 > $clock_metadata_file_destination
54 ok $?
"Clock metadata extraction"
57 function extract_clock_metadata_token
()
59 local clock_metadata_file
=$1
61 # Look for token and get value between ""
62 cat $clock_metadata_file |
grep $token |
awk -F"= |;" '{print $2}' |
tr -d '"'
65 function test_clock_override_metadata
()
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
)
71 diag
"Clock override plugin metadata test"
73 modprobe lttng-clock-plugin-test
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
81 stop_lttng_tracing_ok
$SESSION_NAME
82 destroy_lttng_session_ok
$SESSION_NAME
85 modprobe
--remove lttng-test lttng-clock-plugin-test lttng-clock
87 local TRACE_METADATA_FILE_PATH
="$(find "$TRACE_PATH" -name metadata -type f)"
88 local TRACE_METADATA_DIR
="$(dirname "$TRACE_METADATA_FILE_PATH")"
90 $BABELTRACE_BIN -o ctf-metadata
-w $ctf_metadata_file $TRACE_METADATA_DIR
91 ok $?
"Metadata extraction from babeltrace"
93 extract_clock_metadata
$ctf_metadata_file $clock_metadata_file
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"
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"
106 rm -rf $ctf_metadata_file
107 rm -rf $clock_metadata_file
110 function test_clock_override_timestamp
()
112 diag
"Clock override test"
114 # Test without the plugin
115 diag
"Plugin disabled"
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
124 stop_lttng_tracing_ok
$SESSION_NAME
125 destroy_lttng_session_ok
$SESSION_NAME
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"
133 modprobe
--remove lttng-test
136 # Test with clock override plugin.
137 diag
"Plugin enabled"
139 modprobe lttng-clock-plugin-test
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
148 stop_lttng_tracing_ok
$SESSION_NAME
149 destroy_lttng_session_ok
$SESSION_NAME
152 modprobe
--remove lttng-clock-plugin-test lttng-clock lttng-test
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"
162 # MUST set TESTDIR before calling those functions
163 plan_tests
$NUM_TESTS
165 print_test_banner
"$TEST_DESC"
168 "test_clock_override_metadata"
169 "test_clock_override_timestamp"
172 TEST_COUNT
=${#TESTS[@]}
175 if [ "$(id -u)" == "0" ]; then
181 skip
$isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
183 validate_lttng_modules_present
184 trap signal_cleanup SIGTERM SIGINT
186 while [ "$i" -lt "$TEST_COUNT" ]; do
188 TRACE_PATH
=$
(mktemp
--tmpdir -d tmp.test_clock_override_trace_path.XXXXXX
)