[pypy-commit] pypy jumbojet: sched_get min/max
nanjekye
pypy.commits at gmail.com
Tue May 30 07:37:44 EDT 2017
Author: Joannah Nanjekye <nanjekyejoannah at gmail.com>
Branch: jumbojet
Changeset: r91443:d70723533eef
Date: 2017-04-08 21:35 +0300
http://bitbucket.org/pypy/pypy/changeset/d70723533eef/
Log: sched_get min/max
diff --git a/pypy/module/posix/__init__.py b/pypy/module/posix/__init__.py
--- a/pypy/module/posix/__init__.py
+++ b/pypy/module/posix/__init__.py
@@ -229,6 +229,14 @@
'POSIX_FADV_RANDOM', 'POSIX_FADV_NOREUSE', 'POSIX_FADV_DONTNEED']:
assert getattr(rposix, _name) is not None, "missing %r" % (_name,)
interpleveldefs[_name] = 'space.wrap(%d)' % getattr(rposix, _name)
+
+ if hasattr(rposix, 'sched_get_priority_max'):
+ interpleveldefs['sched_get_priority_max'] = 'interp_posix.sched_get_priority_max'
+ interpleveldefs['sched_get_priority_min'] = 'interp_posix.sched_get_priority_min'
+ for _name in ['SCHED_FIFO', 'SCHED_RR', 'SCHED_OTHER',
+ 'SCHED_BATCH']:
+ assert getattr(rposix, _name) is not None, "missing %r" % (_name,)
+ interpleveldefs[_name] = 'space.wrap(%d)' % getattr(rposix, _name)
for _name in ["O_CLOEXEC"]:
if getattr(rposix, _name) is not None:
diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -2418,3 +2418,31 @@
except OSError as e:
wrap_oserror(space, e, eintr_retry=True)
return space.newint(res)
+
+ at unwrap_spec(policy=int)
+def sched_get_priority_max(space, policy):
+ """returns the maximum priority value that
+ can be used with the scheduling algorithm
+ identified by policy
+ """
+ while True:
+ try:
+ s = rposix.sched_get_priority_max(policy)
+ except OSError as e:
+ wrap_oserror(space, e, eintr_retry=True)
+ else:
+ return space.newint(s)
+
+ at unwrap_spec(policy=int)
+def sched_get_priority_min(space, policy):
+ """rreturns the minimum priority value that
+ can be used with the scheduling algorithm
+ identified by policy
+ """
+ while True:
+ try:
+ s = rposix.sched_get_priority_min(policy)
+ except OSError as e:
+ wrap_oserror(space, e, eintr_retry=True)
+ else:
+ return space.newint(s)
\ No newline at end of file
diff --git a/pypy/module/posix/test/test_posix2.py b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -938,6 +938,34 @@
assert os.WIFEXITED(status1)
assert os.WEXITSTATUS(status1) == 0 # else, test failure
+ if hasattr(rposix, 'sched_get_priority_max'):
+ def test_os_sched_get_priority_max(self):
+ import sys
+ posix, os = self.posix, self.os
+ assert posix.sched_get_priority_max(posix.SCHED_FIFO) != -1
+ assert posix.sched_get_priority_max(posix.SCHED_RR) != -1
+ assert posix.sched_get_priority_max(posix.SCHED_OTHER) != -1
+ assert posix.sched_get_priority_max(posix.SCHED_BATCH) != -1
+
+ if hasattr(rposix, 'sched_get_priority_min'):
+ def test_os_sched_get_priority_min(self):
+ import sys
+ posix, os = self.posix, self.os
+ assert posix.sched_get_priority_min(posix.SCHED_FIFO) != -1
+ assert posix.sched_get_priority_min(posix.SCHED_RR) != -1
+ assert posix.sched_get_priority_min(posix.SCHED_OTHER) != -1
+ assert posix.sched_get_priority_min(posix.SCHED_BATCH) != -1
+
+ if hasattr(rposix, 'sched_get_priority_min'):
+ def test_os_sched_priority_max_greater_than_min(self):
+ posix, os = self.posix, self.os
+ policy = posix.SCHED_RR
+ low = posix.sched_get_priority_min(policy)
+ high = posix.sched_get_priority_max(policy)
+ assert isinstance(low, int) == True
+ assert isinstance(high, int) == True
+ assert high > low
+
def test_write_buffer(self):
os = self.posix
fd = os.open(self.path2 + 'test_write_buffer',
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -235,6 +235,7 @@
includes = ['unistd.h', 'sys/types.h', 'sys/wait.h',
'utime.h', 'sys/time.h', 'sys/times.h',
'sys/resource.h',
+ 'sched.h',
'grp.h', 'dirent.h', 'sys/stat.h', 'fcntl.h',
'signal.h', 'sys/utsname.h', _ptyh]
if sys.platform.startswith('linux'):
@@ -261,6 +262,10 @@
POSIX_FADV_RANDOM= rffi_platform.DefinedConstantInteger('POSIX_FADV_RANDOM')
POSIX_FADV_NOREUSE = rffi_platform.DefinedConstantInteger('POSIX_FADV_NOREUSE')
POSIX_FADV_DONTNEED = rffi_platform.DefinedConstantInteger('POSIX_FADV_DONTNEED')
+ SCHED_FIFO = rffi_platform.DefinedConstantInteger('SCHED_FIFO')
+ SCHED_RR = rffi_platform.DefinedConstantInteger('SCHED_RR')
+ SCHED_OTHER = rffi_platform.DefinedConstantInteger('SCHED_OTHER')
+ SCHED_BATCH = rffi_platform.DefinedConstantInteger('SCHED_BATCH')
O_NONBLOCK = rffi_platform.DefinedConstantInteger('O_NONBLOCK')
OFF_T = rffi_platform.SimpleType('off_t')
OFF_T_SIZE = rffi_platform.SizeOf('off_t')
@@ -1804,6 +1809,21 @@
def setpriority(which, who, prio):
handle_posix_error('setpriority', c_setpriority(which, who, prio))
+ c_sched_get_priority_max = external('sched_get_priority_max', [rffi.INT],
+ rffi.INT, save_err=rffi.RFFI_FULL_ERRNO_ZERO)
+ c_sched_get_priority_min = external('sched_get_priority_min', [rffi.INT],
+ rffi.INT, save_err=rffi.RFFI_SAVE_ERRNO)
+
+ @enforceargs(int)
+ def sched_get_priority_max(policy):
+ return handle_posix_error('sched_get_priority_max', c_sched_get_priority_max(policy))
+
+ @enforceargs(int)
+ def sched_get_priority_min(policy):
+ return handle_posix_error('sched_get_priority_min', c_sched_get_priority_min(policy))
+
+
+
#___________________________________________________________________
diff --git a/rpython/rlib/test/test_rposix.py b/rpython/rlib/test/test_rposix.py
--- a/rpython/rlib/test/test_rposix.py
+++ b/rpython/rlib/test/test_rposix.py
@@ -785,3 +785,27 @@
raise
finally:
os.close(fd)
+
+ at rposix_requires('sched_get_priority_max')
+def test_sched_get_priority_max():
+ assert rposix.sched_get_priority_max(rposix.SCHED_FIFO) != -1
+ assert rposix.sched_get_priority_max(rposix.SCHED_RR) != -1
+ assert rposix.sched_get_priority_max(rposix.SCHED_OTHER) != -1
+ assert rposix.sched_get_priority_max(rposix.SCHED_BATCH) != -1
+
+ at rposix_requires('sched_get_priority_min')
+def test_sched_get_priority_min():
+ assert rposix.sched_get_priority_min(rposix.SCHED_FIFO) != -1
+ assert rposix.sched_get_priority_min(rposix.SCHED_RR) != -1
+ assert rposix.sched_get_priority_min(rposix.SCHED_OTHER) != -1
+ assert rposix.sched_get_priority_min(rposix.SCHED_BATCH) != -1
+
+ at rposix_requires('sched_get_priority_min')
+def test_os_sched_priority_max_greater_than_min():
+ policy = rposix.SCHED_RR
+ low = rposix.sched_get_priority_min(policy)
+ high = rposix.sched_get_priority_max(policy)
+ assert isinstance(low, int) == True
+ assert isinstance(high, int) == True
+ assert high > low
+
More information about the pypy-commit
mailing list