summaryrefslogtreecommitdiff
path: root/tests/renice.test
blob: e87111cc66fe090ca517f70d56f9a703c40e8e9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash

# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>

[ -f testing.sh ] && . testing.sh

#testing "name" "command" "result" "infile" "stdin"

fun_nice_val() 
{
  for each_proc in $@
  do
    echo `awk '{ print $18 }' /proc/${each_proc}/stat`
  done
}

# creating processes as a test data
yes >/dev/null &
proc1=$!
yes >/dev/null &
proc2=$!
yes >/dev/null &
proc3=$!
yes >/dev/null &
proc4=$!
yes >/dev/null &
proc5=$!

n_val1=`fun_nice_val $proc1`
n_val2=`fun_nice_val $proc2`
n_val3=`fun_nice_val $proc3`
n_val4=`fun_nice_val $proc4`
n_val5=`fun_nice_val $proc5`

# Redirecting errors to /dev/null
arg="2>/dev/null"

for n_v in "-1" "1"
do
  for n_o in "" " -p"
  do
    nice_val1=$((`fun_nice_val $proc1` + $n_v))
    nice_val2=$((`fun_nice_val $proc2` + $n_v))
    nice_val3=$((`fun_nice_val $proc3` + $n_v))
    nice_val4=$((`fun_nice_val $proc4` + $n_v))
    nice_val5=$((`fun_nice_val $proc5` + $n_v))
    testing "renice with -n=$n_v and with$n_o multiple_pids" \
      "renice -n $n_v$n_o $proc1 $proc2 $proc3 $proc4 $proc5 &&
       fun_nice_val $proc1 $proc2 $proc3 $proc4 $proc5" \
      "$nice_val1\n$nice_val2\n$nice_val3\n$nice_val4\n$nice_val5\n" "" ""
  
    nice_val1=$((`fun_nice_val $proc1` + $n_v))
    nice_val2=$((`fun_nice_val $proc2` + $n_v))
    nice_val3=$((`fun_nice_val $proc3` + $n_v))
    nice_val4=$((`fun_nice_val $proc4` + $n_v))
    nice_val5=$((`fun_nice_val $proc5` + $n_v))
    testing "renice with -n=$n_v and with$n_o multiple_pids (some invalid)" \
      "renice -n $n_v$n_o $proc1 $proc2 88888 99999 $proc3 $proc4 $proc5 $arg ||
       fun_nice_val $proc1 $proc2 $proc3 $proc4 $proc5" \
      "$nice_val1\n$nice_val2\n$nice_val3\n$nice_val4\n$nice_val5\n" "" ""
  done
done

# Starting Boundary Test Here .. 
loop_cnt=2
echo -n "TEST: Boundary value test for Id($proc1)..[old_nice_val/new_nice_val]:"
cnt=0
n_val=1
while [ $cnt -gt -1 ]
do
  old_nice_val=`fun_nice_val $proc1`
  new_nice_val=`renice -n $n_val $proc1 >/dev/null 2>&1 && fun_nice_val $proc1`
  echo -n "[$old_nice_val/$new_nice_val],"
  if [ $old_nice_val -eq 39 -a $old_nice_val -eq $new_nice_val ]
  then
    echo -n " [Equals 39,doing -1] "
    n_val="-1"
  elif [ $old_nice_val -eq 0 -a $old_nice_val -eq $new_nice_val ]
  then
    echo -n " [Equals 0,doing +1] "
    n_val="1"
  elif [ $new_nice_val -gt 39 -o $new_nice_val -lt 0 ]
  then
    echo " [Test Fail] "
    echo "FAIL: renice with step 1 ($proc1) (boundary value)"
    cnt="-1"
  elif [ $new_nice_val -eq $n_val1 -a $new_nice_val -eq $(($old_nice_val+1)) ]
  then
    cnt=$(($cnt + 1))
    if [ $cnt -eq $loop_cnt ]
    then
      echo " [Test Pass] "
      echo "PASS: renice with step 1 ($proc1) (boundary value)"
      cnt="-1"
    fi
  else
    dif=`echo $(($new_nice_val-$old_nice_val))`
    dif=`echo ${dif/-}`
    if [ $dif -ne 1 ]
    then
      echo " [Test Fail] "
      echo "FAIL: renice with step 1 ($proc1) (boundary value)"
      cnt="-1"
    fi
  fi
done
# Boundary test End

killall yes >/dev/null 2>&1