svn commit: r289441 - in head: etc/mtree tests/sys tests/sys/posixshm tools/regression/posixshm tools/test/posixshm
Garrett Cooper
ngie at FreeBSD.org
Sat Oct 17 04:32:23 UTC 2015
Author: ngie
Date: Sat Oct 17 04:32:21 2015
New Revision: 289441
URL: https://svnweb.freebsd.org/changeset/base/289441
Log:
Integrate tools/test/posixshm and tools/regression/posixshm into the FreeBSD
test suite as tests/sys/posixshm
Some other highlights:
- Convert the testcases over to ATF
- Don't use hardcoded paths to /tmp (which violate the ATF/kyua samdbox); use
mkstemp to generate temporary paths for non-SHM_ANON shm objects.
MFC after: 2 weeks
Sponsored by: EMC / Isilon Storage Division
Added:
head/tests/sys/posixshm/
- copied from r289223, user/ngie/more-tests2/tests/sys/posixshm/
head/tests/sys/posixshm/posixshm_test.c
- copied, changed from r289437, user/ngie/more-tests2/tests/sys/posixshm/posixshm_test.c
Deleted:
head/tests/sys/posixshm/posixshm.c
head/tests/sys/posixshm/shm_test.c
head/tests/sys/posixshm/test.c
head/tests/sys/posixshm/test.h
head/tools/regression/posixshm/
head/tools/test/posixshm/
Modified:
head/etc/mtree/BSD.tests.dist
head/tests/sys/Makefile
head/tests/sys/posixshm/Makefile
Directory Properties:
head/ (props changed)
Modified: head/etc/mtree/BSD.tests.dist
==============================================================================
--- head/etc/mtree/BSD.tests.dist Sat Oct 17 04:07:41 2015 (r289440)
+++ head/etc/mtree/BSD.tests.dist Sat Oct 17 04:32:21 2015 (r289441)
@@ -410,6 +410,8 @@
unlink
..
..
+ posixshm
+ ..
vfs
..
vm
Modified: head/tests/sys/Makefile
==============================================================================
--- head/tests/sys/Makefile Sat Oct 17 04:07:41 2015 (r289440)
+++ head/tests/sys/Makefile Sat Oct 17 04:32:21 2015 (r289441)
@@ -12,6 +12,7 @@ TESTS_SUBDIRS+= kqueue
TESTS_SUBDIRS+= mqueue
TESTS_SUBDIRS+= netinet
TESTS_SUBDIRS+= opencrypto
+TESTS_SUBDIRS+= posixshm
TESTS_SUBDIRS+= vfs
TESTS_SUBDIRS+= vm
Modified: head/tests/sys/posixshm/Makefile
==============================================================================
--- user/ngie/more-tests2/tests/sys/posixshm/Makefile Tue Oct 13 16:50:12 2015 (r289223)
+++ head/tests/sys/posixshm/Makefile Sat Oct 17 04:32:21 2015 (r289441)
@@ -2,10 +2,6 @@
TESTSDIR= ${TESTSBASE}/sys/posixshm
-TAP_TESTS_C+= posixshm_test
-PLAIN_TESTS_C+= posixshm_test2
-
-SRCS.posixshm_test= posixshm.c test.c
-SRCS.posixshm_test2= shm_test.c
+ATF_TESTS_C+= posixshm_test
.include <bsd.test.mk>
Copied and modified: head/tests/sys/posixshm/posixshm_test.c (from r289437, user/ngie/more-tests2/tests/sys/posixshm/posixshm_test.c)
==============================================================================
--- user/ngie/more-tests2/tests/sys/posixshm/posixshm_test.c Sat Oct 17 03:13:22 2015 (r289437, copy source)
+++ head/tests/sys/posixshm/posixshm_test.c Sat Oct 17 04:32:21 2015 (r289441)
@@ -110,18 +110,18 @@ scribble_object(void)
fd = shm_open(test_path, O_CREAT | O_EXCL | O_RDWR, 0777);
}
if (fd < 0)
- atf_tc_fail("shm_open");
+ atf_tc_fail("shm_open failed; errno=%d", errno);
if (ftruncate(fd, getpagesize()) < 0)
- atf_tc_fail("ftruncate");
+ atf_tc_fail("ftruncate failed; errno=%d", errno);
page = mmap(0, getpagesize(), PROT_READ | PROT_WRITE, MAP_SHARED, fd,
0);
if (page == MAP_FAILED)
- atf_tc_fail("mmap");
+ atf_tc_fail("mmap failed; errno=%d", errno);
page[0] = '1';
if (munmap(page, getpagesize()) < 0)
- atf_tc_fail("munmap");
+ atf_tc_fail("munmap failed; errno=%d", errno);
return (fd);
}
@@ -136,32 +136,18 @@ ATF_TC_BODY(remap_object, tc)
page = mmap(0, getpagesize(), PROT_READ | PROT_WRITE, MAP_SHARED, fd,
0);
- if (page == MAP_FAILED) {
- atf_tc_fail("mmap(2)");
- close(fd);
- shm_unlink(test_path);
- return;
- }
+ if (page == MAP_FAILED)
+ atf_tc_fail("mmap(2) failed; errno=%d", errno);
- if (page[0] != '1') {
- atf_tc_fail("missing data");
- close(fd);
- shm_unlink(test_path);
- return;
- }
+ if (page[0] != '1')
+ atf_tc_fail("missing data ('%c' != '1')", page[0]);
close(fd);
- if (munmap(page, getpagesize()) < 0) {
- atf_tc_fail("munmap");
- shm_unlink(test_path);
- return;
- }
-
- if (shm_unlink(test_path) < 0) {
- atf_tc_fail("shm_unlink");
- return;
- }
+ if (munmap(page, getpagesize()) < 0)
+ atf_tc_fail("munmap failed; errno=%d", errno);
+ ATF_REQUIRE_MSG(shm_unlink(test_path) != -1,
+ "shm_unlink failed; errno=%d", errno);
}
ATF_TC_WITHOUT_HEAD(reopen_object);
@@ -174,30 +160,20 @@ ATF_TC_BODY(reopen_object, tc)
close(fd);
fd = shm_open(test_path, O_RDONLY, 0777);
- if (fd < 0) {
- atf_tc_fail("shm_open(2)");
- shm_unlink(test_path);
- return;
- }
+ if (fd < 0)
+ atf_tc_fail("shm_open(2) failed; errno=%d", errno);
+
page = mmap(0, getpagesize(), PROT_READ, MAP_SHARED, fd, 0);
- if (page == MAP_FAILED) {
- atf_tc_fail("mmap(2)");
- close(fd);
- shm_unlink(test_path);
- return;
- }
+ if (page == MAP_FAILED)
+ atf_tc_fail("mmap(2) failed; errno=%d", errno);
- if (page[0] != '1') {
- atf_tc_fail("missing data");
- munmap(page, getpagesize());
- close(fd);
- shm_unlink(test_path);
- return;
- }
+ if (page[0] != '1')
+ atf_tc_fail("missing data ('%c' != '1')", page[0]);
munmap(page, getpagesize());
close(fd);
- shm_unlink(test_path);
+ ATF_REQUIRE_MSG(shm_unlink(test_path) != -1,
+ "shm_unlink failed; errno=%d", errno);
}
ATF_TC_WITHOUT_HEAD(readonly_mmap_write);
@@ -209,30 +185,21 @@ ATF_TC_BODY(readonly_mmap_write, tc)
gen_test_path();
fd = shm_open(test_path, O_RDONLY | O_CREAT, 0777);
- if (fd < 0) {
- atf_tc_fail("shm_open");
- return;
- }
+ ATF_REQUIRE_MSG(fd >= 0, "shm_open failed; errno=%d", errno);
/* PROT_WRITE should fail with EACCES. */
page = mmap(0, getpagesize(), PROT_READ | PROT_WRITE, MAP_SHARED, fd,
0);
- if (page != MAP_FAILED) {
- atf_tc_fail("mmap(PROT_WRITE) succeeded");
- munmap(page, getpagesize());
- close(fd);
- shm_unlink(test_path);
- return;
- }
- if (errno != EACCES) {
- atf_tc_fail("mmap");
- close(fd);
- shm_unlink(test_path);
- return;
- }
+ if (page != MAP_FAILED)
+ atf_tc_fail("mmap(PROT_WRITE) succeeded unexpectedly");
+
+ if (errno != EACCES)
+ atf_tc_fail("mmap(PROT_WRITE) didn't fail with EACCES; "
+ "errno=%d", errno);
close(fd);
- shm_unlink(test_path);
+ ATF_REQUIRE_MSG(shm_unlink(test_path) != -1,
+ "shm_unlink failed; errno=%d", errno);
}
ATF_TC_WITHOUT_HEAD(open_after_link);
@@ -243,16 +210,11 @@ ATF_TC_BODY(open_after_link, tc)
gen_test_path();
fd = shm_open(test_path, O_RDONLY | O_CREAT, 0777);
- if (fd < 0) {
- atf_tc_fail("shm_open(1)");
- return;
- }
+ ATF_REQUIRE_MSG(fd >= 0, "shm_open(1) failed; errno=%d", errno);
close(fd);
- if (shm_unlink(test_path) < 0) {
- atf_tc_fail("shm_unlink");
- return;
- }
+ ATF_REQUIRE_MSG(shm_unlink(test_path) != -1, "shm_unlink failed: %d",
+ errno);
shm_open_should_fail(test_path, O_RDONLY, 0777, ENOENT);
}
@@ -288,10 +250,7 @@ ATF_TC_BODY(open_anon, tc)
int fd;
fd = shm_open(SHM_ANON, O_RDWR, 0777);
- if (fd < 0) {
- atf_tc_fail("shm_open");
- return;
- }
+ ATF_REQUIRE_MSG(fd >= 0, "shm_open failed; errno=%d", errno);
close(fd);
}
@@ -336,13 +295,14 @@ ATF_TC_BODY(open_create_existing_object,
gen_test_path();
fd = shm_open(test_path, O_RDONLY|O_CREAT, 0777);
- ATF_REQUIRE_MSG(fd != -1, "shm_open(O_CREAT) failed; errno=%d", errno);
+ ATF_REQUIRE_MSG(fd >= 0, "shm_open failed; errno=%d", errno);
close(fd);
shm_open_should_fail(test_path, O_RDONLY|O_CREAT|O_EXCL,
0777, EEXIST);
- shm_unlink("shm_object");
+ ATF_REQUIRE_MSG(shm_unlink(test_path) != -1,
+ "shm_unlink failed; errno=%d", errno);
}
ATF_TC_WITHOUT_HEAD(trunc_resets_object);
@@ -355,48 +315,24 @@ ATF_TC_BODY(trunc_resets_object, tc)
/* Create object and set size to 1024. */
fd = shm_open(test_path, O_RDWR | O_CREAT, 0777);
- if (fd < 0) {
- atf_tc_fail("shm_open(1)");
- return;
- }
- if (ftruncate(fd, 1024) < 0) {
- atf_tc_fail("ftruncate");
- close(fd);
- return;
- }
- if (fstat(fd, &sb) < 0) {
- atf_tc_fail("fstat(1)");
- close(fd);
- return;
- }
- if (sb.st_size != 1024) {
- atf_tc_fail("size %d != 1024", (int)sb.st_size);
- close(fd);
- return;
- }
+ ATF_REQUIRE_MSG(fd >= 0, "shm_open(1) failed; errno=%d", errno);
+ ATF_REQUIRE_MSG(ftruncate(fd, 1024) != -1,
+ "ftruncate failed; errno=%d", errno);
+ ATF_REQUIRE_MSG(fstat(fd, &sb) != -1,
+ "fstat(1) failed; errno=%d", errno);
+ ATF_REQUIRE_MSG(sb.st_size == 1024, "size %d != 1024", (int)sb.st_size);
close(fd);
/* Open with O_TRUNC which should reset size to 0. */
fd = shm_open(test_path, O_RDWR | O_TRUNC, 0777);
- if (fd < 0) {
- atf_tc_fail("shm_open(2)");
- return;
- }
- if (fstat(fd, &sb) < 0) {
- atf_tc_fail("fstat(2)");
- close(fd);
- return;
- }
- if (sb.st_size != 0) {
- atf_tc_fail("size after O_TRUNC %d != 0", (int)sb.st_size);
- close(fd);
- return;
- }
+ ATF_REQUIRE_MSG(fd >= 0, "shm_open(2) failed; errno=%d", errno);
+ ATF_REQUIRE_MSG(fstat(fd, &sb) != -1,
+ "fstat(2) failed; errno=%d", errno);
+ ATF_REQUIRE_MSG(sb.st_size == 0,
+ "size was not 0 after truncation: %d", (int)sb.st_size);
close(fd);
- if (shm_unlink(test_path) < 0) {
- atf_tc_fail("shm_unlink");
- return;
- }
+ ATF_REQUIRE_MSG(shm_unlink(test_path) != -1,
+ "shm_unlink failed; errno=%d", errno);
}
ATF_TC_WITHOUT_HEAD(unlink_bad_path_pointer);
@@ -423,110 +359,76 @@ ATF_TC_BODY(object_resize, tc)
{
pid_t pid;
struct stat sb;
- char *page;
+ char err_buf[1024], *page;
int fd, status;
/* Start off with a size of a single page. */
- fd = shm_open(SHM_ANON, O_CREAT | O_RDWR, 0777);
- if (fd < 0) {
- atf_tc_fail("shm_open");
- return;
- }
- if (ftruncate(fd, getpagesize()) < 0) {
- atf_tc_fail("ftruncate(1)");
- close(fd);
- return;
- }
- if (fstat(fd, &sb) < 0) {
- atf_tc_fail("fstat(1)");
- close(fd);
- return;
- }
- if (sb.st_size != getpagesize()) {
- atf_tc_fail("first resize failed");
- close(fd);
- return;
- }
+ fd = shm_open(SHM_ANON, O_CREAT|O_RDWR, 0777);
+ if (fd < 0)
+ atf_tc_fail("shm_open failed; errno=%d", errno);
+
+ if (ftruncate(fd, getpagesize()) < 0)
+ atf_tc_fail("ftruncate(1) failed; errno=%d", errno);
+
+ if (fstat(fd, &sb) < 0)
+ atf_tc_fail("fstat(1) failed; errno=%d", errno);
+
+ if (sb.st_size != getpagesize())
+ atf_tc_fail("first resize failed (%d != %d)",
+ (int)sb.st_size, getpagesize());
/* Write a '1' to the first byte. */
- page = mmap(0, getpagesize(), PROT_READ | PROT_WRITE, MAP_SHARED, fd,
+ page = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd,
0);
- if (page == MAP_FAILED) {
+ if (page == MAP_FAILED)
atf_tc_fail("mmap(1)");
- close(fd);
- return;
- }
page[0] = '1';
- if (munmap(page, getpagesize()) < 0) {
- atf_tc_fail("munmap(1)");
- close(fd);
- return;
- }
+ if (munmap(page, getpagesize()) < 0)
+ atf_tc_fail("munmap(1) failed; errno=%d", errno);
/* Grow the object to 2 pages. */
- if (ftruncate(fd, getpagesize() * 2) < 0) {
- atf_tc_fail("ftruncate(2)");
- close(fd);
- return;
- }
- if (fstat(fd, &sb) < 0) {
- atf_tc_fail("fstat(2)");
- close(fd);
- return;
- }
- if (sb.st_size != getpagesize() * 2) {
- atf_tc_fail("second resize failed");
- close(fd);
- return;
- }
+ if (ftruncate(fd, getpagesize() * 2) < 0)
+ atf_tc_fail("ftruncate(2) failed; errno=%d", errno);
+
+ if (fstat(fd, &sb) < 0)
+ atf_tc_fail("fstat(2) failed; errno=%d", errno);
+
+ if (sb.st_size != getpagesize() * 2)
+ atf_tc_fail("second resize failed (%d != %d)",
+ (int)sb.st_size, getpagesize() * 2);
/* Check for '1' at the first byte. */
- page = mmap(0, getpagesize() * 2, PROT_READ | PROT_WRITE, MAP_SHARED,
+ page = mmap(0, getpagesize() * 2, PROT_READ|PROT_WRITE, MAP_SHARED,
fd, 0);
- if (page == MAP_FAILED) {
- atf_tc_fail("mmap(2)");
- close(fd);
- return;
- }
+ if (page == MAP_FAILED)
+ atf_tc_fail("mmap(2) failed; errno=%d", errno);
- if (page[0] != '1') {
- atf_tc_fail("missing data at 0");
- close(fd);
- return;
- }
+ if (page[0] != '1')
+ atf_tc_fail("'%c' != '1'", page[0]);
/* Write a '2' at the start of the second page. */
page[getpagesize()] = '2';
/* Shrink the object back to 1 page. */
- if (ftruncate(fd, getpagesize()) < 0) {
- atf_tc_fail("ftruncate(3)");
- close(fd);
- return;
- }
- if (fstat(fd, &sb) < 0) {
- atf_tc_fail("fstat(3)");
- close(fd);
- return;
- }
- if (sb.st_size != getpagesize()) {
- atf_tc_fail("third resize failed");
- close(fd);
- return;
- }
+ if (ftruncate(fd, getpagesize()) < 0)
+ atf_tc_fail("ftruncate(3) failed; errno=%d", errno);
+
+ if (fstat(fd, &sb) < 0)
+ atf_tc_fail("fstat(3) failed; errno=%d", errno);
+
+ if (sb.st_size != getpagesize())
+ atf_tc_fail("third resize failed (%d != %d)",
+ (int)sb.st_size, getpagesize());
/*
* Fork a child process to make sure the second page is no
* longer valid.
*/
pid = fork();
- if (pid < 0) {
- atf_tc_fail("fork");
- close(fd);
- return;
- }
+ if (pid == -1)
+ atf_tc_fail("fork failed; errno=%d", errno);
if (pid == 0) {
struct rlimit lim;
@@ -546,33 +448,23 @@ ATF_TC_BODY(object_resize, tc)
fprintf(stderr, "child: page 1: '%c'\n", c);
exit(0);
}
- if (wait(&status) < 0) {
- atf_tc_fail("wait");
- close(fd);
- return;
- }
- if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGSEGV) {
+
+ if (wait(&status) < 0)
+ atf_tc_fail("wait failed; errno=%d", errno);
+
+ if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGSEGV)
atf_tc_fail("child terminated with status %x", status);
- close(fd);
- return;
- }
/* Grow the object back to 2 pages. */
- if (ftruncate(fd, getpagesize() * 2) < 0) {
- atf_tc_fail("ftruncate(4)");
- close(fd);
- return;
- }
- if (fstat(fd, &sb) < 0) {
- atf_tc_fail("fstat(4)");
- close(fd);
- return;
- }
- if (sb.st_size != getpagesize() * 2) {
- atf_tc_fail("second resize failed");
- close(fd);
- return;
- }
+ if (ftruncate(fd, getpagesize() * 2) < 0)
+ atf_tc_fail("ftruncate(2) failed; errno=%d", errno);
+
+ if (fstat(fd, &sb) < 0)
+ atf_tc_fail("fstat(2) failed; errno=%d", errno);
+
+ if (sb.st_size != getpagesize() * 2)
+ atf_tc_fail("fourth resize failed (%d != %d)",
+ (int)sb.st_size, getpagesize());
/*
* Note that the mapping at 'page' for the second page is
@@ -583,11 +475,9 @@ ATF_TC_BODY(object_resize, tc)
* object was shrunk and the new pages when an object are
* grown are zero-filled.
*/
- if (page[getpagesize()] != 0) {
- atf_tc_fail("invalid data at %d", getpagesize());
- close(fd);
- return;
- }
+ if (page[getpagesize()] != 0)
+ atf_tc_fail("invalid data at %d: %x != 0",
+ getpagesize(), (int)page[getpagesize()]);
close(fd);
}
More information about the svn-src-all
mailing list