Module Name: src Committed By: jruoho Date: Thu Jul 7 05:50:27 UTC 2011
Modified Files: src/distrib/sets/lists/tests: mi src/tests/include/sys: Makefile src/tests/syscall: Makefile Added Files: src/tests/include/sys: t_socket.c Removed Files: src/tests/syscall: t_cmsg.c Log Message: Move the 'syscall/t_cmsg' test to 'include/sys/t_socket'. To generate a diff of this commit: cvs rdiff -u -r1.363 -r1.364 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.4 -r1.5 src/tests/include/sys/Makefile cvs rdiff -u -r0 -r1.1 src/tests/include/sys/t_socket.c cvs rdiff -u -r1.40 -r1.41 src/tests/syscall/Makefile cvs rdiff -u -r1.16 -r0 src/tests/syscall/t_cmsg.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/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.363 src/distrib/sets/lists/tests/mi:1.364 --- src/distrib/sets/lists/tests/mi:1.363 Mon Jul 4 15:46:09 2011 +++ src/distrib/sets/lists/tests/mi Thu Jul 7 05:50:26 2011 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.363 2011/07/04 15:46:09 jruoho Exp $ +# $NetBSD: mi,v 1.364 2011/07/07 05:50:26 jruoho Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -287,6 +287,7 @@ ./usr/libdata/debug/usr/tests/include/sys tests-include-tests ./usr/libdata/debug/usr/tests/include/sys/t_bitops.debug tests-include-tests debug,atf ./usr/libdata/debug/usr/tests/include/sys/t_bootblock.debug tests-include-tests debug,atf +./usr/libdata/debug/usr/tests/include/sys/t_socket.debug tests-include-tests debug,atf ./usr/libdata/debug/usr/tests/include/sys/t_tree.debug tests-include-tests debug,atf ./usr/libdata/debug/usr/tests/include/sys/t_types.debug tests-include-tests debug,atf ./usr/libdata/debug/usr/tests/include/t_bitstring.debug tests-include-tests debug,atf @@ -622,7 +623,7 @@ ./usr/libdata/debug/usr/tests/syscall tests-syscall-debug ./usr/libdata/debug/usr/tests/syscall/t_access.debug tests-syscall-debug debug,atf ./usr/libdata/debug/usr/tests/syscall/t_chroot.debug tests-syscall-debug debug,atf -./usr/libdata/debug/usr/tests/syscall/t_cmsg.debug tests-syscall-debug debug,atf +./usr/libdata/debug/usr/tests/syscall/t_cmsg.debug tests-obsolete obsolete ./usr/libdata/debug/usr/tests/syscall/t_dup.debug tests-syscall-debug debug,atf ./usr/libdata/debug/usr/tests/syscall/t_fsync.debug tests-syscall-debug debug,atf ./usr/libdata/debug/usr/tests/syscall/t_getgroups.debug tests-syscall-debug debug,atf @@ -1428,6 +1429,7 @@ ./usr/tests/include/sys/Atffile tests-include-tests atf ./usr/tests/include/sys/t_bitops tests-include-tests atf ./usr/tests/include/sys/t_bootblock tests-include-tests atf +./usr/tests/include/sys/t_socket tests-include-tests atf ./usr/tests/include/sys/t_tree tests-include-tests atf ./usr/tests/include/sys/t_types tests-include-tests atf ./usr/tests/include/t_bitstring tests-include-tests atf @@ -2375,7 +2377,7 @@ ./usr/tests/syscall/Atffile tests-syscall-tests atf ./usr/tests/syscall/t_access tests-syscall-tests atf ./usr/tests/syscall/t_chroot tests-syscall-tests atf -./usr/tests/syscall/t_cmsg tests-syscall-tests atf +./usr/tests/syscall/t_cmsg tests-obsolete obsolete ./usr/tests/syscall/t_dup tests-syscall-tests atf ./usr/tests/syscall/t_fsync tests-syscall-tests atf ./usr/tests/syscall/t_getgroups tests-syscall-tests atf Index: src/tests/include/sys/Makefile diff -u src/tests/include/sys/Makefile:1.4 src/tests/include/sys/Makefile:1.5 --- src/tests/include/sys/Makefile:1.4 Thu May 5 13:36:05 2011 +++ src/tests/include/sys/Makefile Thu Jul 7 05:50:27 2011 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.4 2011/05/05 13:36:05 jruoho Exp $ +# $NetBSD: Makefile,v 1.5 2011/07/07 05:50:27 jruoho Exp $ NOMAN= # defined @@ -6,7 +6,10 @@ TESTSDIR= ${TESTSBASE}/include/sys +TESTS_C= t_bitops t_bootblock t_socket t_tree t_types + LDADD.t_bitops+= -lm -TESTS_C= t_bitops t_bootblock t_tree t_types +LDADD.t_socket+= -lrumpnet_local -lrumpnet_net -lrumpnet +LDADD.t_socket+= -lrumpvfs -lrump -lrumpuser -lpthread .include <bsd.test.mk> Index: src/tests/syscall/Makefile diff -u src/tests/syscall/Makefile:1.40 src/tests/syscall/Makefile:1.41 --- src/tests/syscall/Makefile:1.40 Mon Jul 4 15:46:10 2011 +++ src/tests/syscall/Makefile Thu Jul 7 05:50:26 2011 @@ -1,10 +1,10 @@ -# $NetBSD: Makefile,v 1.40 2011/07/04 15:46:10 jruoho Exp $ +# $NetBSD: Makefile,v 1.41 2011/07/07 05:50:26 jruoho Exp $ .include <bsd.own.mk> TESTSDIR= ${TESTSBASE}/syscall -TESTS_C+= t_access t_chroot t_cmsg t_dup t_fsync +TESTS_C+= t_access t_chroot t_dup t_fsync TESTS_C+= t_getgroups t_getlogin t_getpid TESTS_C+= t_getrusage t_getsid t_gettimeofday TESTS_C+= t_issetugid t_itimer t_kill t_link @@ -17,9 +17,6 @@ LDADD.t_getpid+= -lpthread LDADD.t_timer+= -lpthread -LDADD.t_cmsg+= -lrumpnet_local -lrumpnet_net -lrumpnet -LDADD.t_cmsg+= -lrumpvfs -lrump -lrumpuser -lpthread - WARNS= 4 .include <bsd.test.mk> Added files: Index: src/tests/include/sys/t_socket.c diff -u /dev/null src/tests/include/sys/t_socket.c:1.1 --- /dev/null Thu Jul 7 05:50:27 2011 +++ src/tests/include/sys/t_socket.c Thu Jul 7 05:50:27 2011 @@ -0,0 +1,188 @@ +/* $NetBSD: t_socket.c,v 1.1 2011/07/07 05:50:27 jruoho Exp $ */ + +#include <sys/types.h> +#include <sys/mount.h> +#include <sys/socket.h> +#include <sys/un.h> + +#include <rump/rump.h> +#include <rump/rump_syscalls.h> + +#include <atf-c.h> +#include <fcntl.h> +#include <err.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <util.h> + +#include "../../h_macros.h" + +ATF_TC(cmsg_sendfd_bounds); +ATF_TC_HEAD(cmsg_sendfd_bounds, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks that attempting to pass an " + "invalid fd returns an error"); +} + +ATF_TC_BODY(cmsg_sendfd_bounds, tc) +{ + struct cmsghdr *cmp; + struct msghdr msg; + struct iovec iov; + int s[2]; + int fd; + + rump_init(); + + if (rump_sys_socketpair(AF_LOCAL, SOCK_STREAM, 0, s) == -1) + atf_tc_fail("rump_sys_socket"); + + cmp = malloc(CMSG_SPACE(sizeof(int))); + + iov.iov_base = &fd; + iov.iov_len = sizeof(int); + + cmp->cmsg_level = SOL_SOCKET; + cmp->cmsg_type = SCM_RIGHTS; + cmp->cmsg_len = CMSG_LEN(sizeof(int)); + + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_name = NULL; + msg.msg_namelen = 0; + msg.msg_control = cmp; + msg.msg_controllen = CMSG_SPACE(sizeof(int)); + + /* + * ERROR HERE: trying to pass invalid fd + * (This value was previously directly used to index the fd + * array and therefore we are passing a hyperspace index) + */ + *(int *)CMSG_DATA(cmp) = 0x12345678; + + rump_sys_sendmsg(s[0], &msg, 0); + if (errno != EBADF) + atf_tc_fail("descriptor passing failed: expected EBADF (9), " + "got %d\n(%s)", errno, strerror(errno)); +} + + +ATF_TC(cmsg_sendfd); +ATF_TC_HEAD(cmsg_sendfd, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks that fd passing works"); + atf_tc_set_md_var(tc, "timeout", "2"); +} + +ATF_TC_BODY(cmsg_sendfd, tc) +{ + char buf[128]; + struct cmsghdr *cmp; + struct msghdr msg; + struct sockaddr_un sun; + struct lwp *l1, *l2; + struct iovec iov; + socklen_t sl; + int s1, s2, sgot; + int rfd, fd[2], storage; + + rump_init(); + + RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG)); + l1 = rump_pub_lwproc_curlwp(); + + /* create unix socket and bind it to a path */ + memset(&sun, 0, sizeof(sun)); + sun.sun_family = AF_LOCAL; +#define SOCKPATH "/com" + strncpy(sun.sun_path, SOCKPATH, sizeof(SOCKPATH)); + s1 = rump_sys_socket(AF_LOCAL, SOCK_STREAM, 0); + if (s1 == -1) + atf_tc_fail_errno("socket 1"); + if (rump_sys_bind(s1, (struct sockaddr *)&sun, SUN_LEN(&sun)) == -1) + atf_tc_fail_errno("socket 1 bind"); + if (rump_sys_listen(s1, 1) == -1) + atf_tc_fail_errno("socket 1 listen"); + + /* create second process for test */ + RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG)); + l2 = rump_pub_lwproc_curlwp(); + + /* connect to unix domain socket */ + memset(&sun, 0, sizeof(sun)); + sun.sun_family = AF_LOCAL; + strncpy(sun.sun_path, SOCKPATH, sizeof(SOCKPATH)); + s2 = rump_sys_socket(AF_LOCAL, SOCK_STREAM, 0); + if (s2 == -1) + atf_tc_fail_errno("socket 2"); + if (rump_sys_connect(s2, (struct sockaddr *)&sun, SUN_LEN(&sun)) == -1) + atf_tc_fail_errno("socket 2 connect"); + + /* open a pipe and write stuff to it */ + if (rump_sys_pipe(fd) == -1) + atf_tc_fail_errno("can't open pipe"); +#define MAGICSTRING "duam xnaht" + if (rump_sys_write(fd[1], MAGICSTRING, sizeof(MAGICSTRING)) != + sizeof(MAGICSTRING)) + atf_tc_fail_errno("pipe write"); /* XXX: errno */ + + cmp = malloc(CMSG_SPACE(sizeof(int))); + + iov.iov_base = &storage; + iov.iov_len = sizeof(int); + + cmp->cmsg_level = SOL_SOCKET; + cmp->cmsg_type = SCM_RIGHTS; + cmp->cmsg_len = CMSG_LEN(sizeof(int)); + + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_name = NULL; + msg.msg_namelen = 0; + msg.msg_control = cmp; + msg.msg_controllen = CMSG_SPACE(sizeof(int)); + *(int *)CMSG_DATA(cmp) = fd[0]; + + /* pass the fd */ + if (rump_sys_sendmsg(s2, &msg, 0) == -1) + atf_tc_fail_errno("sendmsg failed"); + + /* + * We will read to the same cmsg space. Overwrite the space + * with an invalid fd to make sure we get an explicit error + * if we don't manage to read the fd. + */ + *(int *)CMSG_DATA(cmp) = -1; + + /* switch back to original proc */ + rump_pub_lwproc_switch(l1); + + /* accept connection and read fd */ + sl = sizeof(sun); + sgot = rump_sys_accept(s1, (struct sockaddr *)&sun, &sl); + if (sgot == -1) + atf_tc_fail_errno("accept"); + if (rump_sys_recvmsg(sgot, &msg, 0) == -1) + atf_tc_fail_errno("recvmsg failed"); + rfd = *(int *)CMSG_DATA(cmp); + + /* read from the fd */ + memset(buf, 0, sizeof(buf)); + if (rump_sys_read(rfd, buf, sizeof(buf)) == -1) + atf_tc_fail_errno("read rfd"); + + /* check that we got the right stuff */ + if (strcmp(buf, MAGICSTRING) != 0) + atf_tc_fail("expected \"%s\", got \"%s\"", MAGICSTRING, buf); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, cmsg_sendfd); + ATF_TP_ADD_TC(tp, cmsg_sendfd_bounds); + + return atf_no_error(); +}