libvirt/tests/testutils.h
Daniel P. Berrange ceacc1dd4f 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
2011-06-24 11:48:14 +01:00

60 lines
1.7 KiB
C

/*
* utils.c: test utils
*
* Copyright (C) 2005, 2008-2011 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
* Karel Zak <kzak@redhat.com>
*/
#ifndef __VIT_TEST_UTILS_H__
# define __VIT_TEST_UTILS_H__
# include <stdio.h>
# define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */
# define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken */
extern char *progname;
extern char *abs_srcdir;
double virtTestCountAverage(double *items,
int nitems);
void virtTestResult(const char *name, int ret, const char *msg, ...);
int virtTestRun(const char *title,
int nloops,
int (*body)(const void *data),
const void *data);
int virtTestLoadFile(const char *file, char **buf);
int virtTestCaptureProgramOutput(const char *const argv[], char **buf, int maxlen);
int virtTestClearLineRegex(const char *pattern,
char *string);
int virtTestDifference(FILE *stream,
const char *expect,
const char *actual);
int virtTestDifferenceBin(FILE *stream,
const char *expect,
const char *actual,
size_t length);
unsigned int virTestGetDebug(void);
unsigned int virTestGetVerbose(void);
char *virtTestLogContentAndReset(void);
int virtTestMain(int argc,
char **argv,
int (*func)(void));
/* Setup, then call func() */
# define VIRT_TEST_MAIN(func) \
int main(int argc, char **argv) { \
return virtTestMain(argc, argv, func); \
}
#endif /* __VIT_TEST_UTILS_H__ */