Loading...
1#!/bin/bash
2# daemon operations
3# SPDX-License-Identifier: GPL-2.0
4
5check_line_first()
6{
7 local line=$1
8 local name=$2
9 local base=$3
10 local output=$4
11 local lock=$5
12 local up=$6
13
14 local line_name
15 line_name=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $2 }'`
16 local line_base
17 line_base=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $3 }'`
18 local line_output
19 line_output=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $4 }'`
20 local line_lock
21 line_lock=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $5 }'`
22 local line_up
23 line_up=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $6 }'`
24
25 if [ "${name}" != "${line_name}" ]; then
26 echo "FAILED: wrong name"
27 error=1
28 fi
29
30 if [ "${base}" != "${line_base}" ]; then
31 echo "FAILED: wrong base"
32 error=1
33 fi
34
35 if [ "${output}" != "${line_output}" ]; then
36 echo "FAILED: wrong output"
37 error=1
38 fi
39
40 if [ "${lock}" != "${line_lock}" ]; then
41 echo "FAILED: wrong lock"
42 error=1
43 fi
44
45 if [ "${up}" != "${line_up}" ]; then
46 echo "FAILED: wrong up"
47 error=1
48 fi
49}
50
51check_line_other()
52{
53 local line=$1
54 local name=$2
55 local run=$3
56 local base=$4
57 local output=$5
58 local control=$6
59 local ack=$7
60 local up=$8
61
62 local line_name
63 line_name=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $2 }'`
64 local line_run
65 line_run=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $3 }'`
66 local line_base
67 line_base=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $4 }'`
68 local line_output
69 line_output=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $5 }'`
70 local line_control
71 line_control=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $6 }'`
72 local line_ack
73 line_ack=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $7 }'`
74 local line_up
75 line_up=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $8 }'`
76
77 if [ "${name}" != "${line_name}" ]; then
78 echo "FAILED: wrong name"
79 error=1
80 fi
81
82 if [ "${run}" != "${line_run}" ]; then
83 echo "FAILED: wrong run"
84 error=1
85 fi
86
87 if [ "${base}" != "${line_base}" ]; then
88 echo "FAILED: wrong base"
89 error=1
90 fi
91
92 if [ "${output}" != "${line_output}" ]; then
93 echo "FAILED: wrong output"
94 error=1
95 fi
96
97 if [ "${control}" != "${line_control}" ]; then
98 echo "FAILED: wrong control"
99 error=1
100 fi
101
102 if [ "${ack}" != "${line_ack}" ]; then
103 echo "FAILED: wrong ack"
104 error=1
105 fi
106
107 if [ "${up}" != "${line_up}" ]; then
108 echo "FAILED: wrong up"
109 error=1
110 fi
111}
112
113daemon_exit()
114{
115 local config=$1
116
117 local line
118 line=`perf daemon --config ${config} -x: | head -1`
119 local pid
120 pid=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $1 }'`
121
122 # Reset trap handler.
123 trap - SIGINT SIGTERM
124
125 # stop daemon
126 perf daemon stop --config ${config}
127
128 # ... and wait for the pid to go away
129 tail --pid=${pid} -f /dev/null
130}
131
132daemon_start()
133{
134 local config=$1
135 local session=$2
136
137 perf daemon start --config ${config}
138
139 # Clean up daemon if interrupted.
140 trap 'echo "FAILED: Signal caught"; daemon_exit "${config}"; exit 1' SIGINT SIGTERM
141
142 # wait for the session to ping
143 local state="FAIL"
144 local retries=0
145 while [ "${state}" != "OK" ]; do
146 state=`perf daemon ping --config ${config} --session ${session} | awk '{ print $1 }'`
147 sleep 0.05
148 retries=$((${retries} +1))
149 if [ ${retries} -ge 600 ]; then
150 echo "FAILED: Timeout waiting for daemon to ping"
151 daemon_exit ${config}
152 exit 1
153 fi
154 done
155}
156
157test_list()
158{
159 echo "test daemon list"
160
161 local config
162 config=$(mktemp /tmp/perf.daemon.config.XXX)
163 local base
164 base=$(mktemp -d /tmp/perf.daemon.base.XXX)
165
166 cat <<EOF > ${config}
167[daemon]
168base=BASE
169
170[session-size]
171run = -e cpu-clock -m 1 sleep 10
172
173[session-time]
174run = -e task-clock -m 1 sleep 10
175EOF
176
177 sed -i -e "s|BASE|${base}|" ${config}
178
179 # start daemon
180 daemon_start ${config} size
181
182 # check first line
183 # pid:daemon:base:base/output:base/lock
184 local line
185 line=`perf daemon --config ${config} -x: | head -1`
186 check_line_first ${line} daemon ${base} ${base}/output ${base}/lock "0"
187
188 # check 1st session
189 # pid:size:-e cpu-clock:base/size:base/size/output:base/size/control:base/size/ack:0
190 local line
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"
195
196 # check 2nd session
197 # pid:time:-e task-clock:base/time:base/time/output:base/time/control:base/time/ack:0
198 local line
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"
203
204 # stop daemon
205 daemon_exit ${config}
206
207 rm -rf ${base}
208 rm -f ${config}
209}
210
211test_reconfig()
212{
213 echo "test daemon reconfig"
214
215 local config
216 config=$(mktemp /tmp/perf.daemon.config.XXX)
217 local base
218 base=$(mktemp -d /tmp/perf.daemon.base.XXX)
219
220 # prepare config
221 cat <<EOF > ${config}
222[daemon]
223base=BASE
224
225[session-size]
226run = -e cpu-clock -m 1 sleep 10
227
228[session-time]
229run = -e task-clock -m 1 sleep 10
230EOF
231
232 sed -i -e "s|BASE|${base}|" ${config}
233
234 # start daemon
235 daemon_start ${config} size
236
237 # check 2nd session
238 # pid:time:-e task-clock:base/time:base/time/output:base/time/control:base/time/ack:0
239 local line
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"
243 local pid
244 pid=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $1 }'`
245
246 # prepare new config
247 local config_new=${config}.new
248 cat <<EOF > ${config_new}
249[daemon]
250base=BASE
251
252[session-size]
253run = -e cpu-clock -m 1 sleep 10
254
255[session-time]
256run = -e cpu-clock -m 1 sleep 10
257EOF
258
259 # TEST 1 - change config
260
261 sed -i -e "s|BASE|${base}|" ${config_new}
262 cp ${config_new} ${config}
263
264 # wait for old session to finish
265 tail --pid=${pid} -f /dev/null
266
267 # wait for new one to start
268 local state="FAIL"
269 while [ "${state}" != "OK" ]; do
270 state=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
271 done
272
273 # check reconfigured 2nd session
274 # pid:time:-e task-clock:base/time:base/time/output:base/time/control:base/time/ack:0
275 local line
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"
279
280 # TEST 2 - empty config
281
282 local config_empty=${config}.empty
283 cat <<EOF > ${config_empty}
284[daemon]
285base=BASE
286EOF
287
288 # change config
289 sed -i -e "s|BASE|${base}|" ${config_empty}
290 cp ${config_empty} ${config}
291
292 # wait for sessions to finish
293 local state="OK"
294 while [ "${state}" != "FAIL" ]; do
295 state=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
296 done
297
298 local state="OK"
299 while [ "${state}" != "FAIL" ]; do
300 state=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
301 done
302
303 local one
304 one=`perf daemon --config ${config} -x: | wc -l`
305
306 if [ ${one} -ne "1" ]; then
307 echo "FAILED: wrong list output"
308 error=1
309 fi
310
311 # TEST 3 - config again
312
313 cp ${config_new} ${config}
314
315 # wait for size to start
316 local state="FAIL"
317 while [ "${state}" != "OK" ]; do
318 state=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
319 done
320
321 # wait for time to start
322 local state="FAIL"
323 while [ "${state}" != "OK" ]; do
324 state=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
325 done
326
327 # stop daemon
328 daemon_exit ${config}
329
330 rm -rf ${base}
331 rm -f ${config}
332 rm -f ${config_new}
333 rm -f ${config_empty}
334}
335
336test_stop()
337{
338 echo "test daemon stop"
339
340 local config
341 config=$(mktemp /tmp/perf.daemon.config.XXX)
342 local base
343 base=$(mktemp -d /tmp/perf.daemon.base.XXX)
344
345 # prepare config
346 cat <<EOF > ${config}
347[daemon]
348base=BASE
349
350[session-size]
351run = -e cpu-clock -m 1 sleep 10
352
353[session-time]
354run = -e task-clock -m 1 sleep 10
355EOF
356
357 sed -i -e "s|BASE|${base}|" ${config}
358
359 # start daemon
360 daemon_start ${config} size
361
362 local pid_size
363 pid_size=`perf daemon --config ${config} -x: | head -2 | tail -1 |
364 awk 'BEGIN { FS = ":" } ; { print $1 }'`
365 local pid_time
366 pid_time=`perf daemon --config ${config} -x: | head -3 | tail -1 |
367 awk 'BEGIN { FS = ":" } ; { print $1 }'`
368
369 # check that sessions are running
370 if [ ! -d "/proc/${pid_size}" ]; then
371 echo "FAILED: session size not up"
372 fi
373
374 if [ ! -d "/proc/${pid_time}" ]; then
375 echo "FAILED: session time not up"
376 fi
377
378 # stop daemon
379 daemon_exit ${config}
380
381 # check that sessions are gone
382 if [ -d "/proc/${pid_size}" ]; then
383 echo "FAILED: session size still up"
384 fi
385
386 if [ -d "/proc/${pid_time}" ]; then
387 echo "FAILED: session time still up"
388 fi
389
390 rm -rf ${base}
391 rm -f ${config}
392}
393
394test_signal()
395{
396 echo "test daemon signal"
397
398 local config
399 config=$(mktemp /tmp/perf.daemon.config.XXX)
400 local base
401 base=$(mktemp -d /tmp/perf.daemon.base.XXX)
402
403 # prepare config
404 cat <<EOF > ${config}
405[daemon]
406base=BASE
407
408[session-test]
409run = -e cpu-clock --switch-output -m 1 sleep 10
410EOF
411
412 sed -i -e "s|BASE|${base}|" ${config}
413
414 # start daemon
415 daemon_start ${config} test
416
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
419 # give up.
420 local retries=0
421 local signals=0
422 local success=0
423 while [ ${retries} -lt 600 ] && [ ${success} -eq 0 ]; do
424 local files
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
428 signals=1
429 elif [ ${signals} -eq 1 ] && [ $files -ge 1 ]; then
430 perf daemon signal --config ${config}
431 signals=2
432 elif [ ${signals} -eq 2 ] && [ $files -ge 2 ]; then
433 daemon_exit ${config}
434 signals=3
435 elif [ ${signals} -eq 3 ] && [ $files -ge 3 ]; then
436 success=1
437 fi
438 retries=$((${retries} +1))
439 done
440 if [ ${success} -eq 0 ]; then
441 error=1
442 echo "FAILED: perf data no generated"
443 fi
444
445 rm -rf ${base}
446 rm -f ${config}
447}
448
449test_ping()
450{
451 echo "test daemon ping"
452
453 local config
454 config=$(mktemp /tmp/perf.daemon.config.XXX)
455 local base
456 base=$(mktemp -d /tmp/perf.daemon.base.XXX)
457
458 # prepare config
459 cat <<EOF > ${config}
460[daemon]
461base=BASE
462
463[session-size]
464run = -e cpu-clock -m 1 sleep 10
465
466[session-time]
467run = -e task-clock -m 1 sleep 10
468EOF
469
470 sed -i -e "s|BASE|${base}|" ${config}
471
472 # start daemon
473 daemon_start ${config} size
474
475 size=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
476 type=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
477
478 if [ ${size} != "OK" ] || [ ${type} != "OK" ]; then
479 error=1
480 echo "FAILED: daemon ping failed"
481 fi
482
483 # stop daemon
484 daemon_exit ${config}
485
486 rm -rf ${base}
487 rm -f ${config}
488}
489
490test_lock()
491{
492 echo "test daemon lock"
493
494 local config
495 config=$(mktemp /tmp/perf.daemon.config.XXX)
496 local base
497 base=$(mktemp -d /tmp/perf.daemon.base.XXX)
498
499 # prepare config
500 cat <<EOF > ${config}
501[daemon]
502base=BASE
503
504[session-size]
505run = -e cpu-clock -m 1 sleep 10
506EOF
507
508 sed -i -e "s|BASE|${base}|" ${config}
509
510 # start daemon
511 daemon_start ${config} size
512
513 # start second daemon over the same config/base
514 failed=`perf daemon start --config ${config} 2>&1 | awk '{ print $1 }'`
515
516 # check that we failed properly
517 if [ ${failed} != "failed:" ]; then
518 error=1
519 echo "FAILED: daemon lock failed"
520 fi
521
522 # stop daemon
523 daemon_exit ${config}
524
525 rm -rf ${base}
526 rm -f ${config}
527}
528
529error=0
530
531test_list
532test_reconfig
533test_stop
534test_signal
535test_ping
536test_lock
537
538exit ${error}
1#!/bin/bash
2# daemon operations
3# SPDX-License-Identifier: GPL-2.0
4
5check_line_first()
6{
7 local line=$1
8 local name=$2
9 local base=$3
10 local output=$4
11 local lock=$5
12 local up=$6
13
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 }'`
19
20 if [ "${name}" != "${line_name}" ]; then
21 echo "FAILED: wrong name"
22 error=1
23 fi
24
25 if [ "${base}" != "${line_base}" ]; then
26 echo "FAILED: wrong base"
27 error=1
28 fi
29
30 if [ "${output}" != "${line_output}" ]; then
31 echo "FAILED: wrong output"
32 error=1
33 fi
34
35 if [ "${lock}" != "${line_lock}" ]; then
36 echo "FAILED: wrong lock"
37 error=1
38 fi
39
40 if [ "${up}" != "${line_up}" ]; then
41 echo "FAILED: wrong up"
42 error=1
43 fi
44}
45
46check_line_other()
47{
48 local line=$1
49 local name=$2
50 local run=$3
51 local base=$4
52 local output=$5
53 local control=$6
54 local ack=$7
55 local up=$8
56
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 }'`
64
65 if [ "${name}" != "${line_name}" ]; then
66 echo "FAILED: wrong name"
67 error=1
68 fi
69
70 if [ "${run}" != "${line_run}" ]; then
71 echo "FAILED: wrong run"
72 error=1
73 fi
74
75 if [ "${base}" != "${line_base}" ]; then
76 echo "FAILED: wrong base"
77 error=1
78 fi
79
80 if [ "${output}" != "${line_output}" ]; then
81 echo "FAILED: wrong output"
82 error=1
83 fi
84
85 if [ "${control}" != "${line_control}" ]; then
86 echo "FAILED: wrong control"
87 error=1
88 fi
89
90 if [ "${ack}" != "${line_ack}" ]; then
91 echo "FAILED: wrong ack"
92 error=1
93 fi
94
95 if [ "${up}" != "${line_up}" ]; then
96 echo "FAILED: wrong up"
97 error=1
98 fi
99}
100
101daemon_exit()
102{
103 local config=$1
104
105 local line=`perf daemon --config ${config} -x: | head -1`
106 local pid=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $1 }'`
107
108 # Reset trap handler.
109 trap - SIGINT SIGTERM
110
111 # stop daemon
112 perf daemon stop --config ${config}
113
114 # ... and wait for the pid to go away
115 tail --pid=${pid} -f /dev/null
116}
117
118daemon_start()
119{
120 local config=$1
121 local session=$2
122
123 perf daemon start --config ${config}
124
125 # Clean up daemon if interrupted.
126 trap "echo 'FAILED: Signal caught'; daemon_exit ${config}; exit 1" SIGINT SIGTERM
127
128 # wait for the session to ping
129 local state="FAIL"
130 local retries=0
131 while [ "${state}" != "OK" ]; do
132 state=`perf daemon ping --config ${config} --session ${session} | awk '{ print $1 }'`
133 sleep 0.05
134 retries=$((${retries} +1))
135 if [ ${retries} -ge 600 ]; then
136 echo "FAILED: Timeout waiting for daemon to ping"
137 daemon_exit ${config}
138 exit 1
139 fi
140 done
141}
142
143test_list()
144{
145 echo "test daemon list"
146
147 local config=$(mktemp /tmp/perf.daemon.config.XXX)
148 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
149
150 cat <<EOF > ${config}
151[daemon]
152base=BASE
153
154[session-size]
155run = -e cpu-clock -m 1 sleep 10
156
157[session-time]
158run = -e task-clock -m 1 sleep 10
159EOF
160
161 sed -i -e "s|BASE|${base}|" ${config}
162
163 # start daemon
164 daemon_start ${config} size
165
166 # check first line
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"
170
171 # check 1st session
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"
177
178 # check 2nd session
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"
184
185 # stop daemon
186 daemon_exit ${config}
187
188 rm -rf ${base}
189 rm -f ${config}
190}
191
192test_reconfig()
193{
194 echo "test daemon reconfig"
195
196 local config=$(mktemp /tmp/perf.daemon.config.XXX)
197 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
198
199 # prepare config
200 cat <<EOF > ${config}
201[daemon]
202base=BASE
203
204[session-size]
205run = -e cpu-clock -m 1 sleep 10
206
207[session-time]
208run = -e task-clock -m 1 sleep 10
209EOF
210
211 sed -i -e "s|BASE|${base}|" ${config}
212
213 # start daemon
214 daemon_start ${config} size
215
216 # check 2nd session
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 }'`
222
223 # prepare new config
224 local config_new=${config}.new
225 cat <<EOF > ${config_new}
226[daemon]
227base=BASE
228
229[session-size]
230run = -e cpu-clock -m 1 sleep 10
231
232[session-time]
233run = -e cpu-clock -m 1 sleep 10
234EOF
235
236 # TEST 1 - change config
237
238 sed -i -e "s|BASE|${base}|" ${config_new}
239 cp ${config_new} ${config}
240
241 # wait for old session to finish
242 tail --pid=${pid} -f /dev/null
243
244 # wait for new one to start
245 local state="FAIL"
246 while [ "${state}" != "OK" ]; do
247 state=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
248 done
249
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"
255
256 # TEST 2 - empty config
257
258 local config_empty=${config}.empty
259 cat <<EOF > ${config_empty}
260[daemon]
261base=BASE
262EOF
263
264 # change config
265 sed -i -e "s|BASE|${base}|" ${config_empty}
266 cp ${config_empty} ${config}
267
268 # wait for sessions to finish
269 local state="OK"
270 while [ "${state}" != "FAIL" ]; do
271 state=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
272 done
273
274 local state="OK"
275 while [ "${state}" != "FAIL" ]; do
276 state=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
277 done
278
279 local one=`perf daemon --config ${config} -x: | wc -l`
280
281 if [ ${one} -ne "1" ]; then
282 echo "FAILED: wrong list output"
283 error=1
284 fi
285
286 # TEST 3 - config again
287
288 cp ${config_new} ${config}
289
290 # wait for size to start
291 local state="FAIL"
292 while [ "${state}" != "OK" ]; do
293 state=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
294 done
295
296 # wait for time to start
297 local state="FAIL"
298 while [ "${state}" != "OK" ]; do
299 state=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
300 done
301
302 # stop daemon
303 daemon_exit ${config}
304
305 rm -rf ${base}
306 rm -f ${config}
307 rm -f ${config_new}
308 rm -f ${config_empty}
309}
310
311test_stop()
312{
313 echo "test daemon stop"
314
315 local config=$(mktemp /tmp/perf.daemon.config.XXX)
316 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
317
318 # prepare config
319 cat <<EOF > ${config}
320[daemon]
321base=BASE
322
323[session-size]
324run = -e cpu-clock -m 1 sleep 10
325
326[session-time]
327run = -e task-clock -m 1 sleep 10
328EOF
329
330 sed -i -e "s|BASE|${base}|" ${config}
331
332 # start daemon
333 daemon_start ${config} size
334
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 }'`
337
338 # check that sessions are running
339 if [ ! -d "/proc/${pid_size}" ]; then
340 echo "FAILED: session size not up"
341 fi
342
343 if [ ! -d "/proc/${pid_time}" ]; then
344 echo "FAILED: session time not up"
345 fi
346
347 # stop daemon
348 daemon_exit ${config}
349
350 # check that sessions are gone
351 if [ -d "/proc/${pid_size}" ]; then
352 echo "FAILED: session size still up"
353 fi
354
355 if [ -d "/proc/${pid_time}" ]; then
356 echo "FAILED: session time still up"
357 fi
358
359 rm -rf ${base}
360 rm -f ${config}
361}
362
363test_signal()
364{
365 echo "test daemon signal"
366
367 local config=$(mktemp /tmp/perf.daemon.config.XXX)
368 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
369
370 # prepare config
371 cat <<EOF > ${config}
372[daemon]
373base=BASE
374
375[session-test]
376run = -e cpu-clock --switch-output -m 1 sleep 10
377EOF
378
379 sed -i -e "s|BASE|${base}|" ${config}
380
381 # start daemon
382 daemon_start ${config} test
383
384 # send 2 signals
385 perf daemon signal --config ${config} --session test
386 perf daemon signal --config ${config}
387
388 # stop daemon
389 daemon_exit ${config}
390
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
394 error=1
395 echo "FAILED: perf data no generated"
396 fi
397
398 rm -rf ${base}
399 rm -f ${config}
400}
401
402test_ping()
403{
404 echo "test daemon ping"
405
406 local config=$(mktemp /tmp/perf.daemon.config.XXX)
407 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
408
409 # prepare config
410 cat <<EOF > ${config}
411[daemon]
412base=BASE
413
414[session-size]
415run = -e cpu-clock -m 1 sleep 10
416
417[session-time]
418run = -e task-clock -m 1 sleep 10
419EOF
420
421 sed -i -e "s|BASE|${base}|" ${config}
422
423 # start daemon
424 daemon_start ${config} size
425
426 size=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
427 type=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
428
429 if [ ${size} != "OK" -o ${type} != "OK" ]; then
430 error=1
431 echo "FAILED: daemon ping failed"
432 fi
433
434 # stop daemon
435 daemon_exit ${config}
436
437 rm -rf ${base}
438 rm -f ${config}
439}
440
441test_lock()
442{
443 echo "test daemon lock"
444
445 local config=$(mktemp /tmp/perf.daemon.config.XXX)
446 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
447
448 # prepare config
449 cat <<EOF > ${config}
450[daemon]
451base=BASE
452
453[session-size]
454run = -e cpu-clock -m 1 sleep 10
455EOF
456
457 sed -i -e "s|BASE|${base}|" ${config}
458
459 # start daemon
460 daemon_start ${config} size
461
462 # start second daemon over the same config/base
463 failed=`perf daemon start --config ${config} 2>&1 | awk '{ print $1 }'`
464
465 # check that we failed properly
466 if [ ${failed} != "failed:" ]; then
467 error=1
468 echo "FAILED: daemon lock failed"
469 fi
470
471 # stop daemon
472 daemon_exit ${config}
473
474 rm -rf ${base}
475 rm -f ${config}
476}
477
478error=0
479
480test_list
481test_reconfig
482test_stop
483test_signal
484test_ping
485test_lock
486
487exit ${error}