From owner-svn-src-user@freebsd.org Wed Oct 14 22:22:22 2015 Return-Path: Delivered-To: svn-src-user@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 06594A128D6 for ; Wed, 14 Oct 2015 22:22:22 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id ADACCF3B; Wed, 14 Oct 2015 22:22:18 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from ralph.baldwin.cx (c-73-231-226-104.hsd1.ca.comcast.net [73.231.226.104]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 60279B922; Wed, 14 Oct 2015 18:22:16 -0400 (EDT) From: John Baldwin To: Garrett Cooper Cc: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: Re: svn commit: r289223 - in user/ngie/more-tests2: etc/mtree tests/sys tests/sys/posixshm tools/regression/posixshm tools/test/posixshm Date: Wed, 14 Oct 2015 14:53:50 -0700 Message-ID: <2077673.bKfe7zWZ9u@ralph.baldwin.cx> User-Agent: KMail/4.14.3 (FreeBSD/10.2-PRERELEASE; KDE/4.14.3; amd64; ; ) In-Reply-To: <201510131650.t9DGoCqD088149@repo.freebsd.org> References: <201510131650.t9DGoCqD088149@repo.freebsd.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Wed, 14 Oct 2015 18:22:16 -0400 (EDT) X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Oct 2015 22:22:22 -0000 On Tuesday, October 13, 2015 04:50:12 PM Garrett Cooper wrote: > Author: ngie > Date: Tue Oct 13 16:50:12 2015 > New Revision: 289223 > URL: https://svnweb.freebsd.org/changeset/base/289223 > > Log: > Integrate tools/test/posixshm and tools/regression/posixshm into the FreeBSD > test suite as tests/sys/posixshm > > Copied: user/ngie/more-tests2/tests/sys/posixshm/posixshm.c (from r289197, user/ngie/more-tests2/tools/regression/posixshm/posixshm.c) > ============================================================================== > --- /dev/null 00:00:00 1970 (empty, because file is newly added) > +++ user/ngie/more-tests2/tests/sys/posixshm/posixshm.c Tue Oct 13 16:50:12 2015 (r289223, copy of r289197, user/ngie/more-tests2/tools/regression/posixshm/posixshm.c) > @@ -0,0 +1,627 @@ > +/*- > + * Copyright (c) 2006 Robert N. M. Watson > + * 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 AUTHOR 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 AUTHOR 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 > +__FBSDID("$FreeBSD$"); > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "test.h" > + > +#define TEST_PATH "/tmp/posixshm_regression_test" > + > +/* > + * Attempt a shm_open() that should fail with an expected error of 'error'. > + */ > +static void > +shm_open_should_fail(const char *path, int flags, mode_t mode, int error) > +{ > + int fd; > + > + fd = shm_open(path, flags, mode); > + if (fd >= 0) { > + fail_err("shm_open() didn't fail"); > + close(fd); > + return; > + } > + if (errno != error) { > + fail_errno("shm_open"); > + return; > + } > + pass(); > +} > + > +/* > + * Attempt a shm_unlink() that should fail with an expected error of 'error'. > + */ > +static void > +shm_unlink_should_fail(const char *path, int error) > +{ > + > + if (shm_unlink(path) >= 0) { > + fail_err("shm_unlink() didn't fail"); > + return; > + } > + if (errno != error) { > + fail_errno("shm_unlink"); > + return; > + } > + pass(); > +} > + > +/* > + * Open the test object and write '1' to the first byte. Returns valid fd > + * on success and -1 on failure. > + */ > +static int > +scribble_object(void) > +{ > + char *page; > + int fd; > + > + fd = shm_open(TEST_PATH, O_CREAT | O_EXCL | O_RDWR, 0777); > + if (fd < 0 && errno == EEXIST) { > + if (shm_unlink(TEST_PATH) < 0) { > + fail_errno("shm_unlink"); > + return (-1); > + } > + fd = shm_open(TEST_PATH, O_CREAT | O_EXCL | O_RDWR, 0777); > + } > + if (fd < 0) { > + fail_errno("shm_open"); > + return (-1); > + } > + if (ftruncate(fd, getpagesize()) < 0) { > + fail_errno("ftruncate"); > + close(fd); > + shm_unlink(TEST_PATH); > + return (-1); > + } > + > + page = mmap(0, getpagesize(), PROT_READ | PROT_WRITE, MAP_SHARED, fd, > + 0); > + if (page == MAP_FAILED) { > + fail_errno("mmap"); > + close(fd); > + shm_unlink(TEST_PATH); > + return (-1); > + } > + > + page[0] = '1'; > + > + if (munmap(page, getpagesize()) < 0) { > + fail_errno("munmap"); > + close(fd); > + shm_unlink(TEST_PATH); > + return (-1); > + } > + > + return (fd); > +} > + > +static void > +remap_object(void) > +{ > + char *page; > + int fd; > + > + fd = scribble_object(); > + if (fd < 0) > + return; > + > + page = mmap(0, getpagesize(), PROT_READ | PROT_WRITE, MAP_SHARED, fd, > + 0); > + if (page == MAP_FAILED) { > + fail_errno("mmap(2)"); > + close(fd); > + shm_unlink(TEST_PATH); > + return; > + } > + > + if (page[0] != '1') { > + fail_err("missing data"); > + close(fd); > + shm_unlink(TEST_PATH); > + return; > + } > + > + close(fd); > + if (munmap(page, getpagesize()) < 0) { > + fail_errno("munmap"); > + shm_unlink(TEST_PATH); > + return; > + } > + > + if (shm_unlink(TEST_PATH) < 0) { > + fail_errno("shm_unlink"); > + return; > + } > + > + pass(); > +} > +TEST(remap_object, "remap object"); This should be rather straight foward to convert to true ATF. It was already using a home-grown test frame work. > Modified: user/ngie/more-tests2/tests/sys/posixshm/shm_test.c > ============================================================================== > --- user/ngie/more-tests2/tools/test/posixshm/shm_test.c Mon Oct 12 18:33:36 2015 (r289197) > +++ user/ngie/more-tests2/tests/sys/posixshm/shm_test.c Tue Oct 13 16:50:12 2015 (r289223) > @@ -79,7 +79,12 @@ main(int argc, char **argv) > /* > * Can't use mkstemp for obvious reasons... > */ > - strcpy(buf, "/tmp/shmtest.XXXXXXXXXXXX"); > + char *tmpdir = getenv("TMPDIR"); > + if (tmpdir == NULL) > + tmpdir = "/tmp"; > + snprintf(buf, sizeof(buf) - 1, > + "%s/shmtest.XXXXXXXXXXXX", tmpdir); > + buf[sizeof(buf) - 1] = '\0'; > mktemp(buf); > desc = shm_open(buf, O_EXCL | O_CREAT | O_RDWR, 0600); This should probably be revisited. It may be that this can just use SHM_ANON instead. This probably predates the in-kernel shm_open(). -- John Baldwin