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 - Getcpu 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 if [ ! -x "$CURDIR/$LIBS_DIR/$LTTNG_UST_CLOCK_PLUGIN_SO" ]; then
53 BAIL_OUT
"No shared object generated"
56 # MUST set TESTDIR before calling those functions
59 $TESTAPP_BIN $NUM_EVENT
60 ok $?
"Application done"
63 function extract_clock_metadata
()
65 local metadata_file
=$1
66 local clock_metadata_file_destination
=$2
68 |
sed -n "/$METADATA_CLOCK_START_TOKEN/,/$METADATA_CLOCK_END_TOKEN/p" \
69 > $clock_metadata_file_destination
70 ok $?
"Clock metadata extraction"
73 function extract_clock_metadata_token
()
75 local clock_metadata_file
=$1
77 # Look for token and get value between ""
78 cat $clock_metadata_file |
grep $token |
awk -F"= |;" '{print $2}' |
tr -d '"'
81 function test_getcpu_override_metadata
()
83 local ctf_metadata_file
=$
(mktemp
-p $TRACE_PATH ctf-metadata.XXXXX
)
84 local clock_metadata_file
=$
(mktemp
-p $TRACE_PATH clock-metadata.XXXXX
)
87 diag
"Clock override plugin metadata test"
89 # LTTNG_UST_CLOCK_PLUGIN need to be defined for lttng-sessiond.
90 export LTTNG_UST_CLOCK_PLUGIN
=$CURDIR/.libs
/$LTTNG_UST_CLOCK_PLUGIN_SO
92 unset LTTNG_UST_CLOCK_PLUGIN
94 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
95 enable_ust_lttng_event_ok
$SESSION_NAME "$EVENT_NAME"
96 start_lttng_tracing_ok
$SESSION_NAME
98 stop_lttng_tracing_ok
$SESSION_NAME
99 destroy_lttng_session_ok
$SESSION_NAME
102 $BABELTRACE_BIN -o ctf-metadata
-w $ctf_metadata_file $TRACE_PATH
103 ok $?
"Metadata extraction from babeltrace"
105 extract_clock_metadata
$ctf_metadata_file $clock_metadata_file
107 test ${#METADATA_TOKEN_LIST[@]} -eq ${#UST_CLOCK_TOKEN_VALUE[@]}
108 ok $?
"Tokens to check(${#METADATA_TOKEN_LIST[@]}) and provided values(${#UST_CLOCK_TOKEN_VALUE[@]}) count is equal"
111 while [ "$counter" -lt "${#METADATA_TOKEN_LIST[@]}" ]; do
112 result
=$
(extract_clock_metadata_token
$clock_metadata_file \
113 ${METADATA_TOKEN_LIST[$counter]})
114 test "$result" == "${UST_CLOCK_TOKEN_VALUE[$counter]}"
115 ok $?
"Token \"${METADATA_TOKEN_LIST[$counter]}\" expect:${UST_CLOCK_TOKEN_VALUE[$counter]} got:$result"
118 rm -rf $ctf_metadata_file
119 rm -rf $clock_metadata_file
122 function test_getcpu_override_timestamp
()
124 diag
"Clock override test"
126 # Test without the plugin
127 diag
"Plugin disabled"
129 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
130 enable_ust_lttng_event_ok
$SESSION_NAME "$EVENT_NAME"
131 start_lttng_tracing_ok
$SESSION_NAME
133 stop_lttng_tracing_ok
$SESSION_NAME
134 destroy_lttng_session_ok
$SESSION_NAME
136 # Use Babeltrace with "-n all" to give a comma separated list for
137 # easy extraction of timestamps.
138 unique_timestamps_count
=$
($BABELTRACE_BIN -n all
$TRACE_PATH | \
139 cut
-d, -f1 |
uniq |
wc -l)
140 test $unique_timestamps_count -gt 1
141 ok $?
"Unique event timestamps without clock override: $unique_timestamps_count expect >1"
144 # Test with clock override plugin.
145 # LTTNG_UST_CLOCK_PLUGIN need to be defined for both lttng-sessiond.
146 diag
"Plugin enabled"
147 export LTTNG_UST_CLOCK_PLUGIN
=$CURDIR/.libs
/$LTTNG_UST_CLOCK_PLUGIN_SO
149 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
150 enable_ust_lttng_event_ok
$SESSION_NAME "$EVENT_NAME"
151 start_lttng_tracing_ok
$SESSION_NAME
153 unset LTTNG_UST_CLOCK_PLUGIN
154 stop_lttng_tracing_ok
$SESSION_NAME
155 destroy_lttng_session_ok
$SESSION_NAME
158 # Use Babeltrace with "-n all" to give a comma separated list for
159 # easy extraction of timestamps.
160 unique_timestamps_count
=$
($BABELTRACE_BIN -n all
$TRACE_PATH | \
161 cut
-d, -f1 |
uniq |
wc -l)
162 test $unique_timestamps_count -eq 1
163 ok $?
"Unique event timestamps with clock override: $unique_timestamps_count expect 1"
166 plan_tests
$NUM_TESTS
168 print_test_banner
"$TEST_DESC"
171 "test_getcpu_override_metadata"
172 "test_getcpu_override_timestamp"
175 TEST_COUNT
=${#TESTS[@]}
178 while [ "$i" -lt "$TEST_COUNT" ]; do
180 TRACE_PATH
=$
(mktemp
-d)