Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Few naive tests for unlink(2).



details:   https://anonhg.NetBSD.org/src/rev/d09b51f387a4
branches:  trunk
changeset: 766874:d09b51f387a4
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Sun Jul 03 15:05:43 2011 +0000

description:
Few naive tests for unlink(2).

diffstat:

 distrib/sets/lists/tests/mi |    4 +-
 tests/syscall/Makefile      |    5 +-
 tests/syscall/t_unlink.c    |  154 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 160 insertions(+), 3 deletions(-)

diffs (202 lines):

diff -r b69e7c08a118 -r d09b51f387a4 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Jul 03 14:45:07 2011 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Jul 03 15:05:43 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.356 2011/07/03 14:34:21 jruoho Exp $
+# $NetBSD: mi,v 1.357 2011/07/03 15:05:43 jruoho Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -647,6 +647,7 @@
 ./usr/libdata/debug/usr/tests/syscall/t_timer.debug                    tests-syscall-debug     debug,atf
 ./usr/libdata/debug/usr/tests/syscall/t_truncate.debug                 tests-syscall-debug     debug,atf
 ./usr/libdata/debug/usr/tests/syscall/t_umask.debug                    tests-syscall-debug     debug,atf
+./usr/libdata/debug/usr/tests/syscall/t_unlink.debug                   tests-syscall-debug     debug,atf
 ./usr/libdata/debug/usr/tests/usr.bin                                  tests-sbin-tests
 ./usr/libdata/debug/usr/tests/usr.sbin                                 tests-sbin-tests
 ./usr/libdata/debug/usr/tests/util                                     tests-util-debug
@@ -2394,6 +2395,7 @@
 ./usr/tests/syscall/t_timer                    tests-syscall-tests     atf
 ./usr/tests/syscall/t_truncate                 tests-syscall-tests     atf
 ./usr/tests/syscall/t_umask                    tests-syscall-tests     atf
+./usr/tests/syscall/t_unlink                   tests-syscall-tests     atf
 ./usr/tests/toolchain                          tests-syscall-tests     atf
 ./usr/tests/toolchain/Atffile                  tests-syscall-tests     atf
 ./usr/tests/toolchain/cc                       tests-syscall-tests     atf
diff -r b69e7c08a118 -r d09b51f387a4 tests/syscall/Makefile
--- a/tests/syscall/Makefile    Sun Jul 03 14:45:07 2011 +0000
+++ b/tests/syscall/Makefile    Sun Jul 03 15:05:43 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.34 2011/07/03 14:34:22 jruoho Exp $
+# $NetBSD: Makefile,v 1.35 2011/07/03 15:05:43 jruoho Exp $
 
 .include <bsd.own.mk>
 
@@ -10,7 +10,8 @@
 TESTS_C+=      t_itimer t_kill
 TESTS_C+=      t_mincore t_mknod t_mmap t_mprotect t_msync t_nanosleep
 TESTS_C+=      t_poll t_pollts t_pselect
-TESTS_C+=      t_setrlimit t_setuid t_stat t_timer t_truncate t_umask
+TESTS_C+=      t_setrlimit t_setuid t_stat t_timer t_truncate
+TESTS_C+=      t_umask t_unlink
 
 LDADD.t_getpid+=       -lpthread
 LDADD.t_timer+=                -lpthread
diff -r b69e7c08a118 -r d09b51f387a4 tests/syscall/t_unlink.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/syscall/t_unlink.c  Sun Jul 03 15:05:43 2011 +0000
@@ -0,0 +1,154 @@
+/* $NetBSD: t_unlink.c,v 1.1 2011/07/03 15:05:43 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jukka Ruohonen.
+ *
+ * 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/cdefs.h>
+__RCSID("$NetBSD: t_unlink.c,v 1.1 2011/07/03 15:05:43 jruoho Exp $");
+
+#include <sys/stat.h>
+
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <string.h>
+#include <unistd.h>
+
+static char     path[] = "unlink";
+
+ATF_TC_WITH_CLEANUP(unlink_basic);
+ATF_TC_HEAD(unlink_basic, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "A basic test of unlink(2)");
+}
+
+ATF_TC_BODY(unlink_basic, tc)
+{
+       const size_t n = 512;
+       size_t i;
+       int fd;
+
+       for (i = 0; i < n; i++) {
+
+               fd = open(path, O_RDWR | O_CREAT, 0666);
+
+               ATF_REQUIRE(fd != -1);
+               ATF_REQUIRE(close(fd) == 0);
+               ATF_REQUIRE(unlink(path) == 0);
+
+               errno = 0;
+               ATF_REQUIRE_ERRNO(ENOENT, open(path, O_RDONLY) == -1);
+       }
+}
+
+ATF_TC_CLEANUP(unlink_basic, tc)
+{
+       (void)unlink(path);
+}
+
+ATF_TC_WITH_CLEANUP(unlink_err);
+ATF_TC_HEAD(unlink_err, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test error conditions of unlink(2)");
+}
+
+ATF_TC_BODY(unlink_err, tc)
+{
+       char buf[PATH_MAX + 1];
+
+       (void)memset(buf, 'x', sizeof(buf));
+
+       errno = 0;
+       ATF_REQUIRE_ERRNO(EBUSY, unlink("/") == -1);
+
+       errno = 0;
+       ATF_REQUIRE_ERRNO(ENAMETOOLONG, unlink(buf) == -1);
+
+       errno = 0;
+       ATF_REQUIRE_ERRNO(ENOENT, unlink("/a/b/c/d/e/f/g/h/i/j/k/l/m") == -1);
+}
+
+ATF_TC_CLEANUP(unlink_err, tc)
+{
+       (void)unlink(path);
+}
+
+ATF_TC_WITH_CLEANUP(unlink_fifo);
+ATF_TC_HEAD(unlink_fifo, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test unlink(2) for a FIFO");
+}
+
+ATF_TC_BODY(unlink_fifo, tc)
+{
+
+       ATF_REQUIRE(mkfifo(path, 0666) == 0);
+       ATF_REQUIRE(unlink(path) == 0);
+
+       errno = 0;
+       ATF_REQUIRE_ERRNO(ENOENT, open(path, O_RDONLY) == -1);
+}
+
+ATF_TC_CLEANUP(unlink_fifo, tc)
+{
+       (void)unlink(path);
+}
+
+ATF_TC_WITH_CLEANUP(unlink_perm);
+ATF_TC_HEAD(unlink_perm, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test permissions with unlink(2)");
+       atf_tc_set_md_var(tc, "require.user", "unprivileged");
+}
+
+ATF_TC_BODY(unlink_perm, tc)
+{
+
+       errno = 0;
+       ATF_REQUIRE_ERRNO(EACCES, unlink("/etc") == -1);
+
+       errno = 0;
+       ATF_REQUIRE_ERRNO(EACCES, unlink("/root/.profile") == -1);
+}
+
+ATF_TC_CLEANUP(unlink_perm, tc)
+{
+       (void)unlink(path);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, unlink_basic);
+       ATF_TP_ADD_TC(tp, unlink_err);
+       ATF_TP_ADD_TC(tp, unlink_fifo);
+       ATF_TP_ADD_TC(tp, unlink_perm);
+
+       return atf_no_error();
+}



Home | Main Index | Thread Index | Old Index