Tests: add kernel test into the `make check` test suite.
[lttng-tools.git] / tests / regression / kernel / test_clock_override
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 # SPDX-License-Identifier: GPL-2.0-only
7 #
8
9 TEST_DESC="Kernel tracer - Clock override plugin"
10
11 CURDIR=$(dirname $0)/
12 TESTDIR=$CURDIR/../..
13 SESSION_NAME="clock_override"
14
15 NUM_TESTS=30
16 EVENT_NAME="lttng_test_filter_event"
17
18 TESTCMD="echo -n 10 > /proc/lttng-test-filter-event"
19
20 METADATA_CLOCK_START_TOKEN="clock {"
21 METADATA_CLOCK_END_TOKEN="};"
22
23 METADATA_TOKEN_LIST=(
24 "name"
25 "uuid"
26 "description"
27 "freq"
28 )
29
30 CLOCK_TOKEN_VALUE=(
31 "lttng_test_clock_override"
32 "83c63deb-7aa4-48fb-abda-946f400d76e6"
33 "Freeze time with 1KHz for regression test"
34 "1000"
35 )
36
37 source $TESTDIR/utils/utils.sh
38
39 function signal_cleanup()
40 {
41 diag "*** Exiting ***"
42 stop_lttng_sessiond
43 modprobe --remove lttng-test lttng-clock-plugin-test lttng-clock
44 full_cleanup
45 }
46
47 function extract_clock_metadata()
48 {
49 local metadata_file=$1
50 local clock_metadata_file_destination=$2
51 cat $metadata_file \
52 | sed -n "/$METADATA_CLOCK_START_TOKEN/,/$METADATA_CLOCK_END_TOKEN/p" \
53 > $clock_metadata_file_destination
54 ok $? "Clock metadata extraction"
55 }
56
57 function extract_clock_metadata_token()
58 {
59 local clock_metadata_file=$1
60 local token=$2
61 # Look for token and get value between ""
62 cat $clock_metadata_file | grep $token | awk -F"= |;" '{print $2}' | tr -d '"'
63 }
64
65 function test_clock_override_metadata()
66 {
67 local ctf_metadata_file=$(mktemp --tmpdir -p $TRACE_PATH ctf-metadata.XXXXXX)
68 local clock_metadata_file=$(mktemp --tmpdir -p $TRACE_PATH clock-metadata.XXXXXX)
69 local result=""
70
71 diag "Clock override plugin metadata test"
72
73 modprobe lttng-clock-plugin-test
74 start_lttng_sessiond
75 modprobe lttng-test
76
77 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
78 enable_kernel_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
79 start_lttng_tracing_ok $SESSION_NAME
80 eval ${TESTCMD}
81 stop_lttng_tracing_ok $SESSION_NAME
82 destroy_lttng_session_ok $SESSION_NAME
83
84 stop_lttng_sessiond
85 modprobe --remove lttng-test lttng-clock-plugin-test lttng-clock
86
87 local TRACE_METADATA_FILE_PATH="$(find "$TRACE_PATH" -name metadata -type f)"
88 local TRACE_METADATA_DIR="$(dirname "$TRACE_METADATA_FILE_PATH")"
89
90 $BABELTRACE_BIN -o ctf-metadata -w $ctf_metadata_file $TRACE_METADATA_DIR
91 ok $? "Metadata extraction from babeltrace"
92
93 extract_clock_metadata $ctf_metadata_file $clock_metadata_file
94
95 test ${#METADATA_TOKEN_LIST[@]} -eq ${#CLOCK_TOKEN_VALUE[@]}
96 ok $? "Tokens to check(${#METADATA_TOKEN_LIST[@]}) and provided values(${#CLOCK_TOKEN_VALUE[@]}) count is equal"
97
98 local counter=0
99 while [ "$counter" -lt "${#METADATA_TOKEN_LIST[@]}" ]; do
100 result=$(extract_clock_metadata_token $clock_metadata_file \
101 ${METADATA_TOKEN_LIST[$counter]})
102 test "$result" == "${CLOCK_TOKEN_VALUE[$counter]}"
103 ok $? "Token \"${METADATA_TOKEN_LIST[$counter]}\" expect:${CLOCK_TOKEN_VALUE[$counter]} got:$result"
104 let "counter++"
105 done
106 rm -rf $ctf_metadata_file
107 rm -rf $clock_metadata_file
108 }
109
110 function test_clock_override_timestamp()
111 {
112 diag "Clock override test"
113
114 # Test without the plugin
115 diag "Plugin disabled"
116
117 start_lttng_sessiond
118 modprobe lttng-test
119
120 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
121 enable_kernel_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
122 start_lttng_tracing_ok $SESSION_NAME
123 eval ${TESTCMD}
124 stop_lttng_tracing_ok $SESSION_NAME
125 destroy_lttng_session_ok $SESSION_NAME
126
127 # Use Babeltrace with "-n all" to give a comma separated list for
128 # easy extraction of timestamps.
129 unique_timestamps_count=$($BABELTRACE_BIN -n all $TRACE_PATH | \
130 cut -d, -f1 | uniq | wc -l)
131 test $unique_timestamps_count -gt 1
132 ok $? "Unique event timestamps without clock override: $unique_timestamps_count expect >1"
133 modprobe --remove lttng-test
134 stop_lttng_sessiond
135
136 # Test with clock override plugin.
137 diag "Plugin enabled"
138
139 modprobe lttng-clock-plugin-test
140 start_lttng_sessiond
141 modprobe lttng-test
142
143 start_lttng_sessiond
144 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
145 enable_kernel_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
146 start_lttng_tracing_ok $SESSION_NAME
147 eval ${TESTCMD}
148 stop_lttng_tracing_ok $SESSION_NAME
149 destroy_lttng_session_ok $SESSION_NAME
150
151 stop_lttng_sessiond
152 modprobe --remove lttng-clock-plugin-test lttng-clock lttng-test
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 # MUST set TESTDIR before calling those functions
163 plan_tests $NUM_TESTS
164
165 print_test_banner "$TEST_DESC"
166
167 TESTS=(
168 "test_clock_override_metadata"
169 "test_clock_override_timestamp"
170 )
171
172 TEST_COUNT=${#TESTS[@]}
173 i=0
174
175 if [ "$(id -u)" == "0" ]; then
176 isroot=1
177 else
178 isroot=0
179 fi
180
181 skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
182 {
183 validate_lttng_modules_present
184 trap signal_cleanup SIGTERM SIGINT
185
186 while [ "$i" -lt "$TEST_COUNT" ]; do
187
188 TRACE_PATH=$(mktemp --tmpdir -d tmp.test_clock_override_trace_path.XXXXXX)
189
190 # Execute test
191 ${TESTS[$i]}
192
193 rm -rf $TRACE_PATH
194
195 let "i++"
196 done
197 }
This page took 0.037336 seconds and 4 git commands to generate.