~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to tests/misc/nice.sh

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
# Test "nice".
 
3
 
 
4
# Copyright (C) 2002-2012 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 3 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, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 
20
print_ver_ nice
 
21
 
 
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
 
44
'
 
45
set $tests
 
46
 
 
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"
 
53
fi
 
54
 
 
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'
 
65
  fi
 
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
 
71
 
 
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
  test -s 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
    nice -n -1 nice > out 2> /dev/full
 
83
    test $? = 125 || fail=1
 
84
    test -s out && fail=1
 
85
  fi
 
86
else
 
87
  # superuser - change succeeds
 
88
  nice -n -1 nice 2> err || fail=1
 
89
  test -s err && fail=1
 
90
  test x$(nice -n -1 nice) = x-1 || fail=1
 
91
  test x$(nice --1 nice) = x-1 || fail=1
 
92
fi
 
93
 
 
94
Exit $fail