3 # SPDX-License-Identifier: GPL-2.0
15 line_name
=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $2 }'`
17 line_base
=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $3 }'`
19 line_output
=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $4 }'`
21 line_lock
=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $5 }'`
23 line_up
=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $6 }'`
25 if [ "${name}" != "${line_name}" ]; then
26 echo "FAILED: wrong name"
30 if [ "${base}" != "${line_base}" ]; then
31 echo "FAILED: wrong base"
35 if [ "${output}" != "${line_output}" ]; then
36 echo "FAILED: wrong output"
40 if [ "${lock}" != "${line_lock}" ]; then
41 echo "FAILED: wrong lock"
45 if [ "${up}" != "${line_up}" ]; then
46 echo "FAILED: wrong up"
63 line_name
=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $2 }'`
65 line_run
=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $3 }'`
67 line_base
=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $4 }'`
69 line_output
=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $5 }'`
71 line_control
=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $6 }'`
73 line_ack
=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $7 }'`
75 line_up
=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $8 }'`
77 if [ "${name}" != "${line_name}" ]; then
78 echo "FAILED: wrong name"
82 if [ "${run}" != "${line_run}" ]; then
83 echo "FAILED: wrong run"
87 if [ "${base}" != "${line_base}" ]; then
88 echo "FAILED: wrong base"
92 if [ "${output}" != "${line_output}" ]; then
93 echo "FAILED: wrong output"
97 if [ "${control}" != "${line_control}" ]; then
98 echo "FAILED: wrong control"
102 if [ "${ack}" != "${line_ack}" ]; then
103 echo "FAILED: wrong ack"
107 if [ "${up}" != "${line_up}" ]; then
108 echo "FAILED: wrong up"
118 line
=`perf daemon --config ${config} -x: | head -1`
120 pid
=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $1 }'`
122 # Reset trap handler.
123 trap - SIGINT SIGTERM
126 perf daemon stop
--config ${config}
128 # ... and wait for the pid to go away
129 tail --pid=${pid} -f /dev
/null
137 perf daemon start
--config ${config}
139 # Clean up daemon if interrupted.
140 trap 'echo "FAILED: Signal caught"; daemon_exit "${config}"; exit 1' SIGINT SIGTERM
142 # wait for the session to ping
145 while [ "${state}" != "OK" ]; do
146 state
=`perf daemon ping --config ${config} --session ${session} | awk '{ print $1 }'`
148 retries
=$
((${retries} +1))
149 if [ ${retries} -ge 600 ]; then
150 echo "FAILED: Timeout waiting for daemon to ping"
151 daemon_exit
${config}
159 echo "test daemon list"
162 config
=$
(mktemp
/tmp
/perf.daemon.config.XXX
)
164 base
=$
(mktemp
-d /tmp
/perf.daemon.base.XXX
)
166 cat <<EOF > ${config}
171 run = -e cpu-clock -m 1 sleep 10
174 run = -e task-clock -m 1 sleep 10
177 sed -i -e "s|BASE|${base}|" ${config}
180 daemon_start
${config} size
183 # pid:daemon:base:base/output:base/lock
185 line
=`perf daemon --config ${config} -x: | head -1`
186 check_line_first
${line} daemon ${base} ${base}/output ${base}/lock
"0"
189 # pid:size:-e cpu-clock:base/size:base/size/output:base/size/control:base/size/ack:0
191 line
=`perf daemon --config ${config} -x: | head -2 | tail -1`
192 check_line_other
"${line}" size
"-e cpu-clock -m 1 sleep 10" ${base}/session-size \
193 ${base}/session-size
/output
${base}/session-size
/control \
194 ${base}/session-size
/ack
"0"
197 # pid:time:-e task-clock:base/time:base/time/output:base/time/control:base/time/ack:0
199 line
=`perf daemon --config ${config} -x: | head -3 | tail -1`
200 check_line_other
"${line}" time "-e task-clock -m 1 sleep 10" ${base}/session-time \
201 ${base}/session-time
/output
${base}/session-time
/control \
202 ${base}/session-time
/ack
"0"
205 daemon_exit
${config}
213 echo "test daemon reconfig"
216 config
=$
(mktemp
/tmp
/perf.daemon.config.XXX
)
218 base
=$
(mktemp
-d /tmp
/perf.daemon.base.XXX
)
221 cat <<EOF > ${config}
226 run = -e cpu-clock -m 1 sleep 10
229 run = -e task-clock -m 1 sleep 10
232 sed -i -e "s|BASE|${base}|" ${config}
235 daemon_start
${config} size
238 # pid:time:-e task-clock:base/time:base/time/output:base/time/control:base/time/ack:0
240 line
=`perf daemon --config ${config} -x: | head -3 | tail -1`
241 check_line_other
"${line}" time "-e task-clock -m 1 sleep 10" ${base}/session-time \
242 ${base}/session-time/output ${base}/session-time/control ${base}/session-time
/ack
"0"
244 pid
=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $1 }'`
247 local config_new
=${config}.new
248 cat <<EOF > ${config_new}
253 run = -e cpu-clock -m 1 sleep 10
256 run = -e cpu-clock -m 1 sleep 10
259 # TEST 1 - change config
261 sed -i -e "s|BASE|${base}|" ${config_new}
262 cp ${config_new} ${config}
264 # wait for old session to finish
265 tail --pid=${pid} -f /dev
/null
267 # wait for new one to start
269 while [ "${state}" != "OK" ]; do
270 state
=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
273 # check reconfigured 2nd session
274 # pid:time:-e task-clock:base/time:base/time/output:base/time/control:base/time/ack:0
276 line
=`perf daemon --config ${config} -x: | head -3 | tail -1`
277 check_line_other
"${line}" time "-e cpu-clock -m 1 sleep 10" ${base}/session-time \
278 ${base}/session-time/output ${base}/session-time/control ${base}/session-time
/ack
"0"
280 # TEST 2 - empty config
282 local config_empty
=${config}.empty
283 cat <<EOF > ${config_empty}
289 sed -i -e "s|BASE|${base}|" ${config_empty}
290 cp ${config_empty} ${config}
292 # wait for sessions to finish
294 while [ "${state}" != "FAIL" ]; do
295 state
=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
299 while [ "${state}" != "FAIL" ]; do
300 state
=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
304 one
=`perf daemon --config ${config} -x: | wc -l`
306 if [ ${one} -ne "1" ]; then
307 echo "FAILED: wrong list output"
311 # TEST 3 - config again
313 cp ${config_new} ${config}
315 # wait for size to start
317 while [ "${state}" != "OK" ]; do
318 state
=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
321 # wait for time to start
323 while [ "${state}" != "OK" ]; do
324 state
=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
328 daemon_exit
${config}
333 rm -f ${config_empty}
338 echo "test daemon stop"
341 config
=$
(mktemp
/tmp
/perf.daemon.config.XXX
)
343 base
=$
(mktemp
-d /tmp
/perf.daemon.base.XXX
)
346 cat <<EOF > ${config}
351 run = -e cpu-clock -m 1 sleep 10
354 run = -e task-clock -m 1 sleep 10
357 sed -i -e "s|BASE|${base}|" ${config}
360 daemon_start
${config} size
363 pid_size
=`perf daemon --config ${config} -x: | head -2 | tail -1 |
364 awk 'BEGIN { FS = ":" } ; { print $1 }'`
366 pid_time
=`perf daemon --config ${config} -x: | head -3 | tail -1 |
367 awk 'BEGIN { FS = ":" } ; { print $1 }'`
369 # check that sessions are running
370 if [ ! -d "/proc/${pid_size}" ]; then
371 echo "FAILED: session size not up"
374 if [ ! -d "/proc/${pid_time}" ]; then
375 echo "FAILED: session time not up"
379 daemon_exit
${config}
381 # check that sessions are gone
382 if [ -d "/proc/${pid_size}" ]; then
383 echo "FAILED: session size still up"
386 if [ -d "/proc/${pid_time}" ]; then
387 echo "FAILED: session time still up"
396 echo "test daemon signal"
399 config
=$
(mktemp
/tmp
/perf.daemon.config.XXX
)
401 base
=$
(mktemp
-d /tmp
/perf.daemon.base.XXX
)
404 cat <<EOF > ${config}
409 run = -e cpu-clock --switch-output -m 1 sleep 10
412 sed -i -e "s|BASE|${base}|" ${config}
415 daemon_start
${config} test
417 # send 2 signals then exit. Do this in a loop watching the number of
418 # files to avoid races. If the loop retries more than 600 times then
423 while [ ${retries} -lt 600 ] && [ ${success} -eq 0 ]; do
425 files
=`ls ${base}/session-test/*perf.data* 2> /dev/null | wc -l`
426 if [ ${signals} -eq 0 ]; then
427 perf daemon signal
--config ${config} --session test
429 elif [ ${signals} -eq 1 ] && [ $files -ge 1 ]; then
430 perf daemon signal
--config ${config}
432 elif [ ${signals} -eq 2 ] && [ $files -ge 2 ]; then
433 daemon_exit
${config}
435 elif [ ${signals} -eq 3 ] && [ $files -ge 3 ]; then
438 retries
=$
((${retries} +1))
440 if [ ${success} -eq 0 ]; then
442 echo "FAILED: perf data no generated"
451 echo "test daemon ping"
454 config
=$
(mktemp
/tmp
/perf.daemon.config.XXX
)
456 base
=$
(mktemp
-d /tmp
/perf.daemon.base.XXX
)
459 cat <<EOF > ${config}
464 run = -e cpu-clock -m 1 sleep 10
467 run = -e task-clock -m 1 sleep 10
470 sed -i -e "s|BASE|${base}|" ${config}
473 daemon_start
${config} size
475 size
=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
476 type=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
478 if [ ${size} != "OK" ] ||
[ ${type} != "OK" ]; then
480 echo "FAILED: daemon ping failed"
484 daemon_exit
${config}
492 echo "test daemon lock"
495 config
=$
(mktemp
/tmp
/perf.daemon.config.XXX
)
497 base
=$
(mktemp
-d /tmp
/perf.daemon.base.XXX
)
500 cat <<EOF > ${config}
505 run = -e cpu-clock -m 1 sleep 10
508 sed -i -e "s|BASE|${base}|" ${config}
511 daemon_start
${config} size
513 # start second daemon over the same config/base
514 failed
=`perf daemon start --config ${config} 2>&1 | awk '{ print $1 }'`
516 # check that we failed properly
517 if [ ${failed} != "failed:" ]; then
519 echo "FAILED: daemon lock failed"
523 daemon_exit
${config}