0001
0002
0003
0004
0005 check_line_first()
0006 {
0007 local line=$1
0008 local name=$2
0009 local base=$3
0010 local output=$4
0011 local lock=$5
0012 local up=$6
0013
0014 local line_name=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $2 }'`
0015 local line_base=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $3 }'`
0016 local line_output=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $4 }'`
0017 local line_lock=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $5 }'`
0018 local line_up=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $6 }'`
0019
0020 if [ "${name}" != "${line_name}" ]; then
0021 echo "FAILED: wrong name"
0022 error=1
0023 fi
0024
0025 if [ "${base}" != "${line_base}" ]; then
0026 echo "FAILED: wrong base"
0027 error=1
0028 fi
0029
0030 if [ "${output}" != "${line_output}" ]; then
0031 echo "FAILED: wrong output"
0032 error=1
0033 fi
0034
0035 if [ "${lock}" != "${line_lock}" ]; then
0036 echo "FAILED: wrong lock"
0037 error=1
0038 fi
0039
0040 if [ "${up}" != "${line_up}" ]; then
0041 echo "FAILED: wrong up"
0042 error=1
0043 fi
0044 }
0045
0046 check_line_other()
0047 {
0048 local line=$1
0049 local name=$2
0050 local run=$3
0051 local base=$4
0052 local output=$5
0053 local control=$6
0054 local ack=$7
0055 local up=$8
0056
0057 local line_name=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $2 }'`
0058 local line_run=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $3 }'`
0059 local line_base=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $4 }'`
0060 local line_output=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $5 }'`
0061 local line_control=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $6 }'`
0062 local line_ack=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $7 }'`
0063 local line_up=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $8 }'`
0064
0065 if [ "${name}" != "${line_name}" ]; then
0066 echo "FAILED: wrong name"
0067 error=1
0068 fi
0069
0070 if [ "${run}" != "${line_run}" ]; then
0071 echo "FAILED: wrong run"
0072 error=1
0073 fi
0074
0075 if [ "${base}" != "${line_base}" ]; then
0076 echo "FAILED: wrong base"
0077 error=1
0078 fi
0079
0080 if [ "${output}" != "${line_output}" ]; then
0081 echo "FAILED: wrong output"
0082 error=1
0083 fi
0084
0085 if [ "${control}" != "${line_control}" ]; then
0086 echo "FAILED: wrong control"
0087 error=1
0088 fi
0089
0090 if [ "${ack}" != "${line_ack}" ]; then
0091 echo "FAILED: wrong ack"
0092 error=1
0093 fi
0094
0095 if [ "${up}" != "${line_up}" ]; then
0096 echo "FAILED: wrong up"
0097 error=1
0098 fi
0099 }
0100
0101 daemon_exit()
0102 {
0103 local config=$1
0104
0105 local line=`perf daemon --config ${config} -x: | head -1`
0106 local pid=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $1 }'`
0107
0108
0109 trap - SIGINT SIGTERM
0110
0111
0112 perf daemon stop --config ${config}
0113
0114
0115 tail --pid=${pid} -f /dev/null
0116 }
0117
0118 daemon_start()
0119 {
0120 local config=$1
0121 local session=$2
0122
0123 perf daemon start --config ${config}
0124
0125
0126 trap "echo 'FAILED: Signal caught'; daemon_exit ${config}; exit 1" SIGINT SIGTERM
0127
0128
0129 local state="FAIL"
0130 local retries=0
0131 while [ "${state}" != "OK" ]; do
0132 state=`perf daemon ping --config ${config} --session ${session} | awk '{ print $1 }'`
0133 sleep 0.05
0134 retries=$((${retries} +1))
0135 if [ ${retries} -ge 600 ]; then
0136 echo "FAILED: Timeout waiting for daemon to ping"
0137 daemon_exit ${config}
0138 exit 1
0139 fi
0140 done
0141 }
0142
0143 test_list()
0144 {
0145 echo "test daemon list"
0146
0147 local config=$(mktemp /tmp/perf.daemon.config.XXX)
0148 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
0149
0150 cat <<EOF > ${config}
0151 [daemon]
0152 base=BASE
0153
0154 [session-size]
0155 run = -e cpu-clock -m 1 sleep 10
0156
0157 [session-time]
0158 run = -e task-clock -m 1 sleep 10
0159 EOF
0160
0161 sed -i -e "s|BASE|${base}|" ${config}
0162
0163
0164 daemon_start ${config} size
0165
0166
0167
0168 local line=`perf daemon --config ${config} -x: | head -1`
0169 check_line_first ${line} daemon ${base} ${base}/output ${base}/lock "0"
0170
0171
0172
0173 local line=`perf daemon --config ${config} -x: | head -2 | tail -1`
0174 check_line_other "${line}" size "-e cpu-clock -m 1 sleep 10" ${base}/session-size \
0175 ${base}/session-size/output ${base}/session-size/control \
0176 ${base}/session-size/ack "0"
0177
0178
0179
0180 local line=`perf daemon --config ${config} -x: | head -3 | tail -1`
0181 check_line_other "${line}" time "-e task-clock -m 1 sleep 10" ${base}/session-time \
0182 ${base}/session-time/output ${base}/session-time/control \
0183 ${base}/session-time/ack "0"
0184
0185
0186 daemon_exit ${config}
0187
0188 rm -rf ${base}
0189 rm -f ${config}
0190 }
0191
0192 test_reconfig()
0193 {
0194 echo "test daemon reconfig"
0195
0196 local config=$(mktemp /tmp/perf.daemon.config.XXX)
0197 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
0198
0199
0200 cat <<EOF > ${config}
0201 [daemon]
0202 base=BASE
0203
0204 [session-size]
0205 run = -e cpu-clock -m 1 sleep 10
0206
0207 [session-time]
0208 run = -e task-clock -m 1 sleep 10
0209 EOF
0210
0211 sed -i -e "s|BASE|${base}|" ${config}
0212
0213
0214 daemon_start ${config} size
0215
0216
0217
0218 local line=`perf daemon --config ${config} -x: | head -3 | tail -1`
0219 check_line_other "${line}" time "-e task-clock -m 1 sleep 10" ${base}/session-time \
0220 ${base}/session-time/output ${base}/session-time/control ${base}/session-time/ack "0"
0221 local pid=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $1 }'`
0222
0223
0224 local config_new=${config}.new
0225 cat <<EOF > ${config_new}
0226 [daemon]
0227 base=BASE
0228
0229 [session-size]
0230 run = -e cpu-clock -m 1 sleep 10
0231
0232 [session-time]
0233 run = -e cpu-clock -m 1 sleep 10
0234 EOF
0235
0236
0237
0238 sed -i -e "s|BASE|${base}|" ${config_new}
0239 cp ${config_new} ${config}
0240
0241
0242 tail --pid=${pid} -f /dev/null
0243
0244
0245 local state="FAIL"
0246 while [ "${state}" != "OK" ]; do
0247 state=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
0248 done
0249
0250
0251
0252 local line=`perf daemon --config ${config} -x: | head -3 | tail -1`
0253 check_line_other "${line}" time "-e cpu-clock -m 1 sleep 10" ${base}/session-time \
0254 ${base}/session-time/output ${base}/session-time/control ${base}/session-time/ack "0"
0255
0256
0257
0258 local config_empty=${config}.empty
0259 cat <<EOF > ${config_empty}
0260 [daemon]
0261 base=BASE
0262 EOF
0263
0264
0265 sed -i -e "s|BASE|${base}|" ${config_empty}
0266 cp ${config_empty} ${config}
0267
0268
0269 local state="OK"
0270 while [ "${state}" != "FAIL" ]; do
0271 state=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
0272 done
0273
0274 local state="OK"
0275 while [ "${state}" != "FAIL" ]; do
0276 state=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
0277 done
0278
0279 local one=`perf daemon --config ${config} -x: | wc -l`
0280
0281 if [ ${one} -ne "1" ]; then
0282 echo "FAILED: wrong list output"
0283 error=1
0284 fi
0285
0286
0287
0288 cp ${config_new} ${config}
0289
0290
0291 local state="FAIL"
0292 while [ "${state}" != "OK" ]; do
0293 state=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
0294 done
0295
0296
0297 local state="FAIL"
0298 while [ "${state}" != "OK" ]; do
0299 state=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
0300 done
0301
0302
0303 daemon_exit ${config}
0304
0305 rm -rf ${base}
0306 rm -f ${config}
0307 rm -f ${config_new}
0308 rm -f ${config_empty}
0309 }
0310
0311 test_stop()
0312 {
0313 echo "test daemon stop"
0314
0315 local config=$(mktemp /tmp/perf.daemon.config.XXX)
0316 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
0317
0318
0319 cat <<EOF > ${config}
0320 [daemon]
0321 base=BASE
0322
0323 [session-size]
0324 run = -e cpu-clock -m 1 sleep 10
0325
0326 [session-time]
0327 run = -e task-clock -m 1 sleep 10
0328 EOF
0329
0330 sed -i -e "s|BASE|${base}|" ${config}
0331
0332
0333 daemon_start ${config} size
0334
0335 local pid_size=`perf daemon --config ${config} -x: | head -2 | tail -1 | awk 'BEGIN { FS = ":" } ; { print $1 }'`
0336 local pid_time=`perf daemon --config ${config} -x: | head -3 | tail -1 | awk 'BEGIN { FS = ":" } ; { print $1 }'`
0337
0338
0339 if [ ! -d "/proc/${pid_size}" ]; then
0340 echo "FAILED: session size not up"
0341 fi
0342
0343 if [ ! -d "/proc/${pid_time}" ]; then
0344 echo "FAILED: session time not up"
0345 fi
0346
0347
0348 daemon_exit ${config}
0349
0350
0351 if [ -d "/proc/${pid_size}" ]; then
0352 echo "FAILED: session size still up"
0353 fi
0354
0355 if [ -d "/proc/${pid_time}" ]; then
0356 echo "FAILED: session time still up"
0357 fi
0358
0359 rm -rf ${base}
0360 rm -f ${config}
0361 }
0362
0363 test_signal()
0364 {
0365 echo "test daemon signal"
0366
0367 local config=$(mktemp /tmp/perf.daemon.config.XXX)
0368 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
0369
0370
0371 cat <<EOF > ${config}
0372 [daemon]
0373 base=BASE
0374
0375 [session-test]
0376 run = -e cpu-clock --switch-output -m 1 sleep 10
0377 EOF
0378
0379 sed -i -e "s|BASE|${base}|" ${config}
0380
0381
0382 daemon_start ${config} test
0383
0384
0385 perf daemon signal --config ${config} --session test
0386 perf daemon signal --config ${config}
0387
0388
0389 daemon_exit ${config}
0390
0391
0392 count=`ls ${base}/session-test/ | grep perf.data | wc -l`
0393 if [ ${count} -ne 3 ]; then
0394 error=1
0395 echo "FAILED: perf data no generated"
0396 fi
0397
0398 rm -rf ${base}
0399 rm -f ${config}
0400 }
0401
0402 test_ping()
0403 {
0404 echo "test daemon ping"
0405
0406 local config=$(mktemp /tmp/perf.daemon.config.XXX)
0407 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
0408
0409
0410 cat <<EOF > ${config}
0411 [daemon]
0412 base=BASE
0413
0414 [session-size]
0415 run = -e cpu-clock -m 1 sleep 10
0416
0417 [session-time]
0418 run = -e task-clock -m 1 sleep 10
0419 EOF
0420
0421 sed -i -e "s|BASE|${base}|" ${config}
0422
0423
0424 daemon_start ${config} size
0425
0426 size=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'`
0427 type=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'`
0428
0429 if [ ${size} != "OK" -o ${type} != "OK" ]; then
0430 error=1
0431 echo "FAILED: daemon ping failed"
0432 fi
0433
0434
0435 daemon_exit ${config}
0436
0437 rm -rf ${base}
0438 rm -f ${config}
0439 }
0440
0441 test_lock()
0442 {
0443 echo "test daemon lock"
0444
0445 local config=$(mktemp /tmp/perf.daemon.config.XXX)
0446 local base=$(mktemp -d /tmp/perf.daemon.base.XXX)
0447
0448
0449 cat <<EOF > ${config}
0450 [daemon]
0451 base=BASE
0452
0453 [session-size]
0454 run = -e cpu-clock -m 1 sleep 10
0455 EOF
0456
0457 sed -i -e "s|BASE|${base}|" ${config}
0458
0459
0460 daemon_start ${config} size
0461
0462
0463 failed=`perf daemon start --config ${config} 2>&1 | awk '{ print $1 }'`
0464
0465
0466 if [ ${failed} != "failed:" ]; then
0467 error=1
0468 echo "FAILED: daemon lock failed"
0469 fi
0470
0471
0472 daemon_exit ${config}
0473
0474 rm -rf ${base}
0475 rm -f ${config}
0476 }
0477
0478 error=0
0479
0480 test_list
0481 test_reconfig
0482 test_stop
0483 test_signal
0484 test_ping
0485 test_lock
0486
0487 exit ${error}