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