Source-Changes-HG archive

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

[src/trunk]: src Few simple tests for mknod(2), including a skipped one for P...



details:   https://anonhg.NetBSD.org/src/rev/16e43b4625b4
branches:  trunk
changeset: 766870:16e43b4625b4
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Sun Jul 03 14:34:21 2011 +0000

description:
Few simple tests for mknod(2), including a skipped one for PR kern/45111.

diffstat:

 distrib/sets/lists/tests/mi |    4 +-
 tests/syscall/Makefile      |    4 +-
 tests/syscall/t_mknod.c     |  164 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 169 insertions(+), 3 deletions(-)

diffs (211 lines):

diff -r c9bdb0eb2d93 -r 16e43b4625b4 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Jul 03 14:11:43 2011 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Jul 03 14:34:21 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.355 2011/06/25 05:45:13 nonaka Exp $
+# $NetBSD: mi,v 1.356 2011/07/03 14:34:21 jruoho Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -633,6 +633,7 @@
 ./usr/libdata/debug/usr/tests/syscall/t_itimer.debug                   tests-syscall-debug     debug,atf
 ./usr/libdata/debug/usr/tests/syscall/t_kill.debug                     tests-syscall-debug     debug,atf
 ./usr/libdata/debug/usr/tests/syscall/t_mincore.debug                  tests-syscall-debug     debug,atf
+./usr/libdata/debug/usr/tests/syscall/t_mknod.debug                    tests-syscall-debug     debug,atf
 ./usr/libdata/debug/usr/tests/syscall/t_mmap.debug                     tests-syscall-debug     debug,atf
 ./usr/libdata/debug/usr/tests/syscall/t_mprotect.debug                 tests-syscall-debug     debug,atf
 ./usr/libdata/debug/usr/tests/syscall/t_msync.debug                    tests-syscall-debug     debug,atf
@@ -2379,6 +2380,7 @@
 ./usr/tests/syscall/t_itimer                   tests-syscall-tests     atf
 ./usr/tests/syscall/t_kill                     tests-syscall-tests     atf
 ./usr/tests/syscall/t_mincore                  tests-syscall-tests     atf
+./usr/tests/syscall/t_mknod                    tests-syscall-tests     atf
 ./usr/tests/syscall/t_mmap                     tests-syscall-tests     atf
 ./usr/tests/syscall/t_mprotect                 tests-syscall-tests     atf
 ./usr/tests/syscall/t_msync                    tests-syscall-tests     atf
diff -r c9bdb0eb2d93 -r 16e43b4625b4 tests/syscall/Makefile
--- a/tests/syscall/Makefile    Sun Jul 03 14:11:43 2011 +0000
+++ b/tests/syscall/Makefile    Sun Jul 03 14:34:21 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.33 2011/06/20 18:03:41 jruoho Exp $
+# $NetBSD: Makefile,v 1.34 2011/07/03 14:34:22 jruoho Exp $
 
 .include <bsd.own.mk>
 
@@ -8,7 +8,7 @@
 TESTS_C+=      t_getgroups t_getlogin t_getpid
 TESTS_C+=      t_getrusage t_getsid t_gettimeofday
 TESTS_C+=      t_itimer t_kill
-TESTS_C+=      t_mincore t_mmap t_mprotect t_msync t_nanosleep
+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
 
