Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / misc / nice
1 #! /bin/sh
2 # Test "nice".
3
4 # Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
20
21 # This script takes no arguments.
22
23 if test -n "$DJDIR"; then
24   echo "$0: cannot test nice on DJGPP" >&2
25   exit 77
26 fi
27
28 tests='
29 0 empty 10
30 1 -1 1
31 2 -12 12
32 3 -1:-2 2
33 4 -n:1 1
34 5 -n:1:-2 2
35 6 -n:1:-+12 12
36 7 -2:-n:1 1
37 8 -2:-n:12 12
38 9 -+1 1
39 10 -+12 12
40 11 -+1:-+12 12
41 12 -n:+1 1
42 13 --1:-2 2
43 14 --1:-2:-13 13
44 15 --1:-n:2 2
45 16 --1:-n:2:-3 3
46 17 --1:-n:2:-13 13
47 18 -n:-1:-12 12
48 19 --1:-12 12
49 NA LAST NA
50 '
51 set $tests
52
53 if test "$VERBOSE" = yes; then
54   nice --version
55   set -x
56 fi
57
58 # Require that this test be run at `nice' level 0.
59 niceness=`nice`
60 if test "$niceness" = 0; then
61     : ok
62 else
63   echo "$0: this test must be run at nice level 0" 1>&2
64   exit 77
65 fi
66
67 fail=0
68 while :; do
69   test_name=$1
70   args=$2
71   expected_result=$3
72   test $args = empty && args=''
73   test x$args = xLAST && break
74   args=`echo x$args|tr : ' '|sed 's/^x//'`
75   if test "$VERBOSE" = yes; then
76     #echo "testing \`nice $args nice\` = $expected_result ..."
77     echo "test $test_name... " | tr -d '\n'
78   fi
79   test x`nice $args nice 2> /dev/null` = x$expected_result \
80     && ok=ok || ok=FAIL fail=1
81   test "$VERBOSE" = yes && echo $ok
82   test x`nice $args nice 2> /dev/null` = x$expected_result || fail=1
83   shift; shift; shift
84 done
85
86 exit $fail