aboutsummaryrefslogtreecommitdiff
path: root/scripts/test/renice.test
diff options
context:
space:
mode:
authorDivya Kothari <divya.s.kothari@gmail.com>2014-06-26 07:25:20 -0500
committerDivya Kothari <divya.s.kothari@gmail.com>2014-06-26 07:25:20 -0500
commita0f56beaf63052179c69fb258478f851ef1e5ca2 (patch)
treed744c3b80dff1dce2632852eb813ea24ca0508bb /scripts/test/renice.test
parent6d15f0d33fbc422689f92fbbf4dc65d3ab1fb970 (diff)
downloadtoybox-a0f56beaf63052179c69fb258478f851ef1e5ca2.tar.gz
I have developed few testsuite for toybox commands - ls, ln, rm, mv, printf, dd, renice.
Diffstat (limited to 'scripts/test/renice.test')
-rw-r--r--scripts/test/renice.test110
1 files changed, 110 insertions, 0 deletions
diff --git a/scripts/test/renice.test b/scripts/test/renice.test
new file mode 100644
index 00000000..e87111cc
--- /dev/null
+++ b/scripts/test/renice.test
@@ -0,0 +1,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