Commit | Line | Data |
---|---|---|
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 | |
17 | TEST_DESC="UST - Getcpu 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 | TESTAPP_WRAPPER="run-getcpu-override" | |
27 | NUM_EVENT=256 | |
28 | EVENT_NAME="tp:tptest" | |
29 | LTTNG_UST_CLOCK_PLUGIN_SO="lttng-ust-clock-override-test.so" | |
30 | LIBS_DIR=".libs" | |
31 | ||
32 | METADATA_CLOCK_START_TOKEN="clock {" | |
33 | METADATA_CLOCK_END_TOKEN="};" | |
34 | ||
35 | METADATA_TOKEN_LIST=( | |
36 | "name" | |
37 | "uuid" | |
38 | "description" | |
39 | "freq" | |
40 | ) | |
41 | ||
42 | UST_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 | ||
49 | NUM_TESTS=33 | |
50 | ||
51 | source $TESTDIR/utils/utils.sh | |
52 | ||
53 | if [ ! -x "$CURDIR/$LIBS_DIR/$LTTNG_UST_CLOCK_PLUGIN_SO" ]; then | |
54 | BAIL_OUT "No shared object generated" | |
55 | fi | |
56 | ||
57 | # MUST set TESTDIR before calling those functions | |
58 | function run_app() | |
59 | { | |
60 | $TESTAPP_BIN $NUM_EVENT | |
61 | ok $? "Application done" | |
62 | } | |
63 | ||
64 | function 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 | ||
74 | function 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 | ||
82 | function 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 | ||
123 | function 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 | ||
167 | plan_tests $NUM_TESTS | |
168 | ||
169 | print_test_banner "$TEST_DESC" | |
170 | ||
171 | TESTS=( | |
172 | "test_getcpu_override_metadata" | |
173 | "test_getcpu_override_timestamp" | |
174 | ) | |
175 | ||
176 | TEST_COUNT=${#TESTS[@]} | |
177 | i=0 | |
178 | ||
179 | while [ "$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++" | |
189 | done | |
190 |