Fix: tests: skip tests on static build
[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 # MUST set TESTDIR before calling those functions
53 function run_app()
54 {
55 $TESTAPP_BIN $NUM_EVENT
56 ok $? "Application done"
57 }
58
59 function extract_clock_metadata()
60 {
61 local metadata_file=$1
62 local clock_metadata_file_destination=$2
63 cat $metadata_file \
64 | sed -n "/$METADATA_CLOCK_START_TOKEN/,/$METADATA_CLOCK_END_TOKEN/p" \
65 > $clock_metadata_file_destination
66 ok $? "Clock metadata extraction"
67 }
68
69 function extract_clock_metadata_token()
70 {
71 local clock_metadata_file=$1
72 local token=$2
73 # Look for token and get value between ""
74 cat $clock_metadata_file | grep $token | awk -F"= |;" '{print $2}' | tr -d '"'
75 }
76
77 function test_getcpu_override_metadata()
78 {
79 local ctf_metadata_file=$(mktemp -p $TRACE_PATH ctf-metadata.XXXXX)
80 local clock_metadata_file=$(mktemp -p $TRACE_PATH clock-metadata.XXXXX)
81 local result=""
82
83 diag "Clock override plugin metadata test"
84
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
87 start_lttng_sessiond
88 unset LTTNG_UST_CLOCK_PLUGIN
89
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
93 run_app
94 stop_lttng_tracing_ok $SESSION_NAME
95 destroy_lttng_session_ok $SESSION_NAME
96 stop_lttng_sessiond
97
98 $BABELTRACE_BIN -o ctf-metadata -w $ctf_metadata_file $TRACE_PATH
99 ok $? "Metadata extraction from babeltrace"
100
101 extract_clock_metadata $ctf_metadata_file $clock_metadata_file
102
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"
105
106 local counter=0
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"
112 let "counter++"
113 done
114 rm -rf $ctf_metadata_file
115 rm -rf $clock_metadata_file
116 }
117
118 function test_getcpu_override_timestamp()
119 {
120 diag "Clock override test"
121
122 # Test without the plugin
123 diag "Plugin disabled"
124 start_lttng_sessiond
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
128 run_app
129 stop_lttng_tracing_ok $SESSION_NAME
130 destroy_lttng_session_ok $SESSION_NAME
131
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"
138 stop_lttng_sessiond
139
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
144 start_lttng_sessiond
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
148 run_app
149 unset LTTNG_UST_CLOCK_PLUGIN
150 stop_lttng_tracing_ok $SESSION_NAME
151 destroy_lttng_session_ok $SESSION_NAME
152 stop_lttng_sessiond
153
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"
160 }
161
162 plan_tests $NUM_TESTS
163
164 print_test_banner "$TEST_DESC"
165
166 if [ -x "$CURDIR/$LIBS_DIR/$LTTNG_UST_CLOCK_PLUGIN_SO" ]; then
167 foundobj=1
168 else
169 foundobj=0
170 fi
171
172 skip $foundobj "No shared object generated. Skipping all tests." $NUM_TESTS && exit 0
173
174 TESTS=(
175 "test_getcpu_override_metadata"
176 "test_getcpu_override_timestamp"
177 )
178
179 TEST_COUNT=${#TESTS[@]}
180 i=0
181
182 while [ "$i" -lt "$TEST_COUNT" ]; do
183
184 TRACE_PATH=$(mktemp -d)
185
186 # Execute test
187 ${TESTS[$i]}
188
189 rm -rf $TRACE_PATH
190
191 let "i++"
192 done
193
This page took 0.048782 seconds and 4 git commands to generate.