Module Name: src Committed By: pooka Date: Wed Feb 9 14:32:45 UTC 2011
Modified Files: src/tests/lib: Makefile Added Files: src/tests/lib/librumpclient: Makefile t_fd.c Log Message: Add test which checks rumpclient does not use fds 0-2 for its internal purposes. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/tests/lib/Makefile cvs rdiff -u -r0 -r1.1 src/tests/lib/librumpclient/Makefile \ src/tests/lib/librumpclient/t_fd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/lib/Makefile diff -u src/tests/lib/Makefile:1.11 src/tests/lib/Makefile:1.12 --- src/tests/lib/Makefile:1.11 Sun Feb 6 18:44:29 2011 +++ src/tests/lib/Makefile Wed Feb 9 14:32:45 2011 @@ -1,9 +1,9 @@ -# $NetBSD: Makefile,v 1.11 2011/02/06 18:44:29 pooka Exp $ +# $NetBSD: Makefile,v 1.12 2011/02/09 14:32:45 pooka Exp $ .include <bsd.own.mk> TESTS_SUBDIRS= csu libc libm libevent libobjc libposix libprop librt \ - libpthread librumphijack libutil semaphore + libpthread librumpclient librumphijack libutil semaphore .if ${MKCRYPTO} != "no" TESTS_SUBDIRS+= libdes Added files: Index: src/tests/lib/librumpclient/Makefile diff -u /dev/null src/tests/lib/librumpclient/Makefile:1.1 --- /dev/null Wed Feb 9 14:32:46 2011 +++ src/tests/lib/librumpclient/Makefile Wed Feb 9 14:32:45 2011 @@ -0,0 +1,12 @@ +# $NetBSD: Makefile,v 1.1 2011/02/09 14:32:45 pooka Exp $ +# + +.include <bsd.own.mk> + +TESTSDIR= ${TESTSBASE}/lib/librumpclient + +TESTS_C= t_fd + +LDADD+= -lrumpclient + +.include <bsd.test.mk> Index: src/tests/lib/librumpclient/t_fd.c diff -u /dev/null src/tests/lib/librumpclient/t_fd.c:1.1 --- /dev/null Wed Feb 9 14:32:46 2011 +++ src/tests/lib/librumpclient/t_fd.c Wed Feb 9 14:32:45 2011 @@ -0,0 +1,92 @@ +/* $NetBSD: t_fd.c,v 1.1 2011/02/09 14:32:45 pooka Exp $ */ + +/* + * Copyright (c) 2011 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/types.h> +#include <sys/stat.h> + +#include <atf-c.h> +#include <errno.h> +#include <unistd.h> + +#include <rump/rumpclient.h> +#include <rump/rump_syscalls.h> + +#include "../../h_macros.h" + +ATF_TC_WITH_CLEANUP(bigenough); +ATF_TC_HEAD(bigenough, tc) +{ + atf_tc_set_md_var(tc, "descr", "Check that rumpclient uses " + "fd > 2"); +} + +#define RUMPSERV "unix://sucket" + +ATF_TC_BODY(bigenough, tc) +{ + struct stat sb; + + RZ(system("rump_server " RUMPSERV)); + RL(setenv("RUMP_SERVER", RUMPSERV, 1)); + + RL(dup2(0, 10)); + RL(dup2(1, 11)); + RL(dup2(2, 12)); + + RL(close(0)); + RL(close(1)); + RL(close(2)); + + RL(rumpclient_init()); + RL(rump_sys_getpid()); + + ATF_REQUIRE_ERRNO(EBADF, fstat(0, &sb) == -1); + ATF_REQUIRE_ERRNO(EBADF, fstat(1, &sb) == -1); + ATF_REQUIRE_ERRNO(EBADF, fstat(2, &sb) == -1); + + RL(rump_sys_getpid()); + + /* restore these. does it help? */ + dup2(10, 0); + dup2(11, 1); + dup2(12, 2); +} + +ATF_TC_CLEANUP(bigenough, tc) +{ + + system("env RUMP_SERVER=" RUMPSERV " rump.halt"); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, bigenough); + + return atf_no_error(); +}