Subject: | getpriority.t and setpriority.t assume priority = 0 |
Hello,
getpriority.t and setpriority.t assume the default priority = 0, which
may or may not hold. (For example, many build systems use nice(1) for
their batch jobs; so I've got test suite failures when trying to rebuild
my perl-BSD-Resource rpm package).
The idea is that you can use nice(1) output to find out current priority
before running tests. Please see the attached patch. Now "make test",
"nice make test", and even "nice nice make test" work fine for me.
(System that do not have /bin/nice will simply got it 0, so it's not
gonna be a problem.)
--
Alexey Tourbin
ALT Linux Team
--- BSD-Resource-1.24/t/getpriority.t~ 1997-04-08 10:54:17 +0400
+++ BSD-Resource-1.24/t/getpriority.t 2005-06-07 03:49:35 +0400
@@ -11,7 +11,7 @@
print "1..3\n";
# AIX without BSD libs has 0..39 priorities, not -20..20.
-$okpriopat = $Config{'osname'} eq 'aix' ? '0|19' : '0';
+$okpriopat = $Config{'osname'} eq 'aix' ? '0|19' : `nice` + 0;
$okpriopat = "^($okpriopat)";
--- BSD-Resource-1.24/t/setpriority.t~ 1997-04-08 10:55:29 +0400
+++ BSD-Resource-1.24/t/setpriority.t 2005-06-07 04:03:58 +0400
@@ -8,40 +8,38 @@
print "1..3\n";
-$gotlower = setpriority(PRIO_PROCESS, 0, 5);
+$nice = getpriority(PRIO_PROCESS, 0);
+print "# nice = $nice\n" if ($debug);
-print "# gotlower = $gotlower\n" if ($debug);
-
-# we must use getpriority() to find out whether setpriority() really worked
-
-$lowerprio = getpriority(PRIO_PROCESS, 0);
-
-print "# lowerprio = $lowerprio\n" if ($debug);
-
-$fail = (not $gotlower or not $lowerprio == 5);
-
-print 'not '
- if ($fail);
+if ($nice < 15) { # only works if nice is not exhausted
+ $gotlower = setpriority(PRIO_PROCESS, 0, $nice + 5);
+ print "# gotlower = $gotlower\n" if ($debug);
+ $lowerprio = getpriority(PRIO_PROCESS, 0);
+ print "# lowerprio = $lowerprio\n" if ($debug);
+ $fail = (not $gotlower or not $lowerprio == $nice + 5);
+ print 'not '
+ if ($fail);
+} else {
+ $lowerprio = $nice;
+ $fail = 0;
+}
print "ok 1\n";
if ($fail) {
print "# syserr = '$!' (",$!+0,"), ruid = $<, euid = $>\n";
print "# gotlower = $gotlower, lowerprio = $lowerprio\n";
}
-$gotlower = setpriority();
-
-print "# gotlower = $gotlower\n" if ($debug);
-
-# we must use getpriority() to find out whether setpriority() really worked
-
-$lowerprio = getpriority();
-
-print "# lowerprio = $lowerprio\n" if ($debug);
-
-$fail = (not $gotlower or not $lowerprio == 10);
-
-print 'not '
- if ($fail);
+if ($lowerprio < 10) { # only works if lowerprio is not exhausted
+ $gotlower = setpriority();
+ print "# gotlower = $gotlower\n" if ($debug);
+ $lowerprio = getpriority();
+ print "# lowerprio = $lowerprio\n" if ($debug);
+ $fail = (not $gotlower or not $lowerprio == 10);
+ print 'not '
+ if ($fail);
+} else {
+ $fail = 0;
+}
print "ok 2\n";
if ($fail) {
print "# syserr = '$!' (",$!+0,"), ruid = $<, euid = $>\n";