Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src New getsockname(2) testcase for UNIX domain sockets.



details:   https://anonhg.NetBSD.org/src/rev/c76f5321de77
branches:  trunk
changeset: 816869:c76f5321de77
user:      njoly <njoly%NetBSD.org@localhost>
date:      Sat Jul 30 11:03:54 2016 +0000

description:
New getsockname(2) testcase for UNIX domain sockets.

diffstat:

 distrib/sets/lists/debug/mi        |   3 +-
 distrib/sets/lists/tests/mi        |   3 +-
 tests/lib/libc/sys/Makefile        |   3 +-
 tests/lib/libc/sys/t_getsockname.c |  82 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 88 insertions(+), 3 deletions(-)

diffs (137 lines):

diff -r b5b997b9d915 -r c76f5321de77 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Sat Jul 30 07:10:42 2016 +0000
+++ b/distrib/sets/lists/debug/mi       Sat Jul 30 11:03:54 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.160 2016/07/02 15:40:51 christos Exp $
+# $NetBSD: mi,v 1.161 2016/07/30 11:03:54 njoly Exp $
 ./etc/mtree/set.debug                           comp-sys-root
 ./usr/lib                                      comp-sys-usr            compatdir
 ./usr/lib/i18n/libBIG5_g.a                     comp-c-debuglib         debuglib,compatfile
@@ -2007,6 +2007,7 @@
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_getpid.debug              tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_getrusage.debug           tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_getsid.debug              tests-lib-debug         debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/lib/libc/sys/t_getsockname.debug         tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_gettimeofday.debug                tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_issetugid.debug           tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_kevent.debug              tests-lib-debug         debug,atf,compattestfile
diff -r b5b997b9d915 -r c76f5321de77 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sat Jul 30 07:10:42 2016 +0000
+++ b/distrib/sets/lists/tests/mi       Sat Jul 30 11:03:54 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.679 2016/07/29 07:02:24 pgoyette Exp $
+# $NetBSD: mi,v 1.680 2016/07/30 11:03:54 njoly Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2682,6 +2682,7 @@
 ./usr/tests/lib/libc/sys/t_getpid              tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libc/sys/t_getrusage           tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libc/sys/t_getsid              tests-lib-tests         compattestfile,atf
+./usr/tests/lib/libc/sys/t_getsockname         tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libc/sys/t_gettimeofday                tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libc/sys/t_issetugid           tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libc/sys/t_kevent              tests-lib-tests         compattestfile,atf
diff -r b5b997b9d915 -r c76f5321de77 tests/lib/libc/sys/Makefile
--- a/tests/lib/libc/sys/Makefile       Sat Jul 30 07:10:42 2016 +0000
+++ b/tests/lib/libc/sys/Makefile       Sat Jul 30 11:03:54 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.42 2016/04/06 00:45:53 christos Exp $
+# $NetBSD: Makefile,v 1.43 2016/07/30 11:03:54 njoly Exp $
 
 MKMAN= no
 
@@ -23,6 +23,7 @@
 TESTS_C+=              t_getpid
 TESTS_C+=              t_getrusage
 TESTS_C+=              t_getsid
+TESTS_C+=              t_getsockname
 TESTS_C+=              t_gettimeofday
 TESTS_C+=              t_issetugid
 TESTS_C+=              t_kevent
diff -r b5b997b9d915 -r c76f5321de77 tests/lib/libc/sys/t_getsockname.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/sys/t_getsockname.c        Sat Jul 30 11:03:54 2016 +0000
@@ -0,0 +1,82 @@
+/*     $NetBSD: t_getsockname.c,v 1.1 2016/07/30 11:03:54 njoly Exp $  */
+/*
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+ATF_TC(getsockname_unix);
+
+ATF_TC_HEAD(getsockname_unix, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Checks getsockname with UNIX domain");
+}
+
+ATF_TC_BODY(getsockname_unix, tc)
+{
+       const char *path = "sock.unix";
+       int sd;
+       socklen_t len;
+       struct sockaddr_un sun;
+
+       sd = socket(AF_UNIX, SOCK_STREAM, 0);
+       ATF_REQUIRE(sd != -1);
+
+       len = sizeof(sun);
+       memset(&sun, 0, sizeof(sun));
+       ATF_REQUIRE(getsockname(sd, (struct sockaddr *)&sun, &len) != -1);
+       ATF_CHECK(sun.sun_family == AF_UNIX);
+       ATF_CHECK(strcmp(sun.sun_path, "") == 0);
+
+       len = sizeof(sun);
+       memset(&sun, 0, sizeof(sun));
+       sun.sun_family = AF_UNIX;
+       strcpy(sun.sun_path, path);
+       ATF_REQUIRE(bind(sd, (struct sockaddr *)&sun, len) != -1);
+
+       len = sizeof(sun);
+       memset(&sun, 0, sizeof(sun));
+       ATF_REQUIRE(getsockname(sd, (struct sockaddr *)&sun, &len) != -1);
+       ATF_CHECK(sun.sun_family == AF_UNIX);
+       ATF_CHECK(strcmp(sun.sun_path, path) == 0);
+
+       ATF_REQUIRE(close(sd) != -1);
+       ATF_REQUIRE(unlink(path) != -1);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, getsockname_unix);
+
+       return atf_no_error();
+}



Home | Main Index | Thread Index | Old Index