diff options
author | Karl Ramm <kcr@1ts.org> | 2009-04-27 14:57:49 +0000 |
---|---|---|
committer | Karl Ramm <kcr@1ts.org> | 2009-04-27 14:57:49 +0000 |
commit | 255977c221eb20577ca9df6090fea2d10a117426 (patch) | |
tree | 88f0296b0083c1007536062798cd1201a45e3291 /lib/zephyr_tests.txt | |
parent | a63a88619864c9236e595fb70cd3b880e4c51de4 (diff) |
Set up a local UDP socket to drive testing
Using socketpair doesn't work because you end up with an AF_UNIX socket,
and it even if you _can_ use sendto with anonymous unix-domain sockets
(which the documentation is mute on and it doesn't seem worth experimenting
on), the zephyr library doesn't allocate enough storage for a sockaddr_un,
and although I'm not above fixing that, I determined that for structural
reasons it's too annoying right now. (But once we have a test suite...)
Anyway, cons up a udp socket, and extract a port number from the library,
and use the python socket interface to send the zephyr packet.
Diffstat (limited to 'lib/zephyr_tests.txt')
-rw-r--r-- | lib/zephyr_tests.txt | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/zephyr_tests.txt b/lib/zephyr_tests.txt index b9d2a03..6b3e0c6 100644 --- a/lib/zephyr_tests.txt +++ b/lib/zephyr_tests.txt @@ -250,23 +250,23 @@ tests". In the meantime, a faster and more local test that synthesizes packets and feeds them through the queuing mechanism will get us some more coverage. - >>> from socket import AF_UNIX, SOCK_DGRAM, socketpair - >>> read_end_sock, write_end_sock = socketpair(AF_UNIX, SOCK_DGRAM) - >>> read_end = read_end_sock.fileno() - >>> write_end = write_end_sock.fileno() - >>> assert _z.ZSetFD(read_end) == 0 + >>> from socket import SOCK_DGRAM, socket, ntohs + >>> port = c_ushort(0) + >>> st = _z.ZOpenPort(port) + >>> port = ntohs(port.value) + >>> assert port + >>> sock = socket(AF_INET, SOCK_DGRAM) + >>> assert sock >>> assert _z.ZPending() == 0 TODO: cook up test-specific notices, but for now we've got some lying around from above... >>> zwhole = string_at(zbuf, size=zbuflen) - >>> wrote = os.write(write_end, zwhole) + >>> wrote = sock.sendto(zwhole, ('127.0.0.1', port)) >>> assert wrote == zbuflen.value, "%s != %s" % (wrote, zbuflen.value) >>> zcount = _z.ZPending() - -zcount ends up being -1, because recvfrom gives 'Socket operation on -non-socket' (ENOTSOCK). Instead we need to actually create a local socket... + >>> assert zcount == 1 Coverage: |