Build: look for python >= 3.0 when building python bindings
[lttng-tools.git] / tests / regression / ust / clock-override / test_clock_override
CommitLineData
199800b2
JR
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
17TEST_DESC="UST - Getcpu override plugin"
18
19CURDIR=$(dirname $0)/
20TESTDIR=$CURDIR/../../..
21SESSION_NAME="clock_override"
22
23TESTAPP_PATH="$TESTDIR/utils/testapp"
24TESTAPP_NAME="gen-ust-events"
25TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
26TESTAPP_WRAPPER="run-getcpu-override"
27NUM_EVENT=256
28EVENT_NAME="tp:tptest"
29LTTNG_UST_CLOCK_PLUGIN_SO="lttng-ust-clock-override-test.so"
30LIBS_DIR=".libs"
31
32METADATA_CLOCK_START_TOKEN="clock {"
33METADATA_CLOCK_END_TOKEN="};"
34
35METADATA_TOKEN_LIST=(
36 "name"
37 "uuid"
38 "description"
39 "freq"
40)
41
42UST_CLOCK_TOKEN_VALUE=(
43 "lttng_test_clock_override"
44 "83c63deb-7aa4-48fb-abda-946f400d76e6"
45 "Freeze time with 1KHz for regression test"
46 "1000"
47)
48
49NUM_TESTS=33
50
51source $TESTDIR/utils/utils.sh
52
53if [ ! -x "$CURDIR/$LIBS_DIR/$LTTNG_UST_CLOCK_PLUGIN_SO" ]; then
54 BAIL_OUT "No shared object generated"
55fi
56
57# MUST set TESTDIR before calling those functions
58function run_app()
59{
60 $TESTAPP_BIN $NUM_EVENT
61 ok $? "Application done"
62}
63
64function extract_clock_metadata()
65{
66 local metadata_file=$1
67 local clock_metadata_file_destination=$2
68 cat $metadata_file \
69 | sed -n "/$METADATA_CLOCK_START_TOKEN/,/$METADATA_CLOCK_END_TOKEN/p" \
70 > $clock_metadata_file_destination
71 ok $? "Clock metadata extraction"
72}
73
74function extract_clock_metadata_token()
75{
76 local clock_metadata_file=$1
77 local token=$2
78 # Look for token and get value between ""
79 cat $clock_metadata_file | grep $token | awk -F"= |;" '{print $2}' | tr -d '"'
80}
81
82function test_getcpu_override_metadata()
83{
84 local ctf_metadata_file=$(mktemp -p $TRACE_PATH ctf-metadata.XXXXX)
85 local clock_metadata_file=$(mktemp -p $TRACE_PATH clock-metadata.XXXXX)
86 local result=""
87
88 diag "Clock override plugin metadata test"
89
90 # LTTNG_UST_CLOCK_PLUGIN need to be defined for lttng-sessiond.
91 export LTTNG_UST_CLOCK_PLUGIN=$CURDIR/.libs/$LTTNG_UST_CLOCK_PLUGIN_SO
92 start_lttng_sessiond
93 unset LTTNG_UST_CLOCK_PLUGIN
94
95 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
96 enable_ust_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
97 start_lttng_tracing_ok $SESSION_NAME
98 run_app
99 stop_lttng_tracing_ok $SESSION_NAME
100 destroy_lttng_session_ok $SESSION_NAME
101 stop_lttng_sessiond
102
103 $BABELTRACE_BIN -o ctf-metadata -w $ctf_metadata_file $TRACE_PATH
104 ok $? "Metadata extraction from babeltrace"
105
106 extract_clock_metadata $ctf_metadata_file $clock_metadata_file
107
108 test ${#METADATA_TOKEN_LIST[@]} -eq ${#UST_CLOCK_TOKEN_VALUE[@]}
109 ok $? "Tokens to check(${#METADATA_TOKEN_LIST[@]}) and provided values(${#UST_CLOCK_TOKEN_VALUE[@]}) count is equal"
110
111 local counter=0
112 while [ "$counter" -lt "${#METADATA_TOKEN_LIST[@]}" ]; do
113 result=$(extract_clock_metadata_token $clock_metadata_file \
114 ${METADATA_TOKEN_LIST[$counter]})
115 test "$result" == "${UST_CLOCK_TOKEN_VALUE[$counter]}"
116 ok $? "Token \"${METADATA_TOKEN_LIST[$counter]}\" expect:${UST_CLOCK_TOKEN_VALUE[$counter]} got:$result"
117 let "counter++"
118 done
119 rm -rf $ctf_metadata_file
120 rm -rf $clock_metadata_file
121}
122
123function test_getcpu_override_timestamp()
124{
125 diag "Clock override test"
126
127 # Test without the plugin
128 diag "Plugin disabled"
129 start_lttng_sessiond
130 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
131 enable_ust_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
132 start_lttng_tracing_ok $SESSION_NAME
133 run_app
134 stop_lttng_tracing_ok $SESSION_NAME
135 destroy_lttng_session_ok $SESSION_NAME
136
137 # Use Babeltrace with "-n all" to give a comma separated list for
138 # easy extraction of timestamps.
139 unique_timestamps_count=$($BABELTRACE_BIN -n all $TRACE_PATH | \
140 cut -d, -f1 | uniq | wc -l)
141 test $unique_timestamps_count -gt 1
142 ok $? "Unique event timestamps without clock override: $unique_timestamps_count expect >1"
143 stop_lttng_sessiond
144
145 # Test with clock override plugin.
146 # LTTNG_UST_CLOCK_PLUGIN need to be defined for both lttng-sessiond.
147 diag "Plugin enabled"
148 export LTTNG_UST_CLOCK_PLUGIN=$CURDIR/.libs/$LTTNG_UST_CLOCK_PLUGIN_SO
149 start_lttng_sessiond
150 unset LTTNG_UST_CLOCK_PLUGIN
151 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
152 enable_ust_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
153 start_lttng_tracing_ok $SESSION_NAME
154 run_app
155 stop_lttng_tracing_ok $SESSION_NAME
156 destroy_lttng_session_ok $SESSION_NAME
157 stop_lttng_sessiond
158
159 # Use Babeltrace with "-n all" to give a comma separated list for
160 # easy extraction of timestamps.
161 unique_timestamps_count=$($BABELTRACE_BIN -n all $TRACE_PATH | \
162 cut -d, -f1 | uniq | wc -l)
163 test $unique_timestamps_count -eq 1
164 ok $? "Unique event timestamps with clock override: $unique_timestamps_count expect 1"
165}
166
167plan_tests $NUM_TESTS
168
169print_test_banner "$TEST_DESC"
170
171TESTS=(
172 "test_getcpu_override_metadata"
173 "test_getcpu_override_timestamp"
174)
175
176TEST_COUNT=${#TESTS[@]}
177i=0
178
179while [ "$i" -lt "$TEST_COUNT" ]; do
180
181 TRACE_PATH=$(mktemp -d)
182
183 # Execute test
184 ${TESTS[$i]}
185
186 rm -rf $TRACE_PATH
187
188 let "i++"
189done
190
This page took 0.029129 seconds and 4 git commands to generate.