New getsockname(2) testcase for UNIX domain sockets.

This commit is contained in:
njoly 2016-07-30 11:03:54 +00:00
parent 2cf0afbf6c
commit d3e4dbe2f3
4 changed files with 88 additions and 3 deletions

View File

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

View File

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

View File

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

View File

@ -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();
}