From 25d048c02a02f13666712fb0fdbeacd6db4bbff2 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Tue, 27 Dec 2011 20:01:47 +0400 Subject: [PATCH] test: Add usnix-socket test Signed-off-by: Cyrill Gorcunov --- test/Makefile | 1 + test/test-unixsocket.c | 44 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 test/test-unixsocket.c diff --git a/test/Makefile b/test/Makefile index a7ade8b46..22e9bb59e 100644 --- a/test/Makefile +++ b/test/Makefile @@ -5,6 +5,7 @@ SRCS += test-shmem-three-async.c SRCS += test-pipe-async.c SRCS += test-vdso.c SRCS += test-sigaction.c +SRCS += test-unixsocket.c SRCS-TH += test-pthreads.c OBJS-TH += $(patsubst %.c,%.o,$(SRCS-TH)) diff --git a/test/test-unixsocket.c b/test/test-unixsocket.c new file mode 100644 index 000000000..1e01acda3 --- /dev/null +++ b/test/test-unixsocket.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(void) +{ + int sv[2]; + char buf; + int ret; + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == -1) { + perror("socketpair"); + exit(1); + } + + buf = 'a'; + write(sv[0], &buf, 1); + printf("sent '%c'\n", buf); + + while (1) { + /* stream */ + read(sv[1], &buf, 1); + printf("read '%c'\n", buf); + + /* + * checkpoint should be done here, + * we don't support queued data yet. + */ + printf("pause\n"); + sleep(10); + + buf = toupper(buf); + write(sv[0], &buf, 1); + printf("sent '%c'\n", buf); + } + + return 0; +}