• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
4# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
5
6[ -f testing.sh ] && . testing.sh
7
8#testing "name" "command" "result" "infile" "stdin"
9
10fun_nice_val()
11{
12  for each_proc in $@
13  do
14    echo `cut -d' ' -f18 /proc/${each_proc}/stat`
15  done
16}
17
18# creating processes as a test data
19yes >/dev/null &
20proc1=$!
21yes >/dev/null &
22proc2=$!
23yes >/dev/null &
24proc3=$!
25yes >/dev/null &
26proc4=$!
27yes >/dev/null &
28proc5=$!
29
30n_val1=`fun_nice_val $proc1`
31n_val2=`fun_nice_val $proc2`
32n_val3=`fun_nice_val $proc3`
33n_val4=`fun_nice_val $proc4`
34n_val5=`fun_nice_val $proc5`
35
36# Redirecting errors to /dev/null
37arg="2>/dev/null"
38
39for n_v in "-1" "1"
40do
41  for n_o in "" " -p"
42  do
43    nice_val1=$((`fun_nice_val $proc1` + $n_v))
44    nice_val2=$((`fun_nice_val $proc2` + $n_v))
45    nice_val3=$((`fun_nice_val $proc3` + $n_v))
46    nice_val4=$((`fun_nice_val $proc4` + $n_v))
47    nice_val5=$((`fun_nice_val $proc5` + $n_v))
48    testing "with -n=$n_v and with$n_o multiple_pids" \
49      "renice -n $n_v$n_o $proc1 $proc2 $proc3 $proc4 $proc5 &&
50       fun_nice_val $proc1 $proc2 $proc3 $proc4 $proc5" \
51      "$nice_val1\n$nice_val2\n$nice_val3\n$nice_val4\n$nice_val5\n" "" ""
52
53    nice_val1=$((`fun_nice_val $proc1` + $n_v))
54    nice_val2=$((`fun_nice_val $proc2` + $n_v))
55    nice_val3=$((`fun_nice_val $proc3` + $n_v))
56    nice_val4=$((`fun_nice_val $proc4` + $n_v))
57    nice_val5=$((`fun_nice_val $proc5` + $n_v))
58    testing "with -n=$n_v and with$n_o multiple_pids (some invalid)" \
59      "renice -n $n_v$n_o $proc1 $proc2 88888 99999 $proc3 $proc4 $proc5 $arg ||
60       fun_nice_val $proc1 $proc2 $proc3 $proc4 $proc5" \
61      "$nice_val1\n$nice_val2\n$nice_val3\n$nice_val4\n$nice_val5\n" "" ""
62  done
63done
64
65# Starting Boundary Test Here ..
66loop_cnt=2
67echo -n "TEST: Boundary value test for Id($proc1)..[old_nice_val/new_nice_val]:"
68cnt=0
69n_val=1
70while [ $cnt -gt -1 ]
71do
72  old_nice_val=`fun_nice_val $proc1`
73  new_nice_val=`renice -n $n_val $proc1 >/dev/null 2>&1 && fun_nice_val $proc1`
74  echo -n "[$old_nice_val/$new_nice_val],"
75  if [ $old_nice_val -eq 39 -a $old_nice_val -eq $new_nice_val ]
76  then
77    echo -n " [Equals 39,doing -1] "
78    n_val="-1"
79  elif [ $old_nice_val -eq 0 -a $old_nice_val -eq $new_nice_val ]
80  then
81    echo -n " [Equals 0,doing +1] "
82    n_val="1"
83  elif [ $new_nice_val -gt 39 -o $new_nice_val -lt 0 ]
84  then
85    echo " [Test Fail] "
86    echo "FAIL: renice with step 1 ($proc1) (boundary value)"
87    cnt="-1"
88  elif [ $new_nice_val -eq $n_val1 -a $new_nice_val -eq $(($old_nice_val+1)) ]
89  then
90    cnt=$(($cnt + 1))
91    if [ $cnt -eq $loop_cnt ]
92    then
93      echo " [Test Pass] "
94      echo "PASS: renice with step 1 ($proc1) (boundary value)"
95      cnt="-1"
96    fi
97  else
98    dif=`echo $(($new_nice_val-$old_nice_val))`
99    dif=`echo ${dif/-}`
100    if [ $dif -ne 1 ]
101    then
102      echo " [Test Fail] "
103      echo "FAIL: renice with step 1 ($proc1) (boundary value)"
104      cnt="-1"
105    fi
106  fi
107done
108# Boundary test End
109
110kill -9 $proc1 $proc2 $proc3 $proc4 $proc5
111