xref: /openbmc/linux/tools/perf/tests/shell/daemon.sh (revision 5bd35dfb)
11dc481c0SLeo Yan#!/bin/bash
22291bb91SJiri Olsa# daemon operations
32291bb91SJiri Olsa# SPDX-License-Identifier: GPL-2.0
42291bb91SJiri Olsa
52291bb91SJiri Olsacheck_line_first()
62291bb91SJiri Olsa{
72291bb91SJiri Olsa	local line=$1
82291bb91SJiri Olsa	local name=$2
92291bb91SJiri Olsa	local base=$3
102291bb91SJiri Olsa	local output=$4
112291bb91SJiri Olsa	local lock=$5
122291bb91SJiri Olsa	local up=$6
132291bb91SJiri Olsa
14*5bd35dfbSShirisha G	local line_name
15*5bd35dfbSShirisha G	line_name=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $2 }'`
16*5bd35dfbSShirisha G	local line_base
17*5bd35dfbSShirisha G	line_base=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $3 }'`
18*5bd35dfbSShirisha G	local line_output
19*5bd35dfbSShirisha G	line_output=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $4 }'`
20*5bd35dfbSShirisha G	local line_lock
21*5bd35dfbSShirisha G	line_lock=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $5 }'`
22*5bd35dfbSShirisha G	local line_up
23*5bd35dfbSShirisha G	line_up=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $6 }'`
242291bb91SJiri Olsa
252291bb91SJiri Olsa	if [ "${name}" != "${line_name}" ]; then
262291bb91SJiri Olsa		echo "FAILED: wrong name"
272291bb91SJiri Olsa		error=1
282291bb91SJiri Olsa	fi
292291bb91SJiri Olsa
302291bb91SJiri Olsa	if [ "${base}" != "${line_base}" ]; then
312291bb91SJiri Olsa		echo "FAILED: wrong base"
322291bb91SJiri Olsa		error=1
332291bb91SJiri Olsa	fi
342291bb91SJiri Olsa
352291bb91SJiri Olsa	if [ "${output}" != "${line_output}" ]; then
362291bb91SJiri Olsa		echo "FAILED: wrong output"
372291bb91SJiri Olsa		error=1
382291bb91SJiri Olsa	fi
392291bb91SJiri Olsa
402291bb91SJiri Olsa	if [ "${lock}" != "${line_lock}" ]; then
412291bb91SJiri Olsa		echo "FAILED: wrong lock"
422291bb91SJiri Olsa		error=1
432291bb91SJiri Olsa	fi
442291bb91SJiri Olsa
452291bb91SJiri Olsa	if [ "${up}" != "${line_up}" ]; then
462291bb91SJiri Olsa		echo "FAILED: wrong up"
472291bb91SJiri Olsa		error=1
482291bb91SJiri Olsa	fi
492291bb91SJiri Olsa}
502291bb91SJiri Olsa
512291bb91SJiri Olsacheck_line_other()
522291bb91SJiri Olsa{
532291bb91SJiri Olsa	local line=$1
542291bb91SJiri Olsa	local name=$2
552291bb91SJiri Olsa	local run=$3
562291bb91SJiri Olsa	local base=$4
572291bb91SJiri Olsa	local output=$5
582291bb91SJiri Olsa	local control=$6
592291bb91SJiri Olsa	local ack=$7
602291bb91SJiri Olsa	local up=$8
612291bb91SJiri Olsa
62*5bd35dfbSShirisha G	local line_name
63*5bd35dfbSShirisha G	line_name=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $2 }'`
64*5bd35dfbSShirisha G	local line_run
65*5bd35dfbSShirisha G	line_run=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $3 }'`
66*5bd35dfbSShirisha G	local line_base
67*5bd35dfbSShirisha G	line_base=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $4 }'`
68*5bd35dfbSShirisha G	local line_output
69*5bd35dfbSShirisha G	line_output=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $5 }'`
70*5bd35dfbSShirisha G	local line_control
71*5bd35dfbSShirisha G	line_control=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $6 }'`
72*5bd35dfbSShirisha G	local line_ack
73*5bd35dfbSShirisha G	line_ack=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $7 }'`
74*5bd35dfbSShirisha G	local line_up
75*5bd35dfbSShirisha G	line_up=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $8 }'`
762291bb91SJiri Olsa
772291bb91SJiri Olsa	if [ "${name}" != "${line_name}" ]; then
782291bb91SJiri Olsa		echo "FAILED: wrong name"
792291bb91SJiri Olsa		error=1
802291bb91SJiri Olsa	fi
812291bb91SJiri Olsa
822291bb91SJiri Olsa	if [ "${run}" != "${line_run}" ]; then
832291bb91SJiri Olsa		echo "FAILED: wrong run"
842291bb91SJiri Olsa		error=1
852291bb91SJiri Olsa	fi
862291bb91SJiri Olsa
872291bb91SJiri Olsa	if [ "${base}" != "${line_base}" ]; then
882291bb91SJiri Olsa		echo "FAILED: wrong base"
892291bb91SJiri Olsa		error=1
902291bb91SJiri Olsa	fi
912291bb91SJiri Olsa
922291bb91SJiri Olsa	if [ "${output}" != "${line_output}" ]; then
932291bb91SJiri Olsa		echo "FAILED: wrong output"
942291bb91SJiri Olsa		error=1
952291bb91SJiri Olsa	fi
962291bb91SJiri Olsa
972291bb91SJiri Olsa	if [ "${control}" != "${line_control}" ]; then
982291bb91SJiri Olsa		echo "FAILED: wrong control"
992291bb91SJiri Olsa		error=1
1002291bb91SJiri Olsa	fi
1012291bb91SJiri Olsa
1022291bb91SJiri Olsa	if [ "${ack}" != "${line_ack}" ]; then
1032291bb91SJiri Olsa		echo "FAILED: wrong ack"
1042291bb91SJiri Olsa		error=1
1052291bb91SJiri Olsa	fi
1062291bb91SJiri Olsa
1072291bb91SJiri Olsa	if [ "${up}" != "${line_up}" ]; then
1082291bb91SJiri Olsa		echo "FAILED: wrong up"
1092291bb91SJiri Olsa		error=1
1102291bb91SJiri Olsa	fi
1112291bb91SJiri Olsa}
1122291bb91SJiri Olsa
1132291bb91SJiri Olsadaemon_exit()
1142291bb91SJiri Olsa{
11587cb88d3SIan Rogers	local config=$1
1162291bb91SJiri Olsa
117*5bd35dfbSShirisha G	local line
118*5bd35dfbSShirisha G	line=`perf daemon --config ${config} -x: | head -1`
119*5bd35dfbSShirisha G	local pid
120*5bd35dfbSShirisha G	pid=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $1 }'`
1212291bb91SJiri Olsa
122078cbb6fSIan Rogers	# Reset trap handler.
123078cbb6fSIan Rogers	trap - SIGINT SIGTERM
124078cbb6fSIan Rogers
1252291bb91SJiri Olsa	# stop daemon
1262291bb91SJiri Olsa	perf daemon stop --config ${config}
1272291bb91SJiri Olsa
1282291bb91SJiri Olsa	# ... and wait for the pid to go away
1292291bb91SJiri Olsa	tail --pid=${pid} -f /dev/null
1302291bb91SJiri Olsa}
1312291bb91SJiri Olsa
132078cbb6fSIan Rogersdaemon_start()
133078cbb6fSIan Rogers{
134078cbb6fSIan Rogers	local config=$1
135078cbb6fSIan Rogers	local session=$2
136078cbb6fSIan Rogers
137078cbb6fSIan Rogers	perf daemon start --config ${config}
138078cbb6fSIan Rogers
139078cbb6fSIan Rogers	# Clean up daemon if interrupted.
140*5bd35dfbSShirisha G	trap 'echo "FAILED: Signal caught"; daemon_exit "${config}"; exit 1' SIGINT SIGTERM
141078cbb6fSIan Rogers
142078cbb6fSIan Rogers	# wait for the session to ping
143078cbb6fSIan Rogers	local state="FAIL"
144a6cb06ffSIan Rogers	local retries=0
145078cbb6fSIan Rogers	while [ "${state}" != "OK" ]; do
146078cbb6fSIan Rogers		state=`perf daemon ping --config ${config} --session ${session} | awk '{ print $1 }'`
147078cbb6fSIan Rogers		sleep 0.05
148a6cb06ffSIan Rogers		retries=$((${retries} +1))
149a6cb06ffSIan Rogers		if [ ${retries} -ge 600 ]; then
150a6cb06ffSIan Rogers			echo "FAILED: Timeout waiting for daemon to ping"
151a6cb06ffSIan Rogers			daemon_exit ${config}
152a6cb06ffSIan Rogers			exit 1
153a6cb06ffSIan Rogers		fi
154078cbb6fSIan Rogers	done
155078cbb6fSIan Rogers}
156078cbb6fSIan Rogers
1572291bb91SJiri Olsatest_list()
1582291bb91SJiri Olsa{
1592291bb91SJiri Olsa	echo "test daemon list"
1602291bb91SJiri Olsa
161*5bd35dfbSShirisha G	local config
162*5bd35dfbSShirisha G	config=$(mktemp /tmp/perf.daemon.config.XXX)
163*5bd35dfbSShirisha G	local base
164*5bd35dfbSShirisha G	base=$(mktemp -d /tmp/perf.daemon.base.XXX)
1652291bb91SJiri Olsa
1662291bb91SJiri Olsa	cat <<EOF > ${config}
1672291bb91SJiri Olsa[daemon]
1682291bb91SJiri Olsabase=BASE
1692291bb91SJiri Olsa
1702291bb91SJiri Olsa[session-size]
17136bc511fSJiri Olsarun = -e cpu-clock -m 1 sleep 10
1722291bb91SJiri Olsa
1732291bb91SJiri Olsa[session-time]
17436bc511fSJiri Olsarun = -e task-clock -m 1 sleep 10
1752291bb91SJiri OlsaEOF
1762291bb91SJiri Olsa
1772291bb91SJiri Olsa	sed -i -e "s|BASE|${base}|" ${config}
1782291bb91SJiri Olsa
1792291bb91SJiri Olsa	# start daemon
1802291bb91SJiri Olsa	daemon_start ${config} size
1812291bb91SJiri Olsa
1822291bb91SJiri Olsa	# check first line
1832291bb91SJiri Olsa	# pid:daemon:base:base/output:base/lock
184*5bd35dfbSShirisha G	local line
185*5bd35dfbSShirisha G	line=`perf daemon --config ${config} -x: | head -1`
1862291bb91SJiri Olsa	check_line_first ${line} daemon ${base} ${base}/output ${base}/lock "0"
1872291bb91SJiri Olsa
1882291bb91SJiri Olsa	# check 1st session
1892291bb91SJiri Olsa	# pid:size:-e cpu-clock:base/size:base/size/output:base/size/control:base/size/ack:0
190*5bd35dfbSShirisha G	local line
191*5bd35dfbSShirisha G	line=`perf daemon --config ${config} -x: | head -2 | tail -1`
19236bc511fSJiri Olsa	check_line_other "${line}" size "-e cpu-clock -m 1 sleep 10" ${base}/session-size \
1932291bb91SJiri Olsa			 ${base}/session-size/output ${base}/session-size/control \
1942291bb91SJiri Olsa			 ${base}/session-size/ack "0"
1952291bb91SJiri Olsa
1962291bb91SJiri Olsa	# check 2nd session
1972291bb91SJiri Olsa	# pid:time:-e task-clock:base/time:base/time/output:base/time/control:base/time/ack:0
198*5bd35dfbSShirisha G	local line
199*5bd35dfbSShirisha G	line=`perf daemon --config ${config} -x: | head -3 | tail -1`
20036bc511fSJiri Olsa	check_line_other "${line}" time "-e task-clock -m 1 sleep 10" ${base}/session-time \
2012291bb91SJiri Olsa			 ${base}/session-time/output ${base}/session-time/control \
2022291bb91SJiri Olsa			 ${base}/session-time/ack "0"
2032291bb91SJiri Olsa
2042291bb91SJiri Olsa	# stop daemon
20587cb88d3SIan Rogers	daemon_exit ${config}
2062291bb91SJiri Olsa
2072291bb91SJiri Olsa	rm -rf ${base}
2082291bb91SJiri Olsa	rm -f ${config}
2092291bb91SJiri Olsa}
2102291bb91SJiri Olsa
21191a17d6fSJiri Olsatest_reconfig()
21291a17d6fSJiri Olsa{
21391a17d6fSJiri Olsa	echo "test daemon reconfig"
21491a17d6fSJiri Olsa
215*5bd35dfbSShirisha G	local config
216*5bd35dfbSShirisha G	config=$(mktemp /tmp/perf.daemon.config.XXX)
217*5bd35dfbSShirisha G	local base
218*5bd35dfbSShirisha G	base=$(mktemp -d /tmp/perf.daemon.base.XXX)
21991a17d6fSJiri Olsa
22091a17d6fSJiri Olsa	# prepare config
22191a17d6fSJiri Olsa	cat <<EOF > ${config}
22291a17d6fSJiri Olsa[daemon]
22391a17d6fSJiri Olsabase=BASE
22491a17d6fSJiri Olsa
22591a17d6fSJiri Olsa[session-size]
22636bc511fSJiri Olsarun = -e cpu-clock -m 1 sleep 10
22791a17d6fSJiri Olsa
22891a17d6fSJiri Olsa[session-time]
22936bc511fSJiri Olsarun = -e task-clock -m 1 sleep 10
23091a17d6fSJiri OlsaEOF
23191a17d6fSJiri Olsa
23291a17d6fSJiri Olsa	sed -i -e "s|BASE|${base}|" ${config}
23391a17d6fSJiri Olsa
23491a17d6fSJiri Olsa	# start daemon
23591a17d6fSJiri Olsa	daemon_start ${config} size
23691a17d6fSJiri Olsa
23791a17d6fSJiri Olsa	# check 2nd session
23891a17d6fSJiri Olsa	# pid:time:-e task-clock:base/time:base/time/output:base/time/control:base/time/ack:0
239*5bd35dfbSShirisha G	local line
240*5bd35dfbSShirisha G	line=`perf daemon --config ${config} -x: | head -3 | tail -1`
24136bc511fSJiri Olsa	check_line_other "${line}" time "-e task-clock -m 1 sleep 10" ${base}/session-time \
24291a17d6fSJiri Olsa			 ${base}/session-time/output ${base}/session-time/control ${base}/session-time/ack "0"
243*5bd35dfbSShirisha G	local pid
244*5bd35dfbSShirisha G	pid=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $1 }'`
24591a17d6fSJiri Olsa
24691a17d6fSJiri Olsa	# prepare new config
24791a17d6fSJiri Olsa	local config_new=${config}.new
24891a17d6fSJiri Olsa	cat <<EOF > ${config_new}
24991a17d6fSJiri Olsa[daemon]
25091a17d6fSJiri Olsabase=BASE
25191a17d6fSJiri Olsa
25291a17d6fSJiri Olsa[session-size]
25336bc511fSJiri Olsarun = -e cpu-clock -m 1 sleep 10
25491a17d6fSJiri Olsa
25591a17d6fSJiri Olsa[session-time]
25636bc511fSJiri Olsarun = -e cpu-clock -m 1 sleep 10
25791a17d6fSJiri OlsaEOF
25891a17d6fSJiri Olsa
25991a17d6fSJiri Olsa	# TEST 1 - change config
26091a17d6fSJiri Olsa
26191a17d6fSJiri Olsa	sed -i -e "s|BASE|${base}|" ${config_new}
26291a17d6fSJiri Olsa	cp ${config_new} ${config}
26391a17d6fSJiri Olsa
26491a17d6fSJiri Olsa	# wait for old session to finish
26591a17d6fSJiri Olsa	tail --pid=${pid} -f /dev/null
26691a17d6fSJiri Olsa
26791a17d6fSJiri Olsa	# wait for new one to start
26891a17d6fSJiri Olsa	local state="FAIL"
26991a17d6fSJiri Olsa	while [ "${state}" != "OK" ]; do
27091a17d6fSJiri Olsa		state=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
27191a17d6fSJiri Olsa	done
27291a17d6fSJiri Olsa
27391a17d6fSJiri Olsa	# check reconfigured 2nd session
27491a17d6fSJiri Olsa	# pid:time:-e task-clock:base/time:base/time/output:base/time/control:base/time/ack:0
275*5bd35dfbSShirisha G	local line
276*5bd35dfbSShirisha G	line=`perf daemon --config ${config} -x: | head -3 | tail -1`
27736bc511fSJiri Olsa	check_line_other "${line}" time "-e cpu-clock -m 1 sleep 10" ${base}/session-time \
27891a17d6fSJiri Olsa			 ${base}/session-time/output ${base}/session-time/control ${base}/session-time/ack "0"
27991a17d6fSJiri Olsa
28091a17d6fSJiri Olsa	# TEST 2 - empty config
28191a17d6fSJiri Olsa
28291a17d6fSJiri Olsa	local config_empty=${config}.empty
28391a17d6fSJiri Olsa	cat <<EOF > ${config_empty}
28491a17d6fSJiri Olsa[daemon]
28591a17d6fSJiri Olsabase=BASE
28691a17d6fSJiri OlsaEOF
28791a17d6fSJiri Olsa
28891a17d6fSJiri Olsa	# change config
28991a17d6fSJiri Olsa	sed -i -e "s|BASE|${base}|" ${config_empty}
29091a17d6fSJiri Olsa	cp ${config_empty} ${config}
29191a17d6fSJiri Olsa
29291a17d6fSJiri Olsa	# wait for sessions to finish
29391a17d6fSJiri Olsa	local state="OK"
29491a17d6fSJiri Olsa	while [ "${state}" != "FAIL" ]; do
29591a17d6fSJiri Olsa		state=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
29691a17d6fSJiri Olsa	done
29791a17d6fSJiri Olsa
29891a17d6fSJiri Olsa	local state="OK"
29991a17d6fSJiri Olsa	while [ "${state}" != "FAIL" ]; do
30091a17d6fSJiri Olsa		state=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
30191a17d6fSJiri Olsa	done
30291a17d6fSJiri Olsa
303*5bd35dfbSShirisha G	local one
304*5bd35dfbSShirisha G	one=`perf daemon --config ${config} -x: | wc -l`
30591a17d6fSJiri Olsa
30691a17d6fSJiri Olsa	if [ ${one} -ne "1" ]; then
30791a17d6fSJiri Olsa		echo "FAILED: wrong list output"
30891a17d6fSJiri Olsa		error=1
30991a17d6fSJiri Olsa	fi
31091a17d6fSJiri Olsa
31191a17d6fSJiri Olsa	# TEST 3 - config again
31291a17d6fSJiri Olsa
31391a17d6fSJiri Olsa	cp ${config_new} ${config}
31491a17d6fSJiri Olsa
31591a17d6fSJiri Olsa	# wait for size to start
31691a17d6fSJiri Olsa	local state="FAIL"
31791a17d6fSJiri Olsa	while [ "${state}" != "OK" ]; do
31891a17d6fSJiri Olsa		state=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
31991a17d6fSJiri Olsa	done
32091a17d6fSJiri Olsa
32191a17d6fSJiri Olsa	# wait for time to start
32291a17d6fSJiri Olsa	local state="FAIL"
32391a17d6fSJiri Olsa	while [ "${state}" != "OK" ]; do
32491a17d6fSJiri Olsa		state=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
32591a17d6fSJiri Olsa	done
32691a17d6fSJiri Olsa
32791a17d6fSJiri Olsa	# stop daemon
32887cb88d3SIan Rogers	daemon_exit ${config}
32991a17d6fSJiri Olsa
33091a17d6fSJiri Olsa	rm -rf ${base}
33191a17d6fSJiri Olsa	rm -f ${config}
33291a17d6fSJiri Olsa	rm -f ${config_new}
33391a17d6fSJiri Olsa	rm -f ${config_empty}
33491a17d6fSJiri Olsa}
335f624f6d0SJiri Olsa
336f624f6d0SJiri Olsatest_stop()
337f624f6d0SJiri Olsa{
338f624f6d0SJiri Olsa	echo "test daemon stop"
339f624f6d0SJiri Olsa
340*5bd35dfbSShirisha G	local config
341*5bd35dfbSShirisha G	config=$(mktemp /tmp/perf.daemon.config.XXX)
342*5bd35dfbSShirisha G	local base
343*5bd35dfbSShirisha G	base=$(mktemp -d /tmp/perf.daemon.base.XXX)
344f624f6d0SJiri Olsa
345f624f6d0SJiri Olsa	# prepare config
346f624f6d0SJiri Olsa	cat <<EOF > ${config}
347f624f6d0SJiri Olsa[daemon]
348f624f6d0SJiri Olsabase=BASE
349f624f6d0SJiri Olsa
350f624f6d0SJiri Olsa[session-size]
35136bc511fSJiri Olsarun = -e cpu-clock -m 1 sleep 10
352f624f6d0SJiri Olsa
353f624f6d0SJiri Olsa[session-time]
35436bc511fSJiri Olsarun = -e task-clock -m 1 sleep 10
355f624f6d0SJiri OlsaEOF
356f624f6d0SJiri Olsa
357f624f6d0SJiri Olsa	sed -i -e "s|BASE|${base}|" ${config}
358f624f6d0SJiri Olsa
359f624f6d0SJiri Olsa	# start daemon
360f624f6d0SJiri Olsa	daemon_start ${config} size
361f624f6d0SJiri Olsa
362*5bd35dfbSShirisha G	local pid_size
363*5bd35dfbSShirisha G	pid_size=`perf daemon --config ${config} -x: | head -2 | tail -1 |
364*5bd35dfbSShirisha G		  awk 'BEGIN { FS = ":" } ; { print $1 }'`
365*5bd35dfbSShirisha G	local pid_time
366*5bd35dfbSShirisha G	pid_time=`perf daemon --config ${config} -x: | head -3 | tail -1 |
367*5bd35dfbSShirisha G		  awk 'BEGIN { FS = ":" } ; { print $1 }'`
368f624f6d0SJiri Olsa
369f624f6d0SJiri Olsa	# check that sessions are running
370f624f6d0SJiri Olsa	if [ ! -d "/proc/${pid_size}" ]; then
371f624f6d0SJiri Olsa		echo "FAILED: session size not up"
372f624f6d0SJiri Olsa	fi
373f624f6d0SJiri Olsa
374f624f6d0SJiri Olsa	if [ ! -d "/proc/${pid_time}" ]; then
375f624f6d0SJiri Olsa		echo "FAILED: session time not up"
376f624f6d0SJiri Olsa	fi
377f624f6d0SJiri Olsa
378f624f6d0SJiri Olsa	# stop daemon
37987cb88d3SIan Rogers	daemon_exit ${config}
380f624f6d0SJiri Olsa
381f624f6d0SJiri Olsa	# check that sessions are gone
382f624f6d0SJiri Olsa	if [ -d "/proc/${pid_size}" ]; then
383f624f6d0SJiri Olsa		echo "FAILED: session size still up"
384f624f6d0SJiri Olsa	fi
385f624f6d0SJiri Olsa
386f624f6d0SJiri Olsa	if [ -d "/proc/${pid_time}" ]; then
387f624f6d0SJiri Olsa		echo "FAILED: session time still up"
388f624f6d0SJiri Olsa	fi
389f624f6d0SJiri Olsa
390f624f6d0SJiri Olsa	rm -rf ${base}
391f624f6d0SJiri Olsa	rm -f ${config}
392f624f6d0SJiri Olsa}
393f624f6d0SJiri Olsa
394f32102aaSJiri Olsatest_signal()
395f32102aaSJiri Olsa{
396f32102aaSJiri Olsa	echo "test daemon signal"
397f32102aaSJiri Olsa
398*5bd35dfbSShirisha G	local config
399*5bd35dfbSShirisha G	config=$(mktemp /tmp/perf.daemon.config.XXX)
400*5bd35dfbSShirisha G	local base
401*5bd35dfbSShirisha G	base=$(mktemp -d /tmp/perf.daemon.base.XXX)
402f32102aaSJiri Olsa
403f32102aaSJiri Olsa	# prepare config
404f32102aaSJiri Olsa	cat <<EOF > ${config}
405f32102aaSJiri Olsa[daemon]
406f32102aaSJiri Olsabase=BASE
407f32102aaSJiri Olsa
408f32102aaSJiri Olsa[session-test]
40936bc511fSJiri Olsarun = -e cpu-clock --switch-output -m 1 sleep 10
410f32102aaSJiri OlsaEOF
411f32102aaSJiri Olsa
412f32102aaSJiri Olsa	sed -i -e "s|BASE|${base}|" ${config}
413f32102aaSJiri Olsa
414f32102aaSJiri Olsa	# start daemon
415f32102aaSJiri Olsa	daemon_start ${config} test
416f32102aaSJiri Olsa
417f32102aaSJiri Olsa	# send 2 signals
418f32102aaSJiri Olsa	perf daemon signal --config ${config} --session test
419f32102aaSJiri Olsa	perf daemon signal --config ${config}
420f32102aaSJiri Olsa
421f32102aaSJiri Olsa	# stop daemon
42287cb88d3SIan Rogers	daemon_exit ${config}
423f32102aaSJiri Olsa
424f32102aaSJiri Olsa	# count is 2 perf.data for signals and 1 for perf record finished
425*5bd35dfbSShirisha G	count=`ls ${base}/session-test/*perf.data* | wc -l`
426f32102aaSJiri Olsa	if [ ${count} -ne 3 ]; then
427f32102aaSJiri Olsa		error=1
428f32102aaSJiri Olsa		echo "FAILED: perf data no generated"
429f32102aaSJiri Olsa	fi
430f32102aaSJiri Olsa
431f32102aaSJiri Olsa	rm -rf ${base}
432f32102aaSJiri Olsa	rm -f ${config}
433f32102aaSJiri Olsa}
434f32102aaSJiri Olsa
43563551dc7SJiri Olsatest_ping()
43663551dc7SJiri Olsa{
43763551dc7SJiri Olsa	echo "test daemon ping"
43863551dc7SJiri Olsa
439*5bd35dfbSShirisha G	local config
440*5bd35dfbSShirisha G	config=$(mktemp /tmp/perf.daemon.config.XXX)
441*5bd35dfbSShirisha G	local base
442*5bd35dfbSShirisha G	base=$(mktemp -d /tmp/perf.daemon.base.XXX)
44363551dc7SJiri Olsa
44463551dc7SJiri Olsa	# prepare config
44563551dc7SJiri Olsa	cat <<EOF > ${config}
44663551dc7SJiri Olsa[daemon]
44763551dc7SJiri Olsabase=BASE
44863551dc7SJiri Olsa
44963551dc7SJiri Olsa[session-size]
45036bc511fSJiri Olsarun = -e cpu-clock -m 1 sleep 10
45163551dc7SJiri Olsa
45263551dc7SJiri Olsa[session-time]
45336bc511fSJiri Olsarun = -e task-clock -m 1 sleep 10
45463551dc7SJiri OlsaEOF
45563551dc7SJiri Olsa
45663551dc7SJiri Olsa	sed -i -e "s|BASE|${base}|" ${config}
45763551dc7SJiri Olsa
45863551dc7SJiri Olsa	# start daemon
45963551dc7SJiri Olsa	daemon_start ${config} size
46063551dc7SJiri Olsa
46163551dc7SJiri Olsa	size=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
46263551dc7SJiri Olsa	type=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
46363551dc7SJiri Olsa
464*5bd35dfbSShirisha G	if [ ${size} != "OK" ] || [ ${type} != "OK" ]; then
46563551dc7SJiri Olsa		error=1
46663551dc7SJiri Olsa		echo "FAILED: daemon ping failed"
46763551dc7SJiri Olsa	fi
46863551dc7SJiri Olsa
46963551dc7SJiri Olsa	# stop daemon
47087cb88d3SIan Rogers	daemon_exit ${config}
47163551dc7SJiri Olsa
47263551dc7SJiri Olsa	rm -rf ${base}
47363551dc7SJiri Olsa	rm -f ${config}
47463551dc7SJiri Olsa}
47563551dc7SJiri Olsa
476dec34515SJiri Olsatest_lock()
477dec34515SJiri Olsa{
478dec34515SJiri Olsa	echo "test daemon lock"
479dec34515SJiri Olsa
480*5bd35dfbSShirisha G	local config
481*5bd35dfbSShirisha G	config=$(mktemp /tmp/perf.daemon.config.XXX)
482*5bd35dfbSShirisha G	local base
483*5bd35dfbSShirisha G	base=$(mktemp -d /tmp/perf.daemon.base.XXX)
484dec34515SJiri Olsa
485dec34515SJiri Olsa	# prepare config
486dec34515SJiri Olsa	cat <<EOF > ${config}
487dec34515SJiri Olsa[daemon]
488dec34515SJiri Olsabase=BASE
489dec34515SJiri Olsa
490dec34515SJiri Olsa[session-size]
49136bc511fSJiri Olsarun = -e cpu-clock -m 1 sleep 10
492dec34515SJiri OlsaEOF
493dec34515SJiri Olsa
494dec34515SJiri Olsa	sed -i -e "s|BASE|${base}|" ${config}
495dec34515SJiri Olsa
496dec34515SJiri Olsa	# start daemon
497dec34515SJiri Olsa	daemon_start ${config} size
498dec34515SJiri Olsa
499dec34515SJiri Olsa	# start second daemon over the same config/base
500dec34515SJiri Olsa	failed=`perf daemon start --config ${config} 2>&1 | awk '{ print $1 }'`
501dec34515SJiri Olsa
502dec34515SJiri Olsa	# check that we failed properly
503dec34515SJiri Olsa	if [ ${failed} != "failed:" ]; then
504dec34515SJiri Olsa		error=1
505dec34515SJiri Olsa		echo "FAILED: daemon lock failed"
506dec34515SJiri Olsa	fi
507dec34515SJiri Olsa
508dec34515SJiri Olsa	# stop daemon
50987cb88d3SIan Rogers	daemon_exit ${config}
510dec34515SJiri Olsa
511dec34515SJiri Olsa	rm -rf ${base}
512dec34515SJiri Olsa	rm -f ${config}
513dec34515SJiri Olsa}
514dec34515SJiri Olsa
5152291bb91SJiri Olsaerror=0
5162291bb91SJiri Olsa
5172291bb91SJiri Olsatest_list
51891a17d6fSJiri Olsatest_reconfig
519f624f6d0SJiri Olsatest_stop
520f32102aaSJiri Olsatest_signal
52163551dc7SJiri Olsatest_ping
522dec34515SJiri Olsatest_lock
5232291bb91SJiri Olsa
5242291bb91SJiri Olsaexit ${error}
525