From 358e368fb84623be20ffbac8bfe527543694b4f9 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sun, 18 Jan 2004 12:39:58 +0000 Subject: [PATCH] Add test programs for the new caps system calls. Temporarily disable the old caps junk in libcaps (it needs to be retargeted to the new system calls). Note: performance is not expected to be very good at the moment. --- lib/libcaps/Makefile | 6 ++++-- test/caps/Makefile | 16 ++++++++++++---- test/caps/client.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ test/caps/server.c | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 test/caps/client.c create mode 100644 test/caps/server.c diff --git a/lib/libcaps/Makefile b/lib/libcaps/Makefile index cdaf88912b..a7e4eb4d8f 100644 --- a/lib/libcaps/Makefile +++ b/lib/libcaps/Makefile @@ -1,4 +1,4 @@ -# $DragonFly: src/lib/libcaps/Makefile,v 1.3 2003/12/07 04:21:52 dillon Exp $ +# $DragonFly: src/lib/libcaps/Makefile,v 1.4 2004/01/18 12:39:58 dillon Exp $ # LIB=caps SHLIB_MAJOR= 1 @@ -12,7 +12,9 @@ INSTALL_PIC_ARCHIVE= yes MISRCS= lwkt_msgport.c lwkt_thread.c \ uthread.c init.c sysport.c slaballoc.c \ - globaldata.c caps_client.c caps_misc.c caps_service.c + globaldata.c + +# caps_client.c caps_service.c caps_misc.c SRCS+= ${.OBJDIR}/asdefs.h CLEANFILES+=asdefs asdefs.o ${.CURDIR}/asdefs.h diff --git a/test/caps/Makefile b/test/caps/Makefile index ce82d2cdc2..0c85d11399 100644 --- a/test/caps/Makefile +++ b/test/caps/Makefile @@ -1,14 +1,14 @@ -# $DragonFly: src/test/caps/Makefile,v 1.2 2003/12/07 04:26:41 dillon Exp $ +# $DragonFly: src/test/caps/Makefile,v 1.3 2004/01/18 12:39:56 dillon Exp $ # -TARGETS=/tmp/caps1 /tmp/thr1 /tmp/thr2 /tmp/thr3 +TARGETS=/tmp/thr1 /tmp/thr2 /tmp/thr3 /tmp/caps_s /tmp/caps_c CFLAGS= -O2 -g -I/usr/src/lib -I/usr/src/lib/libcaps/${MACHINE_ARCH} -DSMP all: $(TARGETS) -/tmp/caps1: caps1.c - $(CC) $(CFLAGS) caps1.c -lcaps -o /tmp/caps1 +#/tmp/caps1: caps1.c +# $(CC) $(CFLAGS) caps1.c -lcaps -o /tmp/caps1 /tmp/thr1: thr1.c $(CC) $(CFLAGS) thr1.c -lcaps -o /tmp/thr1 @@ -19,3 +19,11 @@ all: $(TARGETS) /tmp/thr3: thr3.c $(CC) $(CFLAGS) thr3.c -lcaps -o /tmp/thr3 +/tmp/caps_s: server.c + $(CC) $(CFLAGS) -DDEBUG server.c -o /tmp/caps_s + +/tmp/caps_c: client.c + $(CC) $(CFLAGS) -DDEBUG client.c -o /tmp/caps_c + +clean: + rm -f $(TARGETS) diff --git a/test/caps/client.c b/test/caps/client.c new file mode 100644 index 0000000000..c8768357f1 --- /dev/null +++ b/test/caps/client.c @@ -0,0 +1,44 @@ +/* + * $DragonFly: src/test/caps/client.c,v 1.1 2004/01/18 12:39:56 dillon Exp $ + */ +#include +#include +#include +#include +#include +#include +#include +#include + +int +main(int ac, char **av) +{ + int cid; + int n; + int count = 0; + char buf[256]; + struct caps_msgid msgid; + off_t msgcid; + + cid = caps_sys_client("test", getuid(), getgid(), 0, CAPF_ANYCLIENT); + printf("cid = %d %d\n", cid, errno); + if (cid < 0) + return(0); + for (;;) { + msgcid = caps_sys_put(cid, "xyz", 3); +#ifdef DEBUG + printf("msgcid = %016llx %d\n", msgcid, errno); +#endif + n = caps_sys_wait(cid, buf, sizeof(buf), &msgid, NULL); +#ifdef DEBUG + printf("n = %d msgid=%016llx state=%d errno=%d\n", n, msgid.c_id, msgid.c_state, errno); + if (n > 0) + printf("REPLY: %*.*s\n", n, n, buf); +#endif + ++count; + if ((count & 65535) == 0) + printf("%d\n", count); + } + return(0); +} + diff --git a/test/caps/server.c b/test/caps/server.c new file mode 100644 index 0000000000..9c95396160 --- /dev/null +++ b/test/caps/server.c @@ -0,0 +1,40 @@ +/* + * $DragonFly: src/test/caps/server.c,v 1.1 2004/01/18 12:39:56 dillon Exp $ + */ +#include +#include +#include +#include +#include +#include +#include +#include + +int +main(int ac, char **av) +{ + int cid; + int n; + char buf[256]; + struct caps_msgid msgid; + + cid = caps_sys_service("test", getuid(), getgid(), 0, CAPF_ANYCLIENT); + printf("cid = %d\n", cid); + if (cid < 0) + return(0); + bzero(&msgid, sizeof(msgid)); + for (;;) { + n = caps_sys_wait(cid, buf, sizeof(buf), &msgid, NULL); +#ifdef DEBUG + printf("n = %d msgid=%016llx state=%d errno=%d\n", n, msgid.c_id, msgid.c_state, errno); + if (n > 0) + printf("BUFFER: %*.*s\n", n, n, buf); +#endif + n = caps_sys_reply(cid, "good", 4, msgid.c_id); +#ifdef DEBUG + printf("reply: n = %d\n", n); +#endif + } + return(0); +} + -- 2.41.0