summaryrefslogtreecommitdiff
path: root/lib/zephyr_tests.py
diff options
context:
space:
mode:
authorGravatar Mark W. Eichin <eichin@thok.org>2009-04-07 06:50:33 +0000
committerGravatar Mark W. Eichin <eichin@thok.org>2009-04-07 06:50:33 +0000
commit0e4482af0042da208008eb570cd1881a100efae3 (patch)
treedc11a68aa1daed957e5e11fcc7a734d46238fd0a /lib/zephyr_tests.py
parentba8815ccb99342da7d4464024575280bfd5b148a (diff)
add type-specific pretty-printers (yay classes)
the mess around _ZTimeval.pprint is that either they're not getting initialized, not getting converted properly, or aren't really timestamps anymore.
Diffstat (limited to 'lib/zephyr_tests.py')
-rwxr-xr-xlib/zephyr_tests.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/zephyr_tests.py b/lib/zephyr_tests.py
index 1cc5728..8727642 100755
--- a/lib/zephyr_tests.py
+++ b/lib/zephyr_tests.py
@@ -10,8 +10,11 @@
import optparse
import os
+import socket
+import struct
import ctypes
import ctypes.util
+import time
from ctypes import c_int, c_uint, c_ushort, c_char, c_ubyte
from ctypes import c_uint16, c_uint32
from ctypes import POINTER, c_void_p, c_char_p
@@ -25,11 +28,12 @@ def ctypes_pprint(cstruct, indent=""):
for field_name, field_ctype in cstruct._fields_:
field_value = getattr(cstruct, field_name)
print indent + field_name,
- if hasattr(field_value, "_fields_"):
+ if hasattr(field_value, "pprint"):
+ print field_value.pprint()
+ elif hasattr(field_value, "_fields_"):
print
ctypes_pprint(field_value, indent + " ")
else:
- # TODO: add other displays based on field_ctype
print field_value
@@ -48,6 +52,8 @@ class in_addr(Structure):
_fields_ = [
("s_addr", c_uint32),
]
+ def pprint(self):
+ return socket.inet_ntoa(struct.pack("<I", self.s_addr))
class _U_in6_u(Union):
_fields_ = [
@@ -103,6 +109,15 @@ class _ZTimeval(Structure):
("tv_usec", c_uint),
# };
]
+ def pprint(self):
+ try:
+ timestr = time.ctime(self.tv_sec)
+ except ValueError:
+ timestr = "invalid unix time"
+ if self.tv_usec >= 1000000:
+ # invalid usec, still treat as numbers
+ return "%dsec, %dusec (%s)" % (self.tv_sec, self.tv_usec, timestr)
+ return "%d.%06dsec (%s)" % (self.tv_sec, self.tv_usec, timestr)
# typedef struct _ZUnique_Id_t {
class ZUnique_Id_t(Structure):