3 # SPDX-License-Identifier: GPL-2.0
14 local line_name=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $2 }'`
15 local line_base=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $3 }'`
16 local line_output=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $4 }'`
17 local line_lock=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $5 }'`
18 local line_up=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $6 }'`
20 if [ "${name}" != "${line_name}" ]; then
21 echo "FAILED: wrong name"
25 if [ "${base}" != "${line_base}" ]; then
26 echo "FAILED: wrong base"
30 if [ "${output}" != "${line_output}" ]; then
31 echo "FAILED: wrong output"
35 if [ "${lock}" != "${line_lock}" ]; then
36 echo "FAILED: wrong lock"
40 if [ "${up}" != "${line_up}" ]; then
41 echo "FAILED: wrong up"
57 local line_name=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $2 }'`
58 local line_run=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $3 }'`
59 local line_base=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $4 }'`
60 local line_output=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $5 }'`
61 local line_control=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $6 }'`
62 local line_ack=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $7 }'`
63 local line_up=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $8 }'`
65 if [ "${name}" != "${line_name}" ]; then
66 echo "FAILED: wrong name"
70 if [ "${run}" != "${line_run}" ]; then
71 echo "FAILED: wrong run"
75 if [ "${base}" != "${line_base}" ]; then
76 echo "FAILED: wrong base"
80 if [ "${output}" != "${line_output}" ]; then
81 echo "FAILED: wrong output"
85 if [ "${control}" != "${line_control}" ]; then
86 echo "FAILED: wrong control"
90 if [ "${ack}" != "${line_ack}" ]; then
91 echo "FAILED: wrong ack"
95 if [ "${up}" != "${line_up}" ]; then
96 echo "FAILED: wrong up"
105 local line=`perf daemon --config ${config} -x: | head -1`
106 local pid=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $1 }'`
108 # Reset trap handler.
109 trap - SIGINT SIGTERM
112 perf daemon stop --config ${config}
114 # ... and wait for the pid to go away
115 tail --pid=${pid} -f /dev/null
123 perf daemon start --config ${config}
125 # Clean up daemon if interrupted.
126 trap "echo 'FAILED: Signal caught'; daemon_exit ${config}; exit 1" SIGINT SIGTERM
128 # wait for the session to ping
131 while [ "${state}" != "OK" ]; do
132 state=`perf daemon ping --config ${config} --session ${session} | awk '{ print $1 }'`
134 retries=$((${retries} +1))
135 if [ ${retries} -ge 600 ]; then
136 echo "FAILED: Timeout waiting for daemon to ping"
137 daemon_exit ${config}
145 echo "test daemon list"
147 local config=$(mktemp /tmp/perf.daemon.config.XXX)
148 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
150 cat <<EOF > ${config}
155 run = -e cpu-clock -m 1 sleep 10
158 run = -e task-clock -m 1 sleep 10
161 sed -i -e "s|BASE|${base}|" ${config}
164 daemon_start ${config} size
167 # pid:daemon:base:base/output:base/lock
168 local line=`perf daemon --config ${config} -x: | head -1`
169 check_line_first ${line} daemon ${base} ${base}/output ${base}/lock "0"
172 # pid:size:-e cpu-clock:base/size:base/size/output:base/size/control:base/size/ack:0
173 local line=`perf daemon --config ${config} -x: | head -2 | tail -1`
174 check_line_other "${line}" size "-e cpu-clock -m 1 sleep 10" ${base}/session-size \
175 ${base}/session-size/output ${base}/session-size/control \
176 ${base}/session-size/ack "0"
179 # pid:time:-e task-clock:base/time:base/time/output:base/time/control:base/time/ack:0
180 local line=`perf daemon --config ${config} -x: | head -3 | tail -1`
181 check_line_other "${line}" time "-e task-clock -m 1 sleep 10" ${base}/session-time \
182 ${base}/session-time/output ${base}/session-time/control \
183 ${base}/session-time/ack "0"
186 daemon_exit ${config}
194 echo "test daemon reconfig"
196 local config=$(mktemp /tmp/perf.daemon.config.XXX)
197 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
200 cat <<EOF > ${config}
205 run = -e cpu-clock -m 1 sleep 10
208 run = -e task-clock -m 1 sleep 10
211 sed -i -e "s|BASE|${base}|" ${config}
214 daemon_start ${config} size
217 # pid:time:-e task-clock:base/time:base/time/output:base/time/control:base/time/ack:0
218 local line=`perf daemon --config ${config} -x: | head -3 | tail -1`
219 check_line_other "${line}" time "-e task-clock -m 1 sleep 10" ${base}/session-time \
220 ${base}/session-time/output ${base}/session-time/control ${base}/session-time/ack "0"
221 local pid=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $1 }'`
224 local config_new=${config}.new
225 cat <<EOF > ${config_new}
230 run = -e cpu-clock -m 1 sleep 10
233 run = -e cpu-clock -m 1 sleep 10
236 # TEST 1 - change config
238 sed -i -e "s|BASE|${base}|" ${config_new}
239 cp ${config_new} ${config}
241 # wait for old session to finish
242 tail --pid=${pid} -f /dev/null
244 # wait for new one to start
246 while [ "${state}" != "OK" ]; do
247 state=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
250 # check reconfigured 2nd session
251 # pid:time:-e task-clock:base/time:base/time/output:base/time/control:base/time/ack:0
252 local line=`perf daemon --config ${config} -x: | head -3 | tail -1`
253 check_line_other "${line}" time "-e cpu-clock -m 1 sleep 10" ${base}/session-time \
254 ${base}/session-time/output ${base}/session-time/control ${base}/session-time/ack "0"
256 # TEST 2 - empty config
258 local config_empty=${config}.empty
259 cat <<EOF > ${config_empty}
265 sed -i -e "s|BASE|${base}|" ${config_empty}
266 cp ${config_empty} ${config}
268 # wait for sessions to finish
270 while [ "${state}" != "FAIL" ]; do
271 state=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
275 while [ "${state}" != "FAIL" ]; do
276 state=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
279 local one=`perf daemon --config ${config} -x: | wc -l`
281 if [ ${one} -ne "1" ]; then
282 echo "FAILED: wrong list output"
286 # TEST 3 - config again
288 cp ${config_new} ${config}
290 # wait for size to start
292 while [ "${state}" != "OK" ]; do
293 state=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
296 # wait for time to start
298 while [ "${state}" != "OK" ]; do
299 state=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
303 daemon_exit ${config}
308 rm -f ${config_empty}
313 echo "test daemon stop"
315 local config=$(mktemp /tmp/perf.daemon.config.XXX)
316 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
319 cat <<EOF > ${config}
324 run = -e cpu-clock -m 1 sleep 10
327 run = -e task-clock -m 1 sleep 10
330 sed -i -e "s|BASE|${base}|" ${config}
333 daemon_start ${config} size
335 local pid_size=`perf daemon --config ${config} -x: | head -2 | tail -1 | awk 'BEGIN { FS = ":" } ; { print $1 }'`
336 local pid_time=`perf daemon --config ${config} -x: | head -3 | tail -1 | awk 'BEGIN { FS = ":" } ; { print $1 }'`
338 # check that sessions are running
339 if [ ! -d "/proc/${pid_size}" ]; then
340 echo "FAILED: session size not up"
343 if [ ! -d "/proc/${pid_time}" ]; then
344 echo "FAILED: session time not up"
348 daemon_exit ${config}
350 # check that sessions are gone
351 if [ -d "/proc/${pid_size}" ]; then
352 echo "FAILED: session size still up"
355 if [ -d "/proc/${pid_time}" ]; then
356 echo "FAILED: session time still up"
365 echo "test daemon signal"
367 local config=$(mktemp /tmp/perf.daemon.config.XXX)
368 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
371 cat <<EOF > ${config}
376 run = -e cpu-clock --switch-output -m 1 sleep 10
379 sed -i -e "s|BASE|${base}|" ${config}
382 daemon_start ${config} test
385 perf daemon signal --config ${config} --session test
386 perf daemon signal --config ${config}
389 daemon_exit ${config}
391 # count is 2 perf.data for signals and 1 for perf record finished
392 count=`ls ${base}/session-test/ | grep perf.data | wc -l`
393 if [ ${count} -ne 3 ]; then
395 echo "FAILED: perf data no generated"
404 echo "test daemon ping"
406 local config=$(mktemp /tmp/perf.daemon.config.XXX)
407 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
410 cat <<EOF > ${config}
415 run = -e cpu-clock -m 1 sleep 10
418 run = -e task-clock -m 1 sleep 10
421 sed -i -e "s|BASE|${base}|" ${config}
424 daemon_start ${config} size
426 size=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
427 type=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
429 if [ ${size} != "OK" -o ${type} != "OK" ]; then
431 echo "FAILED: daemon ping failed"
435 daemon_exit ${config}
443 echo "test daemon lock"
445 local config=$(mktemp /tmp/perf.daemon.config.XXX)
446 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
449 cat <<EOF > ${config}
454 run = -e cpu-clock -m 1 sleep 10
457 sed -i -e "s|BASE|${base}|" ${config}
460 daemon_start ${config} size
462 # start second daemon over the same config/base
463 failed=`perf daemon start --config ${config} 2>&1 | awk '{ print $1 }'`
465 # check that we failed properly
466 if [ ${failed} != "failed:" ]; then
468 echo "FAILED: daemon lock failed"
472 daemon_exit ${config}