[pypy-svn] r59444 - in pypy/trunk/pypy/lib: . app_test
arigo at codespeak.net
arigo at codespeak.net
Mon Oct 27 13:21:03 CET 2008
Author: arigo
Date: Mon Oct 27 13:21:03 2008
New Revision: 59444
Added:
pypy/trunk/pypy/lib/app_test/test_resource.py (contents, props changed)
Modified:
pypy/trunk/pypy/lib/resource.py
Log:
Test and fixes: use _structseq.
Added: pypy/trunk/pypy/lib/app_test/test_resource.py
==============================================================================
--- (empty file)
+++ pypy/trunk/pypy/lib/app_test/test_resource.py Mon Oct 27 13:21:03 2008
@@ -0,0 +1,27 @@
+from pypy.lib import resource
+
+def test_resource():
+ x = resource.getrusage(resource.RUSAGE_SELF)
+ assert len(x) == 16
+ assert x[0] == x[-16] == x.ru_utime
+ assert x[1] == x[-15] == x.ru_stime
+ assert x[2] == x[-14] == x.ru_maxrss
+ assert x[3] == x[-13] == x.ru_ixrss
+ assert x[4] == x[-12] == x.ru_idrss
+ assert x[5] == x[-11] == x.ru_isrss
+ assert x[6] == x[-10] == x.ru_minflt
+ assert x[7] == x[-9] == x.ru_majflt
+ assert x[8] == x[-8] == x.ru_nswap
+ assert x[9] == x[-7] == x.ru_inblock
+ assert x[10] == x[-6] == x.ru_oublock
+ assert x[11] == x[-5] == x.ru_msgsnd
+ assert x[12] == x[-4] == x.ru_msgrcv
+ assert x[13] == x[-3] == x.ru_nsignals
+ assert x[14] == x[-2] == x.ru_nvcsw
+ assert x[15] == x[-1] == x.ru_nivcsw
+ for i in range(16):
+ if i < 2:
+ expected_type = float
+ else:
+ expected_type = (int, long)
+ assert isinstance(x[i], expected_type)
Modified: pypy/trunk/pypy/lib/resource.py
==============================================================================
--- pypy/trunk/pypy/lib/resource.py (original)
+++ pypy/trunk/pypy/lib/resource.py Mon Oct 27 13:21:03 2008
@@ -5,6 +5,7 @@
from ctypes_configure.configure import (configure,
ExternalCompilationInfo, ConstantInteger, DefinedConstantInteger,
SimpleType)
+import _structseq
_CONSTANTS = (
'RLIM_INFINITY',
@@ -101,23 +102,24 @@
)
class struct_rusage:
- def __init__(self, ru):
- self.ru_utime = float(ru.ru_utime)
- self.ru_stime = float(ru.ru_stime)
- self.ru_maxrss = ru.ru_maxrss
- self.ru_ixrss = ru.ru_ixrss
- self.ru_idrss = ru.ru_idrss
- self.ru_isrss = ru.ru_isrss
- self.ru_minflt = ru.ru_minflt
- self.ru_majflt = ru.ru_majflt
- self.ru_nswap = ru.ru_nswap
- self.ru_inblock = ru.ru_inblock
- self.ru_oublock = ru.ru_oublock
- self.ru_msgsnd = ru.ru_msgsnd
- self.ru_msgrcv = ru.ru_msgrcv
- self.ru_nsignals = ru.ru_nsignals
- self.ru_nvcsw = ru.ru_nvcsw
- self.ru_nivcsw = ru.ru_nivcsw
+ __metaclass__ = _structseq.structseqtype
+
+ ru_utime = _structseq.structseqfield(0)
+ ru_stime = _structseq.structseqfield(1)
+ ru_maxrss = _structseq.structseqfield(2)
+ ru_ixrss = _structseq.structseqfield(3)
+ ru_idrss = _structseq.structseqfield(4)
+ ru_isrss = _structseq.structseqfield(5)
+ ru_minflt = _structseq.structseqfield(6)
+ ru_majflt = _structseq.structseqfield(7)
+ ru_nswap = _structseq.structseqfield(8)
+ ru_inblock = _structseq.structseqfield(9)
+ ru_oublock = _structseq.structseqfield(10)
+ ru_msgsnd = _structseq.structseqfield(11)
+ ru_msgrcv = _structseq.structseqfield(12)
+ ru_nsignals = _structseq.structseqfield(13)
+ ru_nvcsw = _structseq.structseqfield(14)
+ ru_nivcsw = _structseq.structseqfield(15)
class rlimit(Structure):
_fields_ = (
@@ -133,7 +135,24 @@
if errno == EINVAL:
raise ValueError("invalid who parameter")
raise ResourceError(errno)
- return struct_rusage(ru)
+ return struct_rusage((
+ float(ru.ru_utime),
+ float(ru.ru_stime),
+ ru.ru_maxrss,
+ ru.ru_ixrss,
+ ru.ru_idrss,
+ ru.ru_isrss,
+ ru.ru_minflt,
+ ru.ru_majflt,
+ ru.ru_nswap,
+ ru.ru_inblock,
+ ru.ru_oublock,
+ ru.ru_msgsnd,
+ ru.ru_msgrcv,
+ ru.ru_nsignals,
+ ru.ru_nvcsw,
+ ru.ru_nivcsw,
+ ))
def getrlimit(resource):
if not(0 <= resource < RLIM_NLIMITS):
More information about the Pypy-commit
mailing list