Module Name: src Committed By: pooka Date: Tue Jul 13 11:51:59 UTC 2010
Modified Files: src/tests/fs/vfs: Atffile Makefile Added Files: src/tests/fs/vfs: t_vfsops.c Log Message: Add basic tests for vfsops. tfilehandle is a test for PR kern/43605 To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/fs/vfs/Atffile cvs rdiff -u -r1.2 -r1.3 src/tests/fs/vfs/Makefile cvs rdiff -u -r0 -r1.1 src/tests/fs/vfs/t_vfsops.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/fs/vfs/Atffile diff -u src/tests/fs/vfs/Atffile:1.1 src/tests/fs/vfs/Atffile:1.2 --- src/tests/fs/vfs/Atffile:1.1 Mon Jul 5 12:53:58 2010 +++ src/tests/fs/vfs/Atffile Tue Jul 13 11:51:59 2010 @@ -1,6 +1,6 @@ Content-Type: application/X-atf-atffile; version="1" -X-NetBSD-Id: "$NetBSD: Atffile,v 1.1 2010/07/05 12:53:58 njoly Exp $" +X-NetBSD-Id: "$NetBSD: Atffile,v 1.2 2010/07/13 11:51:59 pooka Exp $" prop: test-suite = "NetBSD" -tp: t_rmdirrace +tp-glob: t_* Index: src/tests/fs/vfs/Makefile diff -u src/tests/fs/vfs/Makefile:1.2 src/tests/fs/vfs/Makefile:1.3 --- src/tests/fs/vfs/Makefile:1.2 Thu Jul 8 13:21:02 2010 +++ src/tests/fs/vfs/Makefile Tue Jul 13 11:51:59 2010 @@ -1,10 +1,11 @@ -# $NetBSD: Makefile,v 1.2 2010/07/08 13:21:02 pooka Exp $ +# $NetBSD: Makefile,v 1.3 2010/07/13 11:51:59 pooka Exp $ # TESTSDIR= ${TESTSBASE}/fs/vfs WARNS= 4 TESTS_C= t_rmdirrace +TESTS_C+= t_vfsops LDADD+=-lrumpfs_ext2fs # ext2fs LDADD+=-lrumpfs_ffs # ffs Added files: Index: src/tests/fs/vfs/t_vfsops.c diff -u /dev/null src/tests/fs/vfs/t_vfsops.c:1.1 --- /dev/null Tue Jul 13 11:51:59 2010 +++ src/tests/fs/vfs/t_vfsops.c Tue Jul 13 11:51:59 2010 @@ -0,0 +1,134 @@ +/* $NetBSD: t_vfsops.c,v 1.1 2010/07/13 11:51:59 pooka Exp $ */ + +/*- + * Copyright (c) 2010 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/stat.h> +#include <sys/statvfs.h> + +#include <atf-c.h> +#include <unistd.h> + +#include <rump/rump_syscalls.h> +#include <rump/rump.h> + +#include "../common/h_fsmacros.h" +#include "../../h_macros.h" + +static void +tmount(const atf_tc_t *tc, const char *path) +{ + + return; +} + +static void +tstatvfs(const atf_tc_t *tc, const char *path) +{ + struct statvfs svb; + + if (rump_sys_statvfs1(path, &svb, ST_WAIT) == -1) + atf_tc_fail_errno("statvfs"); +} + +static void +tsync(const atf_tc_t *tc, const char *path) +{ + + rump_sys_sync(); +} + +#define MAGICSTR "just a string, I like A" +static void +tfilehandle(const atf_tc_t *tc, const char *path) +{ + char fpath[MAXPATHLEN]; + char buf[sizeof(MAGICSTR)]; + size_t fhsize; + void *fhp; + int fd; + + sprintf(fpath, "%s/file", path); + fd = rump_sys_open(fpath, O_RDWR | O_CREAT, 0777); + if (fd == -1) + atf_tc_fail_errno("open"); + + if (rump_sys_write(fd, MAGICSTR, sizeof(MAGICSTR)) != sizeof(MAGICSTR)) + atf_tc_fail("write to file"); + rump_sys_close(fd); + + /* + * Get file handle size. + * This also weeds out unsupported file systems. + */ + fhsize = 0; + if (rump_sys_getfh(fpath, NULL, &fhsize) == -1) { + if (errno == EOPNOTSUPP) { + atf_tc_skip("file handles not supported"); + } else if (errno != E2BIG) { + atf_tc_fail_errno("getfh size"); + } + } + + fhp = malloc(fhsize); + if (rump_sys_getfh(fpath, fhp, &fhsize) == -1) + atf_tc_fail_errno("getfh"); + + /* open file based on file handle */ + fd = rump_sys_fhopen(fhp, fhsize, O_RDONLY); + if (FSTYPE_TMPFS(tc)) { + atf_tc_expect_fail("PR kern/43605"); + if (fd != -1 || errno != EINVAL) + atf_tc_expect_pass(); + } + if (fd == -1) { + atf_tc_fail_errno("fhopen"); + } + + /* check that we got the same file */ + if (rump_sys_read(fd, buf, sizeof(buf)) != sizeof(MAGICSTR)) + atf_tc_fail("read fhopened file"); + + ATF_REQUIRE_STREQ(buf, MAGICSTR); + + rump_sys_close(fd); +} + +ATF_TC_FSAPPLY(tmount, "mount/unmount"); +ATF_TC_FSAPPLY(tstatvfs, "statvfs"); +ATF_TC_FSAPPLY(tsync, "sync"); +ATF_TC_FSAPPLY(tfilehandle, "file handles"); + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_FSAPPLY(tmount); + ATF_TP_FSAPPLY(tstatvfs); + ATF_TP_FSAPPLY(tsync); + ATF_TP_FSAPPLY(tfilehandle); + + return atf_no_error(); +}