aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2010-12-06 17:03:22 +0000
committerDaniel P. Berrange <berrange@redhat.com>2011-06-24 11:48:14 +0100
commitceacc1dd4f73c87bc2521bd35dec97a3c4866e78 (patch)
tree8bf6db6f67dc96bf7a295d5ce9655b4a9e5a9467 /tests/testutils.c
parentDefines the basics of a generic RPC protocol in XDR (diff)
downloadlibvirt-ceacc1dd4f73c87bc2521bd35dec97a3c4866e78.tar.gz
libvirt-ceacc1dd4f73c87bc2521bd35dec97a3c4866e78.tar.bz2
libvirt-ceacc1dd4f73c87bc2521bd35dec97a3c4866e78.zip
Provide a simple object for encoding/decoding RPC messages
This provides a new struct that contains a buffer for the RPC message header+payload, as well as a decoded copy of the message header. There is an API for applying a XDR encoding & decoding of the message headers and payloads. There are also APIs for maintaining a simple FIFO queue of message instances. Expected usage scenarios are: To send a message msg = virNetMessageNew() ...fill in msg->header fields.. virNetMessageEncodeHeader(msg) ...loook at msg->header fields to determine payload filter virNetMessageEncodePayload(msg, xdrfilter, data) ...send msg->bufferLength worth of data from buffer To receive a message msg = virNetMessageNew() ...read VIR_NET_MESSAGE_LEN_MAX of data into buffer virNetMessageDecodeLength(msg) ...read msg->bufferLength-msg->bufferOffset of data into buffer virNetMessageDecodeHeader(msg) ...look at msg->header fields to determine payload filter virNetMessageDecodePayload(msg, xdrfilter, data) ...run payload processor * src/Makefile.am: Add to libvirt-net-rpc.la * src/rpc/virnetmessage.c, src/rpc/virnetmessage.h: Internal message handling API. * testutils.c, testutils.h: Helper for printing binary differences * virnetmessagetest.c: Validate all XDR encoding/decoding
Diffstat (limited to 'tests/testutils.c')
-rw-r--r--tests/testutils.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/testutils.c b/tests/testutils.c
index bc896906f..2405d3d8c 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -370,6 +370,70 @@ int virtTestDifference(FILE *stream,
return 0;
}
+/**
+ * @param stream: output stream write to differences to
+ * @param expect: expected output text
+ * @param actual: actual output text
+ *
+ * Display expected and actual output text, trimmed to
+ * first and last characters at which differences occur
+ */
+int virtTestDifferenceBin(FILE *stream,
+ const char *expect,
+ const char *actual,
+ size_t length)
+{
+ size_t start = 0, end = length;
+ ssize_t i;
+
+ if (!virTestGetDebug())
+ return 0;
+
+ if (virTestGetDebug() < 2) {
+ /* Skip to first character where they differ */
+ for (i = 0 ; i < length ; i++) {
+ if (expect[i] != actual[i]) {
+ start = i;
+ break;
+ }
+ }
+
+ /* Work backwards to last character where they differ */
+ for (i = (length -1) ; i >= 0 ; i--) {
+ if (expect[i] != actual[i]) {
+ end = i;
+ break;
+ }
+ }
+ }
+ /* Round to nearest boundary of 4, except that last world can be short */
+ start -= (start % 4);
+ end += 4 - (end % 4);
+ if (end >= length)
+ end = length - 1;
+
+ /* Show the trimmed differences */
+ fprintf(stream, "\nExpect [ Region %d-%d", (int)start, (int)end);
+ for (i = start; i < end ; i++) {
+ if ((i % 4) == 0)
+ fprintf(stream, "\n ");
+ fprintf(stream, "0x%02x, ", ((int)expect[i])&0xff);
+ }
+ fprintf(stream, "]\n");
+ fprintf(stream, "Actual [ Region %d-%d", (int)start, (int)end);
+ for (i = start; i < end ; i++) {
+ if ((i % 4) == 0)
+ fprintf(stream, "\n ");
+ fprintf(stream, "0x%02x, ", ((int)actual[i])&0xff);
+ }
+ fprintf(stream, "]\n");
+
+ /* Pad to line up with test name ... in virTestRun */
+ fprintf(stream, " ... ");
+
+ return 0;
+}
+
#if TEST_OOM
static void
virtTestErrorFuncQuiet(void *data ATTRIBUTE_UNUSED,