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

This commit is contained in:
jruoho 2011-07-03 14:34:21 +00:00
parent cac6cf8528
commit 8ce73eddfe
3 changed files with 169 additions and 3 deletions

View File

@ -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

View File

@ -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_access t_cmsg t_dup t_fsync
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

164
tests/syscall/t_mknod.c Normal file
View File

@ -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();
}