test: Add usnix-socket test

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This commit is contained in:
Cyrill Gorcunov 2011-12-27 20:01:47 +04:00
parent 843747de55
commit 25d048c02a
2 changed files with 45 additions and 0 deletions

View file

@ -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))

44
test/test-unixsocket.c Normal file
View file

@ -0,0 +1,44 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <sys/un.h>
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;
}