File: test_getcpu_override

package info (click to toggle)
ltt-control 2.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,860 kB
  • sloc: cpp: 192,012; sh: 28,777; ansic: 10,960; python: 7,108; makefile: 3,520; java: 109; xml: 46
file content (188 lines) | stat: -rwxr-xr-x 5,237 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/bash
#
# SPDX-FileCopyrightText: 2015 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
#
# SPDX-License-Identifier: LGPL-2.1-only

TEST_DESC="UST - Getcpu override plugin"

CURDIR=$(dirname $0)/
TESTDIR=$CURDIR/../../..
SESSION_NAME="sequence-cpu"

TESTAPP_PATH="$TESTDIR/utils/testapp"
TESTAPP_NAME="gen-ust-events"
TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
TESTAPP_WRAPPER="run-getcpu-override"
NUM_EVENT=256
EVENT_WAIT_USEC=1
EVENT_NAME="tp:tptest"

NUM_TESTS=20

SEQUENCE_SEED=(
100 57 232 236 42 193 224 184 216 150 92 91 108 118 55 243 65 101 209 0 147 36
29 34 49 188 174 105 253 245 227 238 112 20 222 201 102 175 119 19 132 41 78 90
114 64 138 14 48 18 162 85 204 124 133 73 172 106 241 126 28 104 111 21 127 219
9 244 237 189 59 214 52 141 107 26 25 199 3 157 117 234 33 44 46 84 69 155 122
250 231 86 239 76 190 120 1 94 206 8 148 159 167 215 164 31 217 61 71 125 68 109
195 177 95 82 142 182 129 87 37 140 134 186 173 39 116 143 254 229 131 67 121
192 240 15 221 30 242 185 80 170 135 51 187 194 246 12 225 181 137 211 228 88
218 27 233 161 77 252 123 93 220 248 205 223 144 128 196 70 247 210 178 203 154
24 169 149 163 35 7 151 103 197 139 165 158 207 72 113 145 45 183 11 198 43 81
230 97 96 2 66 213 146 179 22 58 54 38 160 200 235 226 156 56 208 249 32 176 168
110 191 79 152 115 10 74 60 251 17 83 180 171 202 40 166 255 53 212 98 5 50 99 4
89 13 63 6 136 153 23 16 47 130 75 62
)

source $TESTDIR/utils/utils.sh

# Equivalent to the syconf(_SC_NPROCESSORS_CONF) call.
num_cpus=$(conf_proc_count)

# MUST set TESTDIR before calling those functions

run_app()
{
	diag "Launching app without getcpu-plugin wrapper"
	$TESTAPP_BIN -i $NUM_EVENT -w $EVENT_WAIT_USEC
	ok $? "Application without wrapper done"
}

run_getcpu_plugin_app()
{
	diag "Launching app with getcpu-plugin wrapper"
	$CURDIR/$TESTAPP_WRAPPER $TESTAPP_BIN -i $NUM_EVENT -w $EVENT_WAIT_USEC
	ok $? "Application with wrapper done"
}

compare_ok()
{
	compare 0 "$@"
}

compare_fail()
{
	compare 1 "$@"
}

compare()
{
	local expected_to_fail=$1
	declare -a array_to_compare=("${!2}")
	local valid=0

	test ${#array_to_compare[*]} -eq ${#SEQUENCE_SEED[*]}
	ok $? "Sequence seed and cpuid sequence have the same size ${#SEQUENCE_SEED[*]}/${#array_to_compare[*]}"

	for (( i = 0; i < ${#SEQUENCE_SEED[*]}; i++ )); do
		if [ "${array_to_compare[$i]}" -ne "$(( ${SEQUENCE_SEED[$i]} % $num_cpus))" ]; then
			valid=1
			break
		fi
	done

	if [[ $expected_to_fail -eq "1" ]]; then
		test $valid -ne "0"
		ok $? "Cpuid extraction and seed sequence comparison fails as expected"
	else
		ok $valid "Cpuid extraction and seed sequence comparison"
		if [[ $valid -ne "0" ]]; then
			diag "Dumping arrays after failed comparison"
			for (( i = 0; i < ${#SEQUENCE_SEED[*]}; i++ )); do
				echo -n "# array value is "
				echo -n "${array_to_compare[$i]}"
				echo -n " expected "
				echo "$(( ${SEQUENCE_SEED[$i]} % $num_cpus))"
			done
			diag "Dumping trace"
			_run_babeltrace_cmd $TRACE_PATH | awk '{print "# " $0}'
		fi
	fi
}

test_getcpu_override_fail()
{
	diag "Getcpu plugin - no preloaded plugin"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH
	enable_ust_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
	start_lttng_tracing_ok $SESSION_NAME
	run_app
	stop_lttng_tracing_ok $SESSION_NAME
	destroy_lttng_session_ok $SESSION_NAME

	# Move output to an array by using =($())
	local cpuid_events=($(_run_babeltrace_cmd $TRACE_PATH | sed -n 's/.*cpu_id = \([0-9]*\).*/\1/p'))
	local num_events=${#cpuid_events[*]}
	test $num_events -eq $NUM_EVENT
	ok $? "Extraction without getcpu plugin have $num_events/$NUM_EVENT"
	compare_fail cpuid_events[@]

	return $?
}

test_getcpu_override()
{
	diag "Getcpu plugin - with plugin preloaded"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH
	enable_ust_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
	start_lttng_tracing_ok $SESSION_NAME
	run_getcpu_plugin_app
	stop_lttng_tracing_ok $SESSION_NAME
	destroy_lttng_session_ok $SESSION_NAME

	local cpuid_events=($(_run_babeltrace_cmd $TRACE_PATH | sed -n 's/.*cpu_id = \([0-9]*\).*/\1/p'))
	local num_events=${#cpuid_events[*]}
	test $num_events -eq $NUM_EVENT
	ok $? "Extraction with getcpu plugin have $num_events/$NUM_EVENT"

	compare_ok cpuid_events[@]

	return $?
}

plan_tests $NUM_TESTS

print_test_banner "$TEST_DESC"

bail_out_if_no_babeltrace

if [ ! -x "$CURDIR/.libs/lttng-ust-getcpu-override-test.so" ]; then
	skip 0 "No shared object generated. Skipping all tests." $NUM_TESTS && exit 0
fi

if [ "$num_cpus" -eq "1" ]; then
	# Skip the test since we cannot perform it as designed since N mod 1
	# is always equals to zero. There is no point testing this on a system
	# with a single configured core. LTTng-UST limits the get_cpu function
	# to return value inside the [0, NUM_CPU - 1] range for a valid event
	# (present in trace).
	skip 0 "Test system only have a single thread. Skipping all tests." $NUM_TESTS && exit 0
fi


TESTS=(
	test_getcpu_override_fail
	test_getcpu_override
)

TEST_COUNT=${#TESTS[@]}
i=0

start_lttng_sessiond

for fct_test in ${TESTS[@]};
do
	TRACE_PATH=$(mktemp -d -t tmp.test_getcpu_override_trace_path.XXXXXX)

	${fct_test}
	if [ $? -ne 0 ]; then
		break;
	fi

	rm -rf $TRACE_PATH
done

stop_lttng_sessiond