f4a5feaee3f7151177a6fe6ed3b33458d7dd4503
[lttng-tools.git] / tests / regression / ust / clock-override / test_clock_override
1 #!/bin/bash
2 #
3 # Copyright (C) - 2015 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
4 #
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.
8 #
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
12 # details.
13 #
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"
18
19 CURDIR=$(dirname $0)/
20 TESTDIR=$CURDIR/../../..
21 SESSION_NAME="clock_override"
22
23 TESTAPP_PATH="$TESTDIR/utils/testapp"
24 TESTAPP_NAME="gen-ust-events"
25 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
26 NUM_EVENT=256
27 EVENT_NAME="tp:tptest"
28 LTTNG_UST_CLOCK_PLUGIN_SO="lttng-ust-clock-override-test.so"
29 LIBS_DIR=".libs"
30
31 METADATA_CLOCK_START_TOKEN="clock {"
32 METADATA_CLOCK_END_TOKEN="};"
33
34 METADATA_TOKEN_LIST=(
35 "name"
36 "uuid"
37 "description"
38 "freq"
39 )
40
41 UST_CLOCK_TOKEN_VALUE=(
42 "lttng_test_clock_override"
43 "83c63deb-7aa4-48fb-abda-946f400d76e6"
44 "Freeze time with 1KHz for regression test"
45 "1000"
46 )
47
48 NUM_TESTS=33
49
50 source $TESTDIR/utils/utils.sh
51
52 if [ ! -x "$CURDIR/$LIBS_DIR/$LTTNG_UST_CLOCK_PLUGIN_SO" ]; then
53 BAIL_OUT "No shared object generated"
54 fi
55
56 # MUST set TESTDIR before calling those functions
57 function run_app()
58 {
59 $TESTAPP_BIN $NUM_EVENT
60 ok $? "Application done"
61 }
62
63 function extract_clock_metadata()
64 {
65 local metadata_file=$1
66 local clock_metadata_file_destination=$2
67 cat $metadata_file \
68 | sed -n "/$METADATA_CLOCK_START_TOKEN/,/$METADATA_CLOCK_END_TOKEN/p" \
69 > $clock_metadata_file_destination
70 ok $? "Clock metadata extraction"
71 }
72
73 function extract_clock_metadata_token()
74 {
75 local clock_metadata_file=$1
76 local token=$2
77 # Look for token and get value between ""
78 cat $clock_metadata_file | grep $token | awk -F"= |;" '{print $2}' | tr -d '"'
79 }
80
81 function test_getcpu_override_metadata()
82 {
83 local ctf_metadata_file=$(mktemp -p $TRACE_PATH ctf-metadata.XXXXX)
84 local clock_metadata_file=$(mktemp -p $TRACE_PATH clock-metadata.XXXXX)
85 local result=""
86
87 diag "Clock override plugin metadata test"
88
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
91 start_lttng_sessiond
92 unset LTTNG_UST_CLOCK_PLUGIN
93
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
97 run_app
98 stop_lttng_tracing_ok $SESSION_NAME
99 destroy_lttng_session_ok $SESSION_NAME
100 stop_lttng_sessiond
101
102 $BABELTRACE_BIN -o ctf-metadata -w $ctf_metadata_file $TRACE_PATH
103 ok $? "Metadata extraction from babeltrace"
104
105 extract_clock_metadata $ctf_metadata_file $clock_metadata_file
106
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"
109
110 local counter=0
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"
116 let "counter++"
117 done
118 rm -rf $ctf_metadata_file
119 rm -rf $clock_metadata_file
120 }
121
122 function test_getcpu_override_timestamp()
123 {
124 diag "Clock override test"
125
126 # Test without the plugin
127 diag "Plugin disabled"
128 start_lttng_sessiond
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
132 run_app
133 stop_lttng_tracing_ok $SESSION_NAME
134 destroy_lttng_session_ok $SESSION_NAME
135
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"
142 stop_lttng_sessiond
143
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
148 start_lttng_sessiond
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
152 run_app
153 unset LTTNG_UST_CLOCK_PLUGIN
154 stop_lttng_tracing_ok $SESSION_NAME
155 destroy_lttng_session_ok $SESSION_NAME
156 stop_lttng_sessiond
157
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"
164 }
165
166 plan_tests $NUM_TESTS
167
168 print_test_banner "$TEST_DESC"
169
170 TESTS=(
171 "test_getcpu_override_metadata"
172 "test_getcpu_override_timestamp"
173 )
174
175 TEST_COUNT=${#TESTS[@]}
176 i=0
177
178 while [ "$i" -lt "$TEST_COUNT" ]; do
179
180 TRACE_PATH=$(mktemp -d)
181
182 # Execute test
183 ${TESTS[$i]}
184
185 rm -rf $TRACE_PATH
186
187 let "i++"
188 done
189
This page took 0.050576 seconds and 3 git commands to generate.