Module Name:    src
Committed By:   jruoho
Date:           Sun Jul  3 15:05:44 UTC 2011

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/tests/syscall: Makefile
Added Files:
        src/tests/syscall: t_unlink.c

Log Message:
Few naive tests for unlink(2).


To generate a diff of this commit:
cvs rdiff -u -r1.356 -r1.357 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.34 -r1.35 src/tests/syscall/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/syscall/t_unlink.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.356 src/distrib/sets/lists/tests/mi:1.357
--- src/distrib/sets/lists/tests/mi:1.356	Sun Jul  3 14:34:21 2011
+++ src/distrib/sets/lists/tests/mi	Sun Jul  3 15:05:43 2011
@@ -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

Index: src/tests/syscall/Makefile
diff -u src/tests/syscall/Makefile:1.34 src/tests/syscall/Makefile:1.35
--- src/tests/syscall/Makefile:1.34	Sun Jul  3 14:34:22 2011
+++ src/tests/syscall/Makefile	Sun Jul  3 15:05:43 2011
@@ -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

Added files:

Index: src/tests/syscall/t_unlink.c
diff -u /dev/null src/tests/syscall/t_unlink.c:1.1
--- /dev/null	Sun Jul  3 15:05:44 2011
+++ src/tests/syscall/t_unlink.c	Sun Jul  3 15:05:43 2011
@@ -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();
+}

Reply via email to