summaryrefslogtreecommitdiff
path: root/lib/zephyr_tests.py
diff options
context:
space:
mode:
authorGravatar Mark W. Eichin <eichin@thok.org>2009-04-07 05:24:16 +0000
committerGravatar Mark W. Eichin <eichin@thok.org>2009-04-07 05:24:16 +0000
commitba8815ccb99342da7d4464024575280bfd5b148a (patch)
tree3d365d5d4c18a29e1277aaf868f72d224b284c93 /lib/zephyr_tests.py
parente8d282aaea77c41891aea7eb0f0dc6a0bf2b7163 (diff)
generic pretty-printer for ctypes Structures and Unions
use it to display fields of interest for testing fix the immediately exposed bug (tv_sec/tv_usec sign)
Diffstat (limited to 'lib/zephyr_tests.py')
-rwxr-xr-xlib/zephyr_tests.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/zephyr_tests.py b/lib/zephyr_tests.py
index 3a4352e..1cc5728 100755
--- a/lib/zephyr_tests.py
+++ b/lib/zephyr_tests.py
@@ -20,6 +20,19 @@ from ctypes import Structure, Union, sizeof
__revision__ = "$Id$"
__version__ = "%s/%s" % (__revision__.split()[3], __revision__.split()[2])
+def ctypes_pprint(cstruct, indent=""):
+ """pretty print a ctypes Structure or Union"""
+ for field_name, field_ctype in cstruct._fields_:
+ field_value = getattr(cstruct, field_name)
+ print indent + field_name,
+ if hasattr(field_value, "_fields_"):
+ print
+ ctypes_pprint(field_value, indent + " ")
+ else:
+ # TODO: add other displays based on field_ctype
+ print field_value
+
+
# TODO: pick some real framework later, we're just poking around for now
class TestSuite(object):
"""test collection and runner"""
@@ -85,9 +98,9 @@ ZNOAUTH = 0
class _ZTimeval(Structure):
_fields_ = [
# int tv_sec;
- ("tv_sec", c_int),
+ ("tv_sec", c_uint),
# int tv_usec;
- ("tv_usec", c_int),
+ ("tv_usec", c_uint),
# };
]
@@ -305,6 +318,7 @@ class ZephyrTestSuite(TestSuite):
st = self._libzephyr.ZParseNotice(zbuf, zbuflen, new_notice)
print "ZParseNotice:", "retval", st
print "\tz_version", new_notice.z_version
+ ctypes_pprint(new_notice)
if __name__ == "__main__":
parser = optparse.OptionParser(usage=__doc__,