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
130 while [ "${state}" != "OK" ]; do
131 state=`perf daemon ping --config ${config} --session ${session} | awk '{ print $1 }'`
138 echo "test daemon list"
140 local config=$(mktemp /tmp/perf.daemon.config.XXX)
141 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
143 cat <<EOF > ${config}
148 run = -e cpu-clock -m 1 sleep 10
151 run = -e task-clock -m 1 sleep 10
154 sed -i -e "s|BASE|${base}|" ${config}
157 daemon_start ${config} size
160 # pid:daemon:base:base/output:base/lock
161 local line=`perf daemon --config ${config} -x: | head -1`
162 check_line_first ${line} daemon ${base} ${base}/output ${base}/lock "0"
165 # pid:size:-e cpu-clock:base/size:base/size/output:base/size/control:base/size/ack:0
166 local line=`perf daemon --config ${config} -x: | head -2 | tail -1`
167 check_line_other "${line}" size "-e cpu-clock -m 1 sleep 10" ${base}/session-size \
168 ${base}/session-size/output ${base}/session-size/control \
169 ${base}/session-size/ack "0"
172 # pid:time:-e task-clock:base/time:base/time/output:base/time/control:base/time/ack:0
173 local line=`perf daemon --config ${config} -x: | head -3 | tail -1`
174 check_line_other "${line}" time "-e task-clock -m 1 sleep 10" ${base}/session-time \
175 ${base}/session-time/output ${base}/session-time/control \
176 ${base}/session-time/ack "0"
179 daemon_exit ${config}
187 echo "test daemon reconfig"
189 local config=$(mktemp /tmp/perf.daemon.config.XXX)
190 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
193 cat <<EOF > ${config}
198 run = -e cpu-clock -m 1 sleep 10
201 run = -e task-clock -m 1 sleep 10
204 sed -i -e "s|BASE|${base}|" ${config}
207 daemon_start ${config} size
210 # pid:time:-e task-clock:base/time:base/time/output:base/time/control:base/time/ack:0
211 local line=`perf daemon --config ${config} -x: | head -3 | tail -1`
212 check_line_other "${line}" time "-e task-clock -m 1 sleep 10" ${base}/session-time \
213 ${base}/session-time/output ${base}/session-time/control ${base}/session-time/ack "0"
214 local pid=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $1 }'`
217 local config_new=${config}.new
218 cat <<EOF > ${config_new}
223 run = -e cpu-clock -m 1 sleep 10
226 run = -e cpu-clock -m 1 sleep 10
229 # TEST 1 - change config
231 sed -i -e "s|BASE|${base}|" ${config_new}
232 cp ${config_new} ${config}
234 # wait for old session to finish
235 tail --pid=${pid} -f /dev/null
237 # wait for new one to start
239 while [ "${state}" != "OK" ]; do
240 state=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
243 # check reconfigured 2nd session
244 # pid:time:-e task-clock:base/time:base/time/output:base/time/control:base/time/ack:0
245 local line=`perf daemon --config ${config} -x: | head -3 | tail -1`
246 check_line_other "${line}" time "-e cpu-clock -m 1 sleep 10" ${base}/session-time \
247 ${base}/session-time/output ${base}/session-time/control ${base}/session-time/ack "0"
249 # TEST 2 - empty config
251 local config_empty=${config}.empty
252 cat <<EOF > ${config_empty}
258 sed -i -e "s|BASE|${base}|" ${config_empty}
259 cp ${config_empty} ${config}
261 # wait for sessions to finish
263 while [ "${state}" != "FAIL" ]; do
264 state=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
268 while [ "${state}" != "FAIL" ]; do
269 state=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
272 local one=`perf daemon --config ${config} -x: | wc -l`
274 if [ ${one} -ne "1" ]; then
275 echo "FAILED: wrong list output"
279 # TEST 3 - config again
281 cp ${config_new} ${config}
283 # wait for size to start
285 while [ "${state}" != "OK" ]; do
286 state=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
289 # wait for time to start
291 while [ "${state}" != "OK" ]; do
292 state=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
296 daemon_exit ${config}
301 rm -f ${config_empty}
306 echo "test daemon stop"
308 local config=$(mktemp /tmp/perf.daemon.config.XXX)
309 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
312 cat <<EOF > ${config}
317 run = -e cpu-clock -m 1 sleep 10
320 run = -e task-clock -m 1 sleep 10
323 sed -i -e "s|BASE|${base}|" ${config}
326 daemon_start ${config} size
328 local pid_size=`perf daemon --config ${config} -x: | head -2 | tail -1 | awk 'BEGIN { FS = ":" } ; { print $1 }'`
329 local pid_time=`perf daemon --config ${config} -x: | head -3 | tail -1 | awk 'BEGIN { FS = ":" } ; { print $1 }'`
331 # check that sessions are running
332 if [ ! -d "/proc/${pid_size}" ]; then
333 echo "FAILED: session size not up"
336 if [ ! -d "/proc/${pid_time}" ]; then
337 echo "FAILED: session time not up"
341 daemon_exit ${config}
343 # check that sessions are gone
344 if [ -d "/proc/${pid_size}" ]; then
345 echo "FAILED: session size still up"
348 if [ -d "/proc/${pid_time}" ]; then
349 echo "FAILED: session time still up"
358 echo "test daemon signal"
360 local config=$(mktemp /tmp/perf.daemon.config.XXX)
361 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
364 cat <<EOF > ${config}
369 run = -e cpu-clock --switch-output -m 1 sleep 10
372 sed -i -e "s|BASE|${base}|" ${config}
375 daemon_start ${config} test
378 perf daemon signal --config ${config} --session test
379 perf daemon signal --config ${config}
382 daemon_exit ${config}
384 # count is 2 perf.data for signals and 1 for perf record finished
385 count=`ls ${base}/session-test/ | grep perf.data | wc -l`
386 if [ ${count} -ne 3 ]; then
388 echo "FAILED: perf data no generated"
397 echo "test daemon ping"
399 local config=$(mktemp /tmp/perf.daemon.config.XXX)
400 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
403 cat <<EOF > ${config}
408 run = -e cpu-clock -m 1 sleep 10
411 run = -e task-clock -m 1 sleep 10
414 sed -i -e "s|BASE|${base}|" ${config}
417 daemon_start ${config} size
419 size=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
420 type=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
422 if [ ${size} != "OK" -o ${type} != "OK" ]; then
424 echo "FAILED: daemon ping failed"
428 daemon_exit ${config}
436 echo "test daemon lock"
438 local config=$(mktemp /tmp/perf.daemon.config.XXX)
439 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
442 cat <<EOF > ${config}
447 run = -e cpu-clock -m 1 sleep 10
450 sed -i -e "s|BASE|${base}|" ${config}
453 daemon_start ${config} size
455 # start second daemon over the same config/base
456 failed=`perf daemon start --config ${config} 2>&1 | awk '{ print $1 }'`
458 # check that we failed properly
459 if [ ${failed} != "failed:" ]; then
461 echo "FAILED: daemon lock failed"
465 daemon_exit ${config}