Testing the TCP and UDP transports alike

This commit is contained in:
Pierre Pronchery 2012-10-18 01:56:25 +00:00
parent a6da501b9d
commit 15ebf43c9e
6 changed files with 34 additions and 29 deletions

View File

@ -56,7 +56,7 @@ dist:
$(PACKAGE)-$(VERSION)/src/transport/udp.c \
$(PACKAGE)-$(VERSION)/src/transport/Makefile \
$(PACKAGE)-$(VERSION)/src/transport/project.conf \
$(PACKAGE)-$(VERSION)/tests/udp.c \
$(PACKAGE)-$(VERSION)/tests/transport.c \
$(PACKAGE)-$(VERSION)/tests/Makefile \
$(PACKAGE)-$(VERSION)/tests/tests.sh \
$(PACKAGE)-$(VERSION)/tests/project.conf \

View File

@ -1,2 +1,2 @@
tests.log
udp
transport

View File

@ -1,4 +1,4 @@
TARGETS = tests.log udp
TARGETS = tests.log transport
PREFIX = /usr/local
DESTDIR =
BINDIR = $(PREFIX)/bin
@ -17,21 +17,21 @@ INSTALL ?= install
all: $(TARGETS)
tests.log: udp
tests.log: transport
./tests.sh -P "$(PREFIX)" -- "tests.log"
udp_OBJS = udp.o
udp_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
udp_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
transport_OBJS = transport.o
transport_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
transport_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
udp: $(udp_OBJS)
$(CC) -o udp $(udp_OBJS) $(udp_LDFLAGS)
transport: $(transport_OBJS)
$(CC) -o transport $(transport_OBJS) $(transport_LDFLAGS)
udp.o: udp.c ../src/libApp.a
$(CC) $(udp_CFLAGS) -c udp.c
transport.o: transport.c ../src/libApp.a
$(CC) $(transport_CFLAGS) -c transport.c
clean:
$(RM) -- $(tests.log_OBJS) $(udp_OBJS)
$(RM) -- $(tests.log_OBJS) $(transport_OBJS)
distclean: clean
$(RM) -- $(TARGETS)

View File

@ -1,4 +1,4 @@
targets=tests.log,udp
targets=tests.log,transport
cppflags=-I ../include
cflags_force=-W `pkg-config --cflags libSystem`
cflags=-Wall -g -O2
@ -9,11 +9,11 @@ dist=Makefile,tests.sh
[tests.log]
type=script
script=./tests.sh
depends=udp
depends=transport
[udp]
[transport]
type=binary
sources=udp.c
sources=transport.c
[udp.c]
[transport.c]
depends=../src/libApp.a

View File

@ -45,7 +45,8 @@ target="$1"
> "$target"
FAILED=
./udp >> "$target" || FAILED="$FAILED udp(error $?)"
./transport -p tcp >> "$target" || FAILED="$FAILED tcp(error $?)"
./transport -p udp >> "$target" || FAILED="$FAILED udp(error $?)"
[ -z "$FAILED" ] && exit 0
echo "Failed tests:$FAILED" 1>&2
#XXX ignore errors for now

View File

@ -26,14 +26,14 @@
/* private */
/* prototypes */
static int _udp(char const * name);
static int _transport(char const * protocol, char const * name);
static int _usage(void);
/* functions */
/* udp */
static int _udp(char const * name)
/* transport */
static int _transport(char const * protocol, char const * name)
{
char * cwd;
Plugin * plugin;
@ -44,16 +44,16 @@ static int _udp(char const * name)
/* load the transport plug-in */
if((cwd = getcwd(NULL, 0)) == NULL)
return error_set_print("udp", 2, "%s", strerror(errno));
return error_set_print("transport", 2, "%s", strerror(errno));
/* XXX rather ugly but does the trick */
plugin = plugin_new(cwd, "../src", "transport", "udp");
plugin = plugin_new(cwd, "../src", "transport", protocol);
free(cwd);
if(plugin == NULL)
return error_print("udp");
return error_print("transport");
if((plugind = plugin_lookup(plugin, "transport")) == NULL)
{
plugin_delete(plugin);
return error_print("udp");
return error_print("transport");
}
/* initialize the helper */
memset(&helper, 0, sizeof(helper));
@ -69,7 +69,7 @@ static int _udp(char const * name)
if(server != NULL)
plugind->destroy(server);
plugin_delete(plugin);
return error_print("udp");
return error_print("transport");
}
/* FIXME really implement */
plugind->destroy(client);
@ -83,7 +83,7 @@ static int _udp(char const * name)
/* usage */
static int _usage(void)
{
fputs("Usage: udp name\n", stderr);
fputs("Usage: transport -p protocol name\n", stderr);
return 1;
}
@ -93,12 +93,16 @@ static int _usage(void)
/* main */
int main(int argc, char * argv[])
{
char const * protocol = "udp";
char const * name = "127.0.0.1:4242";
int o;
while((o = getopt(argc, argv, "")) != -1)
while((o = getopt(argc, argv, "p:")) != -1)
switch(o)
{
case 'p':
protocol = optarg;
break;
default:
return _usage();
}
@ -106,5 +110,5 @@ int main(int argc, char * argv[])
name = argv[optind];
else if(optind != argc)
return _usage();
return (_udp(name) == 0) ? 0 : 2;
return (_transport(protocol, name) == 0) ? 0 : 2;
}