Gen-ust-events: use options instead of arguments
[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
e10ccd82 17TEST_DESC="UST - Clock override plugin"
199800b2
JR
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"
199800b2
JR
26NUM_EVENT=256
27EVENT_NAME="tp:tptest"
28LTTNG_UST_CLOCK_PLUGIN_SO="lttng-ust-clock-override-test.so"
29LIBS_DIR=".libs"
30
31METADATA_CLOCK_START_TOKEN="clock {"
32METADATA_CLOCK_END_TOKEN="};"
33
34METADATA_TOKEN_LIST=(
35 "name"
36 "uuid"
37 "description"
38 "freq"
39)
40
41UST_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
48NUM_TESTS=33
49
50source $TESTDIR/utils/utils.sh
51
199800b2
JR
52# MUST set TESTDIR before calling those functions
53function run_app()
54{
a4c30524 55 $TESTAPP_BIN -i $NUM_EVENT
199800b2
JR
56 ok $? "Application done"
57}
58
59function 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
69function 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
77function test_getcpu_override_metadata()
78{
8d12820e
NL
79 local ctf_metadata_file=$(mktemp -p $TRACE_PATH ctf-metadata.XXXXXX)
80 local clock_metadata_file=$(mktemp -p $TRACE_PATH clock-metadata.XXXXXX)
199800b2
JR
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
3d2deead
JG
98 local TRACE_METADATA_FILE_PATH="$(find "$TRACE_PATH" -name metadata -type f)"
99 local TRACE_METADATA_DIR="$(dirname "$TRACE_METADATA_FILE_PATH")"
100
101 $BABELTRACE_BIN -o ctf-metadata -w $ctf_metadata_file $TRACE_METADATA_DIR
199800b2
JR
102 ok $? "Metadata extraction from babeltrace"
103
104 extract_clock_metadata $ctf_metadata_file $clock_metadata_file
105
106 test ${#METADATA_TOKEN_LIST[@]} -eq ${#UST_CLOCK_TOKEN_VALUE[@]}
107 ok $? "Tokens to check(${#METADATA_TOKEN_LIST[@]}) and provided values(${#UST_CLOCK_TOKEN_VALUE[@]}) count is equal"
108
109 local counter=0
110 while [ "$counter" -lt "${#METADATA_TOKEN_LIST[@]}" ]; do
111 result=$(extract_clock_metadata_token $clock_metadata_file \
112 ${METADATA_TOKEN_LIST[$counter]})
113 test "$result" == "${UST_CLOCK_TOKEN_VALUE[$counter]}"
114 ok $? "Token \"${METADATA_TOKEN_LIST[$counter]}\" expect:${UST_CLOCK_TOKEN_VALUE[$counter]} got:$result"
115 let "counter++"
116 done
117 rm -rf $ctf_metadata_file
118 rm -rf $clock_metadata_file
119}
120
121function test_getcpu_override_timestamp()
122{
123 diag "Clock override test"
124
125 # Test without the plugin
126 diag "Plugin disabled"
127 start_lttng_sessiond
128 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
129 enable_ust_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
130 start_lttng_tracing_ok $SESSION_NAME
131 run_app
132 stop_lttng_tracing_ok $SESSION_NAME
133 destroy_lttng_session_ok $SESSION_NAME
134
135 # Use Babeltrace with "-n all" to give a comma separated list for
136 # easy extraction of timestamps.
137 unique_timestamps_count=$($BABELTRACE_BIN -n all $TRACE_PATH | \
138 cut -d, -f1 | uniq | wc -l)
139 test $unique_timestamps_count -gt 1
140 ok $? "Unique event timestamps without clock override: $unique_timestamps_count expect >1"
141 stop_lttng_sessiond
142
143 # Test with clock override plugin.
144 # LTTNG_UST_CLOCK_PLUGIN need to be defined for both lttng-sessiond.
145 diag "Plugin enabled"
146 export LTTNG_UST_CLOCK_PLUGIN=$CURDIR/.libs/$LTTNG_UST_CLOCK_PLUGIN_SO
147 start_lttng_sessiond
199800b2
JR
148 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
149 enable_ust_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
150 start_lttng_tracing_ok $SESSION_NAME
151 run_app
1df1febe 152 unset LTTNG_UST_CLOCK_PLUGIN
199800b2
JR
153 stop_lttng_tracing_ok $SESSION_NAME
154 destroy_lttng_session_ok $SESSION_NAME
155 stop_lttng_sessiond
156
157 # Use Babeltrace with "-n all" to give a comma separated list for
158 # easy extraction of timestamps.
159 unique_timestamps_count=$($BABELTRACE_BIN -n all $TRACE_PATH | \
160 cut -d, -f1 | uniq | wc -l)
161 test $unique_timestamps_count -eq 1
162 ok $? "Unique event timestamps with clock override: $unique_timestamps_count expect 1"
163}
164
165plan_tests $NUM_TESTS
166
167print_test_banner "$TEST_DESC"
168
f37e092d
MD
169if [ -x "$CURDIR/$LIBS_DIR/$LTTNG_UST_CLOCK_PLUGIN_SO" ]; then
170 foundobj=1
171else
172 foundobj=0
173fi
174
175skip $foundobj "No shared object generated. Skipping all tests." $NUM_TESTS && exit 0
176
199800b2
JR
177TESTS=(
178 "test_getcpu_override_metadata"
179 "test_getcpu_override_timestamp"
180)
181
182TEST_COUNT=${#TESTS[@]}
183i=0
184
185while [ "$i" -lt "$TEST_COUNT" ]; do
186
187 TRACE_PATH=$(mktemp -d)
188
189 # Execute test
190 ${TESTS[$i]}
191
192 rm -rf $TRACE_PATH
193
194 let "i++"
195done
196
This page took 0.070891 seconds and 5 git commands to generate.