Add tests for mknod(2).

Submitted by:	Jan Senolt <senoltj@centrum.cz>
Submitted by:	Milan Cermak <Milan.Cermak@Sun.COM>
Polished by:	pjd
This commit is contained in:
Pawel Jakub Dawidek 2010-08-06 20:51:39 +00:00
parent ce29a12f91
commit bbbc67e6ff
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=210967
12 changed files with 408 additions and 0 deletions

View File

@ -0,0 +1,73 @@
#!/bin/sh
# $FreeBSD$
desc="mknod creates fifo files"
dir=`dirname $0`
. ${dir}/../misc.sh
echo "1..36"
n0=`namegen`
n1=`namegen`
expect 0 mkdir ${n1} 0755
cdir=`pwd`
cd ${n1}
# POSIX: The file permission bits of the new FIFO shall be initialized from
# mode. The file permission bits of the mode argument shall be modified by the
# process' file creation mask.
expect 0 mknod ${n0} f 0755 0 0
expect fifo,0755 lstat ${n0} type,mode
expect 0 unlink ${n0}
expect 0 mknod ${n0} f 0151 0 0
expect fifo,0151 lstat ${n0} type,mode
expect 0 unlink ${n0}
expect 0 -U 077 mknod ${n0} f 0151 0 0
expect fifo,0100 lstat ${n0} type,mode
expect 0 unlink ${n0}
expect 0 -U 070 mknod ${n0} f 0345 0 0
expect fifo,0305 lstat ${n0} type,mode
expect 0 unlink ${n0}
expect 0 -U 0501 mknod ${n0} f 0345 0 0
expect fifo,0244 lstat ${n0} type,mode
expect 0 unlink ${n0}
# POSIX: The FIFO's user ID shall be set to the process' effective user ID.
# The FIFO's group ID shall be set to the group ID of the parent directory or to
# the effective group ID of the process.
expect 0 chown . 65535 65535
expect 0 -u 65535 -g 65535 mknod ${n0} f 0755 0 0
expect 65535,65535 lstat ${n0} uid,gid
expect 0 unlink ${n0}
expect 0 -u 65535 -g 65534 mknod ${n0} f 0755 0 0
expect "65535,6553[45]" lstat ${n0} uid,gid
expect 0 unlink ${n0}
expect 0 chmod . 0777
expect 0 -u 65534 -g 65533 mknod ${n0} f 0755 0 0
expect "65534,6553[35]" lstat ${n0} uid,gid
expect 0 unlink ${n0}
# POSIX: Upon successful completion, mkfifo() shall mark for update the
# st_atime, st_ctime, and st_mtime fields of the file. Also, the st_ctime and
# st_mtime fields of the directory that contains the new entry shall be marked
# for update.
expect 0 chown . 0 0
time=`${fstest} stat . ctime`
sleep 1
expect 0 mknod ${n0} f 0755 0 0
atime=`${fstest} stat ${n0} atime`
test_check $time -lt $atime
mtime=`${fstest} stat ${n0} mtime`
test_check $time -lt $mtime
ctime=`${fstest} stat ${n0} ctime`
test_check $time -lt $ctime
mtime=`${fstest} stat . mtime`
test_check $time -lt $mtime
ctime=`${fstest} stat . ctime`
test_check $time -lt $ctime
expect 0 unlink ${n0}
cd ${cdir}
expect 0 rmdir ${n1}

View File

@ -0,0 +1,18 @@
#!/bin/sh
# $FreeBSD$
desc="mknod returns ENOTDIR if a component of the path prefix is not a directory"
dir=`dirname $0`
. ${dir}/../misc.sh
echo "1..5"
n0=`namegen`
n1=`namegen`
expect 0 mkdir ${n0} 0755
expect 0 create ${n0}/${n1} 0644
expect ENOTDIR mknod ${n0}/${n1}/test f 0644 0 0
expect 0 unlink ${n0}/${n1}
expect 0 rmdir ${n0}

View File

@ -0,0 +1,13 @@
#!/bin/sh
# $FreeBSD$
desc="mknod returns ENAMETOOLONG if a component of a pathname exceeded 255 characters"
dir=`dirname $0`
. ${dir}/../misc.sh
echo "1..3"
expect 0 mknod ${name255} f 0644 0 0
expect 0 unlink ${name255}
expect ENAMETOOLONG mknod ${name256} f 0644 0 0

View File

