From f6944967ac9ec5d1014a8e004e5d567f595668f4 Mon Sep 17 00:00:00 2001 From: Kevin Cernekee Date: Sat, 7 Apr 2012 13:31:30 -0700 Subject: test/inet: Add tst-sock-nonblock Signed-off-by: Kevin Cernekee Signed-off-by: Mike Frysinger --- test/.gitignore | 1 + test/inet/tst-sock-nonblock.c | 53 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 test/inet/tst-sock-nonblock.c (limited to 'test') diff --git a/test/.gitignore b/test/.gitignore index 4abedb1c3..2b035431e 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -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 index 000000000..54a7ee28a --- /dev/null +++ b/test/inet/tst-sock-nonblock.c @@ -0,0 +1,53 @@ +/* vi: set sw=4 ts=4 sts=4: */ +/* + * Nonblocking socket test for uClibc + * Copyright (C) 2012 by Kevin Cernekee + * + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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" -- cgit v1.2.3