Module Name: src Committed By: njoly Date: Sat Jul 30 11:03:54 UTC 2016
Modified Files: src/distrib/sets/lists/debug: mi src/distrib/sets/lists/tests: mi src/tests/lib/libc/sys: Makefile Added Files: src/tests/lib/libc/sys: t_getsockname.c Log Message: New getsockname(2) testcase for UNIX domain sockets. To generate a diff of this commit: cvs rdiff -u -r1.160 -r1.161 src/distrib/sets/lists/debug/mi cvs rdiff -u -r1.679 -r1.680 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.42 -r1.43 src/tests/lib/libc/sys/Makefile cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_getsockname.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/debug/mi diff -u src/distrib/sets/lists/debug/mi:1.160 src/distrib/sets/lists/debug/mi:1.161 --- src/distrib/sets/lists/debug/mi:1.160 Sat Jul 2 15:40:51 2016 +++ src/distrib/sets/lists/debug/mi Sat Jul 30 11:03:54 2016 @@ -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 Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.679 src/distrib/sets/lists/tests/mi:1.680 --- src/distrib/sets/lists/tests/mi:1.679 Fri Jul 29 07:02:24 2016 +++ src/distrib/sets/lists/tests/mi Sat Jul 30 11:03:54 2016 @@ -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 Index: src/tests/lib/libc/sys/Makefile diff -u src/tests/lib/libc/sys/Makefile:1.42 src/tests/lib/libc/sys/Makefile:1.43 --- src/tests/lib/libc/sys/Makefile:1.42 Wed Apr 6 00:45:53 2016 +++ src/tests/lib/libc/sys/Makefile Sat Jul 30 11:03:54 2016 @@ -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_getlogin 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 Added files: Index: src/tests/lib/libc/sys/t_getsockname.c diff -u /dev/null src/tests/lib/libc/sys/t_getsockname.c:1.1 --- /dev/null Sat Jul 30 11:03:55 2016 +++ src/tests/lib/libc/sys/t_getsockname.c Sat Jul 30 11:03:54 2016 @@ -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(); +}