@ -0,0 +1,21 @@
#!/bin/sh
# $FreeBSD$
desc="mknod returns ENAMETOOLONG if an entire path name exceeded 1023 characters"
dir=`dirname $0`
. ${dir}/../misc.sh
echo "1..11"
expect 0 mkdir ${name255} 0755 # 1
expect 0 mkdir ${name255}/${name255} 0755 # 2
expect 0 mkdir ${name255}/${name255}/${name255} 0755 # 3
expect 0 mkdir ${path1021} 0755 # 4
expect 0 mknod ${path1023} f 0644 0 0 # 5
expect 0 unlink ${path1023} # 6
expect ENAMETOOLONG mknod ${path1024} f 0644 0 0 # 7
expect 0 rmdir ${path1021} # 8
expect 0 rmdir ${name255}/${name255}/${name255} # 9
expect 0 rmdir ${name255}/${name255} # 10
expect 0 rmdir ${name255} # 11

View File

@ -0,0 +1,16 @@
#!/bin/sh
# $FreeBSD$
desc="mkfifo returns ENOENT if a component of the path prefix does not exist"
dir=`dirname $0`
. ${dir}/../misc.sh
echo "1..3"
n0=`namegen`
n1=`namegen`
expect 0 mkdir ${n0} 0755
expect ENOENT mknod ${n0}/${n1}/test f 0644 0 0
expect 0 rmdir ${n0}

View File

@ -0,0 +1,29 @@
#!/bin/sh
# $FreeBSD$
desc="mknod returns EACCES when search permission is denied for a component of the path prefix"
dir=`dirname $0`
. ${dir}/../misc.sh
echo "1..12"
n0=`namegen`
n1=`namegen`
n2=`namegen`
expect 0 mkdir ${n0} 0755
cdir=`pwd`
cd ${n0}
expect 0 mkdir ${n1} 0755
expect 0 chown ${n1} 65534 65534
expect 0 -u 65534 -g 65534 mknod ${n1}/${n2} f 0644 0 0
expect 0 -u 65534 -g 65534 unlink ${n1}/${n2}
expect 0 chmod ${n1} 0644
expect EACCES -u 65534 -g 65534 mknod ${n1}/${n2} f 0644 0 0
expect 0 chmod ${n1} 0755
expect 0 -u 65534 -g 65534 mknod ${n1}/${n2} f 0644 0 0
expect 0 -u 65534 -g 65534 unlink ${n1}/${n2}
expect 0 rmdir ${n1}
cd ${cdir}
expect 0 rmdir ${n0}

View File

@ -0,0 +1,29 @@
#!/bin/sh
# $FreeBSD$
desc="mknod returns EACCES when write permission is denied on the parent directory of the file to be created"
dir=`dirname $0`
. ${dir}/../misc.sh
echo "1..12"
n0=`namegen`
n1=`namegen`
n2=`namegen`
expect 0 mkdir ${n0} 0755
cdir=`pwd`
cd ${n0}
expect 0 mkdir ${n1} 0755
expect 0 chown ${n1} 65534 65534
expect 0 -u 65534 -g 65534 mknod ${n1}/${n2} f 0644 0 0
expect 0 -u 65534 -g 65534 unlink ${n1}/${n2}
expect 0 chmod ${n1} 0555
expect EACCES -u 65534 -g 65534 mknod ${n1}/${n2} f 0644 0 0
expect 0 chmod ${n1} 0755
expect 0 -u 65534 -g 65534 mknod ${n1}/${n2} f 0644 0 0
expect 0 -u 65534 -g 65534 unlink ${n1}/${n2}
expect 0 rmdir ${n1}
cd ${cdir}
expect 0 rmdir ${n0}

View File

@ -0,0 +1,19 @@
#!/bin/sh
# $FreeBSD$
desc="mknod returns ELOOP if too many symbolic links were encountered in translating the pathname"
dir=`dirname $0`
. ${dir}/../misc.sh
echo "1..6"
n0=`namegen`
n1=`namegen`
expect 0 symlink ${n0} ${n1}
expect 0 symlink ${n1} ${n0}
expect ELOOP mknod ${n0}/test f 0644 0 0
expect ELOOP mknod ${n1}/test f 0644 0 0
expect 0 unlink ${n0}
expect 0 unlink ${n1}

View File

@ -0,0 +1,35 @@
#!/bin/sh
# $FreeBSD$
desc="mknod returns EEXIST if the named file exists"
dir=`dirname $0`
. ${dir}/../misc.sh
echo "1..18"
n0=`namegen`
expect 0 mkdir ${n0} 0755
expect EEXIST mknod ${n0} f 0644 0 0
expect 0 rmdir ${n0}
expect 0 create ${n0} 0644
expect EEXIST mknod ${n0} f 0644 0 0
expect 0 unlink ${n0}
expect 0 symlink test ${n0}
expect EEXIST mknod ${n0} f 0644 0 0
expect 0 unlink ${n0}
expect 0 mkfifo ${n0} 0644
expect EEXIST mknod ${n0} f 0644 0 0
expect 0 unlink ${n0}
expect 0 bind ${n0}
expect EEXIST mknod ${n0} f 0644 0 0
expect 0 unlink ${n0}
expect 0 mknod ${n0} f 0644 0 0
expect EEXIST mknod ${n0} f 0644 0 0
expect 0 unlink ${n0}

