pubsubd: test programs
parent
0d50185b3a
commit
368e54d4cf
|
@ -0,0 +1,48 @@
|
||||||
|
#include "../lib/pubsubd.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define MESSAGE "coucou"
|
||||||
|
#define CHAN "chan1"
|
||||||
|
|
||||||
|
void
|
||||||
|
ohshit(int rvalue, const char* str) {
|
||||||
|
fprintf (stderr, "\033[31merr: %s\033[00m\n", str);
|
||||||
|
exit (rvalue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void usage (char **argv)
|
||||||
|
{
|
||||||
|
printf ( "usage: %s\n", argv[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
if (argc != 1) {
|
||||||
|
usage (argv);
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct pubsub_msg msg;
|
||||||
|
memset (&msg, 0, sizeof (struct pubsub_msg));
|
||||||
|
msg.type = PUBSUB_TYPE_MESSAGE;
|
||||||
|
msg.chan = malloc (strlen (CHAN) + 1);
|
||||||
|
strncpy ((char *)msg.chan, CHAN, strlen (CHAN) + 1);
|
||||||
|
msg.chanlen = strlen (CHAN) + 1;
|
||||||
|
|
||||||
|
msg.data = malloc (strlen (MESSAGE) + 1);
|
||||||
|
strncpy ((char *)msg.data, MESSAGE, strlen (CHAN) + 1);
|
||||||
|
msg.datalen = strlen (MESSAGE) + 1;
|
||||||
|
|
||||||
|
char *data = NULL;
|
||||||
|
size_t len = 0;
|
||||||
|
pubsubd_msg_serialize (&msg, &data, &len);
|
||||||
|
pubsubd_msg_free (&msg);
|
||||||
|
|
||||||
|
if (len != write (1, data, len)) {
|
||||||
|
ohshit (1, "unable to write the data");
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
#include "../lib/pubsubd.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
ohshit(int rvalue, const char* str) {
|
||||||
|
fprintf (stderr, "\033[31merr: %s\033[00m\n", str);
|
||||||
|
exit (rvalue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void usage (char **argv)
|
||||||
|
{
|
||||||
|
printf ( "usage: cat msg | %s\n", argv[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void msg_print (struct pubsub_msg *msg) {
|
||||||
|
printf ("msg: type=%d chan=%.*s, data=%.*s\n"
|
||||||
|
, msg->type
|
||||||
|
, msg->chanlen, msg->chan
|
||||||
|
, msg->datalen, msg->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (argc != 1) {
|
||||||
|
usage (argv);
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
char data[BUFSIZ];
|
||||||
|
memset (data, 0, BUFSIZ);
|
||||||
|
size_t len = read (0, data, BUFSIZ);
|
||||||
|
printf ("msg len %ld\n", len);
|
||||||
|
|
||||||
|
struct pubsub_msg msg;
|
||||||
|
pubsubd_msg_unserialize (&msg, data, len);
|
||||||
|
msg_print (&msg);
|
||||||
|
pubsubd_msg_free (&msg);
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# start pubsub-test-send alone, with some parameters
|
||||||
|
# then test it with this script
|
||||||
|
|
||||||
|
REP=/tmp/ipc/
|
||||||
|
PID=10
|
||||||
|
INDEX=1
|
||||||
|
VERSION=1
|
||||||
|
ACTION="pub"
|
||||||
|
CHAN="chan1"
|
||||||
|
|
||||||
|
if [ $# != 0 ] ; then
|
||||||
|
PID=$1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $# != 0 ] ; then
|
||||||
|
INDEX=$1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $# != 0 ] ; then
|
||||||
|
ACTION=$1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $# != 0 ] ; then
|
||||||
|
CHAN=$1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "there should be a line in $REP/pubsub"
|
||||||
|
cat $REP/pubsub
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "there should be something to read in $REP/${PID}-${INDEX}-out"
|
||||||
|
cat $REP/${PID}-${INDEX}-out | xxd
|
Reference in New Issue