3 # Copyright (C) - 2015 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
5 # This library is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation; version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this library; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 TEST_DESC
="UST - Clock override plugin"
20 TESTDIR
=$CURDIR/..
/..
/..
21 SESSION_NAME
="clock_override"
23 TESTAPP_PATH
="$TESTDIR/utils/testapp"
24 TESTAPP_NAME
="gen-ust-events"
25 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
27 EVENT_NAME
="tp:tptest"
28 LTTNG_UST_CLOCK_PLUGIN_SO
="lttng-ust-clock-override-test.so"
31 METADATA_CLOCK_START_TOKEN
="clock {"
32 METADATA_CLOCK_END_TOKEN
="};"
41 UST_CLOCK_TOKEN_VALUE
=(
42 "lttng_test_clock_override"
43 "83c63deb-7aa4-48fb-abda-946f400d76e6"
44 "Freeze time with 1KHz for regression test"
50 source $TESTDIR/utils
/utils.sh
52 # MUST set TESTDIR before calling those functions
55 $TESTAPP_BIN $NUM_EVENT
56 ok $?
"Application done"
59 function extract_clock_metadata
()
61 local metadata_file
=$1
62 local clock_metadata_file_destination
=$2
64 |
sed -n "/$METADATA_CLOCK_START_TOKEN/,/$METADATA_CLOCK_END_TOKEN/p" \
65 > $clock_metadata_file_destination
66 ok $?
"Clock metadata extraction"
69 function extract_clock_metadata_token
()
71 local clock_metadata_file
=$1
73 # Look for token and get value between ""
74 cat $clock_metadata_file |
grep $token |
awk -F"= |;" '{print $2}' |
tr -d '"'
77 function test_getcpu_override_metadata
()
79 local ctf_metadata_file
=$
(mktemp
-p $TRACE_PATH ctf-metadata.XXXXX
)
80 local clock_metadata_file
=$
(mktemp
-p $TRACE_PATH clock-metadata.XXXXX
)
83 diag
"Clock override plugin metadata test"
85 # LTTNG_UST_CLOCK_PLUGIN need to be defined for lttng-sessiond.
86 export LTTNG_UST_CLOCK_PLUGIN
=$CURDIR/.libs
/$LTTNG_UST_CLOCK_PLUGIN_SO
88 unset LTTNG_UST_CLOCK_PLUGIN
90 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
91 enable_ust_lttng_event_ok
$SESSION_NAME "$EVENT_NAME"
92 start_lttng_tracing_ok
$SESSION_NAME
94 stop_lttng_tracing_ok
$SESSION_NAME
95 destroy_lttng_session_ok
$SESSION_NAME
98 $BABELTRACE_BIN -o ctf-metadata
-w $ctf_metadata_file $TRACE_PATH
99 ok $?
"Metadata extraction from babeltrace"
101 extract_clock_metadata
$ctf_metadata_file $clock_metadata_file
103 test ${#METADATA_TOKEN_LIST[@]} -eq ${#UST_CLOCK_TOKEN_VALUE[@]}
104 ok $?
"Tokens to check(${#METADATA_TOKEN_LIST[@]}) and provided values(${#UST_CLOCK_TOKEN_VALUE[@]}) count is equal"
107 while [ "$counter" -lt "${#METADATA_TOKEN_LIST[@]}" ]; do
108 result
=$
(extract_clock_metadata_token
$clock_metadata_file \
109 ${METADATA_TOKEN_LIST[$counter]})
110 test "$result" == "${UST_CLOCK_TOKEN_VALUE[$counter]}"
111 ok $?
"Token \"${METADATA_TOKEN_LIST[$counter]}\" expect:${UST_CLOCK_TOKEN_VALUE[$counter]} got:$result"
114 rm -rf $ctf_metadata_file
115 rm -rf $clock_metadata_file
118 function test_getcpu_override_timestamp
()
120 diag
"Clock override test"
122 # Test without the plugin
123 diag
"Plugin disabled"
125 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
126 enable_ust_lttng_event_ok
$SESSION_NAME "$EVENT_NAME"
127 start_lttng_tracing_ok
$SESSION_NAME
129 stop_lttng_tracing_ok
$SESSION_NAME
130 destroy_lttng_session_ok
$SESSION_NAME
132 # Use Babeltrace with "-n all" to give a comma separated list for
133 # easy extraction of timestamps.
134 unique_timestamps_count
=$
($BABELTRACE_BIN -n all
$TRACE_PATH | \
135 cut
-d, -f1 |
uniq |
wc -l)
136 test $unique_timestamps_count -gt 1
137 ok $?
"Unique event timestamps without clock override: $unique_timestamps_count expect >1"
140 # Test with clock override plugin.
141 # LTTNG_UST_CLOCK_PLUGIN need to be defined for both lttng-sessiond.
142 diag
"Plugin enabled"
143 export LTTNG_UST_CLOCK_PLUGIN
=$CURDIR/.libs
/$LTTNG_UST_CLOCK_PLUGIN_SO
145 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
146 enable_ust_lttng_event_ok
$SESSION_NAME "$EVENT_NAME"
147 start_lttng_tracing_ok
$SESSION_NAME
149 unset LTTNG_UST_CLOCK_PLUGIN
150 stop_lttng_tracing_ok
$SESSION_NAME
151 destroy_lttng_session_ok
$SESSION_NAME
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 plan_tests
$NUM_TESTS
164 print_test_banner
"$TEST_DESC"
166 if [ -x "$CURDIR/$LIBS_DIR/$LTTNG_UST_CLOCK_PLUGIN_SO" ]; then
172 skip
$foundobj "No shared object generated. Skipping all tests." $NUM_TESTS && exit 0
175 "test_getcpu_override_metadata"
176 "test_getcpu_override_timestamp"
179 TEST_COUNT
=${#TESTS[@]}
182 while [ "$i" -lt "$TEST_COUNT" ]; do
184 TRACE_PATH
=$
(mktemp
-d)