diff -r c9bdb0eb2d93 -r 16e43b4625b4 tests/syscall/t_mknod.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/syscall/t_mknod.c   Sun Jul 03 14:34:21 2011 +0000
@@ -0,0 +1,164 @@
+/* $NetBSD: t_mknod.c,v 1.1 2011/07/03 14:34:22 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_mknod.c,v 1.1 2011/07/03 14:34:22 jruoho Exp $");
+
+#include <sys/stat.h>
+
+#include <atf-c.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+static char     path[] = "node";
+
+ATF_TC_WITH_CLEANUP(mknod_err);
+ATF_TC_HEAD(mknod_err, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test error conditions of mknod(2)");
+       atf_tc_set_md_var(tc, "require.user", "root");
+}
+
+ATF_TC_BODY(mknod_err, tc)
+{
+       char buf[PATH_MAX + 1];
+
+       (void)memset(buf, 'x', sizeof(buf));
+
+       errno = 0;
+       ATF_REQUIRE_ERRNO(EINVAL, mknod(path, -1, 0) == -1);
+
+       /*
+        * The following case triggers an assertion with tmpfs.
+        */
+       atf_tc_skip("the test case may cause a panic; see PR kern/45111");
+
+       errno = 0;
+       ATF_REQUIRE_ERRNO(EINVAL, mknod(path, S_IFCHR, -1) == -1);
+
+       errno = 0;
+       ATF_REQUIRE_ERRNO(ENAMETOOLONG, mknod(buf, S_IFCHR, 0) == -1);
+
+       errno = 0;
+       ATF_REQUIRE_ERRNO(EFAULT, mknod((char *)-1, S_IFCHR, 0) == -1);
+
+       errno = 0;
+       ATF_REQUIRE_ERRNO(EEXIST, mknod("/dev/null", S_IFCHR, 0) == -1);
+
+       errno = 0;
+       ATF_REQUIRE_ERRNO(ENOENT, mknod("/a/b/c/d/e/f/g", S_IFCHR, 0) == -1);
+}
+
+ATF_TC_CLEANUP(mknod_err, tc)
+{
+       (void)unlink(path);
+}
+
+ATF_TC_WITH_CLEANUP(mknod_perm);
+ATF_TC_HEAD(mknod_perm, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test permissions of mknod(2)");
+       atf_tc_set_md_var(tc, "require.user", "unprivileged");
+}
+
+ATF_TC_BODY(mknod_perm, tc)
+{
+
+       errno = 0;
+       ATF_REQUIRE_ERRNO(EPERM, mknod(path, S_IFCHR, 0) == -1);
+
+       errno = 0;
+       ATF_REQUIRE_ERRNO(EPERM, mknod(path, S_IFBLK, 0) == -1);
+}
+
+ATF_TC_CLEANUP(mknod_perm, tc)
+{
+       (void)unlink(path);
+}
+
+ATF_TC_WITH_CLEANUP(mknod_stat);
+ATF_TC_HEAD(mknod_stat, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "A basic test of mknod(2)");
+       atf_tc_set_md_var(tc, "require.user", "root");
+}
+
+ATF_TC_BODY(mknod_stat, tc)
+{
+       struct stat st;
+
+       (void)memset(&st, 0, sizeof(struct stat));
+
+       ATF_REQUIRE(mknod(path, S_IFCHR, 0) == 0);
+       ATF_REQUIRE(stat(path, &st) == 0);
+
+       if (S_ISCHR(st.st_mode) == 0)
+               atf_tc_fail_nonfatal("invalid mode from mknod(2) (S_IFBLK)");
+
+       ATF_REQUIRE(unlink(path) == 0);
+
+       (void)memset(&st, 0, sizeof(struct stat));
+
+       ATF_REQUIRE(mknod(path, S_IFBLK, 0) == 0);
+       ATF_REQUIRE(stat(path, &st) == 0);
+
+       if (S_ISBLK(st.st_mode) == 0)
+               atf_tc_fail_nonfatal("invalid mode from mknod(2) (S_IFBLK)");
+
+       ATF_REQUIRE(unlink(path) == 0);
+
+       (void)memset(&st, 0, sizeof(struct stat));
+
+       ATF_REQUIRE(mknod(path, S_IFREG, 0) == 0);
+       ATF_REQUIRE(stat(path, &st) == 0);
+
+       if (S_ISREG(st.st_mode) == 0)
+               atf_tc_fail_nonfatal("invalid mode from mknod(2) (S_IFREG)");
+
+       ATF_REQUIRE(unlink(path) == 0);
+}
+
+ATF_TC_CLEANUP(mknod_stat, tc)
+{
+       (void)unlink(path);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, mknod_err);
+       ATF_TP_ADD_TC(tp, mknod_perm);
+       ATF_TP_ADD_TC(tp, mknod_stat);
+
+       return atf_no_error();
+}



Home | Main Index | Thread Index | Old Index