This patch contains scripts for applying stress on host or guest at
[kvmfornfv.git] / ci / envs / stress_scripts.sh
1 ################################################################
2 #This script will impose stress on specified processors with the
3 #arguments passed based on stress type.
4 ################################################################
5 #!/bin/bash
6 function usage() {
7     echo ""
8     echo "Usage --> $0 [-c CPU] [-t timeout] [-a stress-args][-h]"
9     echo "  CPU : 1/0-2 ;  default is 22-43"
10     echo "  timeout : N(number)"
11     echo "  stress-args : "--cpu=100 --vm=100 --io=10 --hdd=100""
12     echo "  -h : Help section"
13     echo ""
14 }
15
16 ##  --- Parse command line arguments / parameters ---
17 while getopts ":c:t:a:h" option; do
18     case $option in
19         c) # processor
20           processors=$OPTARG
21           ;;
22         t) # output_dir
23           timeout=$OPTARG
24           ;;
25         a)#istress args
26           args=$OPTARG
27           ;;
28         :)
29           echo "Option -$OPTARG requires an argument."
30           usage
31           exit 1
32           ;;
33         h)
34           usage
35           exit 0
36           ;;
37         *)
38           echo "Unknown option: $OPTARG."
39           usage
40           exit 1
41           ;;
42         ?)
43           echo "[WARNING] Unknown parameters!!!"
44           echo "Using default values for CPU,timeout and stress parameters"
45     esac
46 done
47
48
49 if [[ -z "$processors" ]]
50 then
51     processors='22-43'
52 fi
53
54 if [[ -z "$timeout" ]]
55 then
56    timeout='10m'
57 fi
58
59 if [[ -z "$args" ]]
60 then
61    args="--cpu=100"
62 fi
63
64 stress_params=$(echo $args | sed 's/[,=]/ /g'|sed -e 's/\r//g')
65
66 cmd="taskset -c $processors stress --timeout ${timeout} ${stress_params}"
67
68 echo $cmd
69
70 eval "${cmd}" &>/dev/null &disown