tests: invoke full_cleanup from script trap handlers, use modprobe -r
[lttng-tools.git] / tests / regression / kernel / test_clock_override
CommitLineData
002db623
MD
1#!/bin/bash
2#
3# Copyright (C) - 2013 Christian Babeux <christian.babeux@efficios.com>
4# Copyright (C) - 2014, 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5#
6# This program is free software; you can redistribute it and/or modify it
7# under the terms of the GNU General Public License, version 2 only, as
8# published by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13# more details.
14#
15# You should have received a copy of the GNU General Public License along with
16# this program; if not, write to the Free Software Foundation, Inc., 51
17# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19TEST_DESC="Kernel tracer - Clock override plugin"
20
21CURDIR=$(dirname $0)/
22TESTDIR=$CURDIR/../..
23SESSION_NAME="clock_override"
24
25NUM_TESTS=30
26EVENT_NAME="lttng_test_filter_event"
27
28TESTCMD="echo -n 10 > /proc/lttng-test-filter-event"
29
30METADATA_CLOCK_START_TOKEN="clock {"
31METADATA_CLOCK_END_TOKEN="};"
32
33METADATA_TOKEN_LIST=(
34 "name"
35 "uuid"
36 "description"
37 "freq"
38)
39
40CLOCK_TOKEN_VALUE=(
41 "lttng_test_clock_override"
42 "83c63deb-7aa4-48fb-abda-946f400d76e6"
43 "Freeze time with 1KHz for regression test"
44 "1000"
45)
46
47source $TESTDIR/utils/utils.sh
48
49function signal_cleanup()
50{
51 diag "*** Exiting ***"
002db623 52 stop_lttng_sessiond
3be453c9
MD
53 modprobe -r lttng-test lttng-clock-plugin-test lttng-clock
54 full_cleanup
002db623
MD
55}
56
57function extract_clock_metadata()
58{
59 local metadata_file=$1
60 local clock_metadata_file_destination=$2
61 cat $metadata_file \
62 | sed -n "/$METADATA_CLOCK_START_TOKEN/,/$METADATA_CLOCK_END_TOKEN/p" \
63 > $clock_metadata_file_destination
64 ok $? "Clock metadata extraction"
65}
66
67function extract_clock_metadata_token()
68{
69 local clock_metadata_file=$1
70 local token=$2
71 # Look for token and get value between ""
72 cat $clock_metadata_file | grep $token | awk -F"= |;" '{print $2}' | tr -d '"'
73}
74
75function test_clock_override_metadata()
76{
8d12820e
NL
77 local ctf_metadata_file=$(mktemp -p $TRACE_PATH ctf-metadata.XXXXXX)
78 local clock_metadata_file=$(mktemp -p $TRACE_PATH clock-metadata.XXXXXX)
002db623
MD
79 local result=""
80
81 diag "Clock override plugin metadata test"
82
83 modprobe lttng-clock-plugin-test
84 start_lttng_sessiond
85 modprobe lttng-test
86
87 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
88 enable_kernel_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
89 start_lttng_tracing_ok $SESSION_NAME
90 eval ${TESTCMD}
91 stop_lttng_tracing_ok $SESSION_NAME
92 destroy_lttng_session_ok $SESSION_NAME
93
002db623 94 stop_lttng_sessiond
3be453c9 95 modprobe -r lttng-test lttng-clock-plugin-test lttng-clock
002db623 96
3d2deead
JG
97 local TRACE_METADATA_FILE_PATH="$(find "$TRACE_PATH" -name metadata -type f)"
98 local TRACE_METADATA_DIR="$(dirname "$TRACE_METADATA_FILE_PATH")"
99
100 $BABELTRACE_BIN -o ctf-metadata -w $ctf_metadata_file $TRACE_METADATA_DIR
002db623
MD
101 ok $? "Metadata extraction from babeltrace"
102
103 extract_clock_metadata $ctf_metadata_file $clock_metadata_file
104
105 test ${#METADATA_TOKEN_LIST[@]} -eq ${#CLOCK_TOKEN_VALUE[@]}
106 ok $? "Tokens to check(${#METADATA_TOKEN_LIST[@]}) and provided values(${#CLOCK_TOKEN_VALUE[@]}) count is equal"
107
108 local counter=0
109 while [ "$counter" -lt "${#METADATA_TOKEN_LIST[@]}" ]; do
110 result=$(extract_clock_metadata_token $clock_metadata_file \
111 ${METADATA_TOKEN_LIST[$counter]})
112 test "$result" == "${CLOCK_TOKEN_VALUE[$counter]}"
113 ok $? "Token \"${METADATA_TOKEN_LIST[$counter]}\" expect:${CLOCK_TOKEN_VALUE[$counter]} got:$result"
114 let "counter++"
115 done
116 rm -rf $ctf_metadata_file
117 rm -rf $clock_metadata_file
118}
119
120function test_clock_override_timestamp()
121{
122 diag "Clock override test"
123
124 # Test without the plugin
125 diag "Plugin disabled"
126
127 start_lttng_sessiond
128 modprobe lttng-test
129
130 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
131 enable_kernel_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
132 start_lttng_tracing_ok $SESSION_NAME
133 eval ${TESTCMD}
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 rmmod lttng-test
144 stop_lttng_sessiond
145
146 # Test with clock override plugin.
147 diag "Plugin enabled"
148
149 modprobe lttng-clock-plugin-test
150 start_lttng_sessiond
151 modprobe lttng-test
152
153 start_lttng_sessiond
154 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
155 enable_kernel_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
156 start_lttng_tracing_ok $SESSION_NAME
157 eval ${TESTCMD}
158 stop_lttng_tracing_ok $SESSION_NAME
159 destroy_lttng_session_ok $SESSION_NAME
160
161 rmmod lttng-test
162 stop_lttng_sessiond
163 rmmod lttng-clock-plugin-test
164 rmmod lttng-clock
165
166 # Use Babeltrace with "-n all" to give a comma separated list for
167 # easy extraction of timestamps.
168 unique_timestamps_count=$($BABELTRACE_BIN -n all $TRACE_PATH | \
169 cut -d, -f1 | uniq | wc -l)
170 test $unique_timestamps_count -eq 1
171 ok $? "Unique event timestamps with clock override: $unique_timestamps_count expect 1"
172}
173
174# MUST set TESTDIR before calling those functions
175plan_tests $NUM_TESTS
176
177print_test_banner "$TEST_DESC"
178
179TESTS=(
180 "test_clock_override_metadata"
181 "test_clock_override_timestamp"
182)
183
184TEST_COUNT=${#TESTS[@]}
185i=0
186
187if [ "$(id -u)" == "0" ]; then
188 isroot=1
189else
190 isroot=0
191fi
192
193skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
194{
195 trap signal_cleanup SIGTERM SIGINT
196
197 while [ "$i" -lt "$TEST_COUNT" ]; do
198
199 TRACE_PATH=$(mktemp -d)
200
201 # Execute test
202 ${TESTS[$i]}
203
204 rm -rf $TRACE_PATH
205
206 let "i++"
207 done
208}
This page took 0.062111 seconds and 5 git commands to generate.