OSDN Git Service

test/inet: Add tst-sock-nonblock
authorKevin Cernekee <cernekee@gmail.com>
Sat, 7 Apr 2012 20:31:30 +0000 (13:31 -0700)
committerMike Frysinger <vapier@gentoo.org>
Sun, 8 Apr 2012 21:00:57 +0000 (17:00 -0400)
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
test/.gitignore
test/inet/tst-sock-nonblock.c [new file with mode: 0644]

index 4abedb1..2b03543 100644 (file)
@@ -47,6 +47,7 @@ inet/tst-ethers
 inet/tst-ethers-line
 inet/tst-network
 inet/tst-ntoa
+inet/tst-sock-nonblock
 inet/gethostid
 inet/getnetent
 librt/shmtest
diff --git a/test/inet/tst-sock-nonblock.c b/test/inet/tst-sock-nonblock.c
new file mode 100644 (file)
index 0000000..54a7ee2
--- /dev/null
@@ -0,0 +1,53 @@
+/* vi: set sw=4 ts=4 sts=4: */
+/*
+ * Nonblocking socket test for uClibc
+ * Copyright (C) 2012 by Kevin Cernekee <cernekee@gmail.com>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <error.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/fcntl.h>
+
+static int
+do_test(void)
+{
+       int fd, ret, result = 0;
+       struct sockaddr_un sa;
+       char buf;
+
+       fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0);
+       if (fd < 0) {
+               perror("socket()");
+               result = 1;
+       }
+
+       memset(&sa, 0, sizeof(sa));
+       sa.sun_family = AF_UNIX;
+       strcpy(sa.sun_path, "socktest");
+       unlink("socktest");
+       if (bind(fd, (const struct sockaddr *)&sa, sizeof(sa)) < 0) {
+               perror("bind()");
+               result = 1;
+       }
+
+       ret = read(fd, &buf, sizeof(buf));
+       if (ret != -1 || errno != EAGAIN) {
+               error(0, 0, "Nonblocking read returned %d", ret);
+               result = 1;
+       }
+
+       return result;
+}
+
+#define TIMEOUT 5
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"