maint: update all copyright year number ranges
[coreutils.git] / tests / misc / nice.sh
blob9cb74a0d688315b307470dfe6e8f0c3d3b724186
1 #!/bin/sh
2 # Test "nice".
4 # Copyright (C) 2002-2017 Free Software Foundation, Inc.
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 3 of the License, or
9 # (at your option) any later version.
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.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ nice
22 tests='
23 0 empty 10
24 1 -1 1
25 2 -12 12
26 3 -1:-2 2
27 4 -n:1 1
28 5 -n:1:-2 2
29 6 -n:1:-+12 12
30 7 -2:-n:1 1
31 8 -2:-n:12 12
32 9 -+1 1
33 10 -+12 12
34 11 -+1:-+12 12
35 12 -n:+1 1
36 13 --1:-2 2
37 14 --1:-2:-13 13
38 15 --1:-n:2 2
39 16 --1:-n:2:-3 3
40 17 --1:-n:2:-13 13
41 18 -n:-1:-12 12
42 19 --1:-12 12
43 NA LAST NA
45 set $tests
47 # Require that this test be run at 'nice' level 0.
48 niceness=$(nice)
49 if test "$niceness" = 0; then
50 : ok
51 else
52 skip_ "this test must be run at nice level 0"
55 while :; do
56 test_name=$1
57 args=$2
58 expected_result=$3
59 test $args = empty && args=''
60 test x$args = xLAST && break
61 args=$(echo x$args|tr : ' '|sed 's/^x//')
62 if test "$VERBOSE" = yes; then
63 #echo "testing \$(nice $args nice\) = $expected_result ..."
64 echo "test $test_name... " | tr -d '\n'
66 test x$(nice $args nice 2> /dev/null) = x$expected_result \
67 && ok=ok || ok=FAIL fail=1
68 test "$VERBOSE" = yes && echo $ok
69 shift; shift; shift
70 done
72 # Test negative niceness - command must be run whether or not change happens.
73 if test x$(nice -n -1 nice 2> /dev/null) = x0 ; then
74 # unprivileged user - warn about failure to change
75 nice -n -1 true 2> err || fail=1
76 compare /dev/null err && fail=1
77 mv err exp || framework_failure_
78 nice --1 true 2> err || fail=1
79 compare exp err || fail=1
80 # Failure to write advisory message is fatal. Buggy through coreutils 8.0.
81 if test -w /dev/full && test -c /dev/full; then
82 returns_ 125 nice -n -1 nice > out 2> /dev/full || fail=1
83 compare /dev/null out || fail=1
85 else
86 # superuser - change succeeds
87 nice -n -1 nice 2> err || fail=1
88 compare /dev/null err || fail=1
89 test x$(nice -n -1 nice) = x-1 || fail=1
90 test x$(nice --1 nice) = x-1 || fail=1
93 Exit $fail