View File

@ -0,0 +1,64 @@
#!/bin/sh
# $FreeBSD$
desc="mknod returns EPERM if the parent directory of the file to be created has its immutable flag set"
dir=`dirname $0`
. ${dir}/../misc.sh
require chflags
case "${os}:${fs}" in
FreeBSD:UFS)
echo "1..30"
;;
*)
echo "1..17"
;;
esac
n0=`namegen`
n1=`namegen`
expect 0 mkdir ${n0} 0755
expect 0 mknod ${n0}/${n1} f 0644 0 0
expect 0 unlink ${n0}/${n1}
expect 0 chflags ${n0} SF_IMMUTABLE
expect EPERM mknod ${n0}/${n1} f 0644 0 0
expect 0 chflags ${n0} none
expect 0 mknod ${n0}/${n1} f 0644 0 0
expect 0 unlink ${n0}/${n1}
expect 0 chflags ${n0} SF_APPEND
expect 0 mknod ${n0}/${n1} f 0644 0 0
expect 0 chflags ${n0} none
expect 0 unlink ${n0}/${n1}
expect 0 chflags ${n0} SF_NOUNLINK
expect 0 mknod ${n0}/${n1} f 0644 0 0
expect 0 unlink ${n0}/${n1}
expect 0 chflags ${n0} none
case "${os}:${fs}" in
FreeBSD:UFS)
expect 0 chflags ${n0} UF_IMMUTABLE
expect EPERM mknod ${n0}/${n1} f 0644 0 0
expect 0 chflags ${n0} none
expect 0 mknod ${n0}/${n1} f 0644 0 0
expect 0 unlink ${n0}/${n1}
expect 0 chflags ${n0} UF_APPEND
expect 0 mknod ${n0}/${n1} f 0644 0 0
expect 0 chflags ${n0} none
expect 0 unlink ${n0}/${n1}
expect 0 chflags ${n0} UF_NOUNLINK
expect 0 mknod ${n0}/${n1} f 0644 0 0
expect 0 unlink ${n0}/${n1}
expect 0 chflags ${n0} none
;;
esac
expect 0 rmdir ${n0}

View File

@ -0,0 +1,12 @@
#!/bin/sh
# $FreeBSD$
desc="mknod returns EFAULT if the path argument points outside the process's allocated address space"
dir=`dirname $0`
. ${dir}/../misc.sh
echo "1..2"
expect EFAULT mknod NULL f 0644 0 0
expect EFAULT mknod DEADCODE f 0644 0 0

View File

@ -0,0 +1,79 @@
#!/bin/sh
# $FreeBSD$
desc="mknod creates device files"
dir=`dirname $0`
. ${dir}/../misc.sh
case "${os}" in
SunOS)
echo "1..40"
;;
*)
echo "1..28"
;;
esac
n0=`namegen`
n1=`namegen`
expect 0 mkdir ${n1} 0755
cdir=`pwd`
cd ${n1}
for type in c b; do
case "${type}" in
c)
stattype="char"
;;
b)
stattype="block"
;;
esac
# Create char special with old-style numbers
expect 0 mknod ${n0} ${type} 0755 1 2
expect ${stattype},0755 lstat ${n0} type,mode
expect 1,2 lstat ${n0} major,minor
expect EEXIST mknod ${n0} ${type} 0777 3 4
expect 0 unlink ${n0}
case "${os}" in
SunOS)
# Create char special with new-style numbers
expect 0 mknod ${n0} ${type} 0755 4095 4095
expect ${stattype},0755 lstat ${n0} type,mode
expect 4095,4095 lstat ${n0} major,minor
expect EEXIST mknod ${n0} ${type} 0777 4000 4000
expect 0 unlink ${n0}
# mknod returns EINVAL if device's numbers are too big
# for 32-bit solaris !!
expect EINVAL mknod ${n0} ${type} 0755 4096 262144
;;
esac
# POSIX: Upon successful completion, mknod(2) shall mark for update the
# st_atime, st_ctime, and st_mtime fields of the file. Also, the st_ctime and
# st_mtime fields of the directory that contains the new entry shall be marked
# for update.
expect 0 chown . 0 0
time=`${fstest} stat . ctime`
sleep 1
expect 0 mknod ${n0} ${type} 0755 1 2
atime=`${fstest} stat ${n0} atime`
test_check $time -lt $atime
mtime=`${fstest} stat ${n0} mtime`
test_check $time -lt $mtime
ctime=`${fstest} stat ${n0} ctime`
test_check $time -lt $ctime
mtime=`${fstest} stat . mtime`
test_check $time -lt $mtime
ctime=`${fstest} stat . ctime`
test_check $time -lt $ctime
expect 0 unlink ${n0}
done
cd ${cdir}
expect 0 rmdir ${n1}