# $FreeBSD: stable/11/contrib/pjdfstest/tests/misc.sh 296766 2016-03-12 19:41:38Z ngie $ setglobal ntest = '1' match $(dir) { with /* setglobal maindir = ""$(dir)/../.."" with * setglobal maindir = ""$[pwd]/$(dir)/../.."" } setglobal fstest = ""$(maindir)/pjdfstest"" source ${maindir}/tests/conf proc expect { setglobal e = $(1) shift setglobal r = $[$(fstest) $ifsjoin(ARGV) 2>/dev/null | tail -1] echo $(r) | $(GREP) -Eq '^'$(e)'$' if test $Status -eq 0 { if test -z $(todomsg) { echo "ok $(ntest)" } else { echo "ok $(ntest) # TODO $(todomsg)" } } else { if test -z $(todomsg) { echo "not ok $(ntest) - tried '$ifsjoin(ARGV)', expected $(e), got $(r)" } else { echo "not ok $(ntest) # TODO $(todomsg)" } } setglobal todomsg = ''"" setglobal ntest = $shExpr('ntest+1') } proc jexpect { setglobal s = $(1) setglobal d = $(2) setglobal e = $(3) shift 3 setglobal r = $[jail -s $(s) / pjdfstest 127.0.0.1 /bin/sh -c "cd $(d) && $(fstest) $ifsjoin(ARGV) 2>/dev/null" | tail -1] echo $(r) | $(GREP) -Eq '^'$(e)'$' if test $Status -eq 0 { if test -z $(todomsg) { echo "ok $(ntest)" } else { echo "ok $(ntest) # TODO $(todomsg)" } } else { if test -z $(todomsg) { echo "not ok $(ntest) - tried '$ifsjoin(ARGV)', expected $(e), got $(r)" } else { echo "not ok $(ntest) # TODO $(todomsg)" } } setglobal todomsg = ''"" setglobal ntest = $shExpr('ntest+1') } proc test_check { if test $ifsjoin(ARGV) { if test -z $(todomsg) { echo "ok $(ntest)" } else { echo "ok $(ntest) # TODO $(todomsg)" } } else { if test -z $(todomsg) { echo "not ok $(ntest)" } else { echo "not ok $(ntest) # TODO $(todomsg)" } } setglobal todomsg = ''"" setglobal ntest = $shExpr('ntest+1') } proc todo { if test $(os) = $(1) -o "$(os):$(fs)" = $(1) { setglobal todomsg = $(2) } } proc namegen { echo "pjdfstest_$[dd if=/dev/urandom bs=1k count=1 2>/dev/null | openssl md5 | awk '{print $NF}]" } proc namegen_len { setglobal len = $(1) setglobal name = ''"" while : { setglobal namepart = $[dd if=/dev/urandom bs=64 count=1 2>/dev/null | openssl md5 | awk '{print $NF}] setglobal name = ""$(name)$(namepart)"" setglobal curlen = $[printf "%s" $(name) | wc -c] test $(curlen) -lt $(len) || break } setglobal name = $[echo $(name) | cut -b -$(len)] printf "%s" $(name) } # POSIX: # {NAME_MAX} # Maximum number of bytes in a filename (not including terminating null). proc namegen_max { setglobal name_max = $[$(fstest) pathconf . _PC_NAME_MAX] namegen_len $(name_max) } # POSIX: # {PATH_MAX} # Maximum number of bytes in a pathname, including the terminating null character. proc dirgen_max { setglobal name_max = $[$(fstest) pathconf . _PC_NAME_MAX] setglobal complen = $shExpr('name_max/2') setglobal path_max = $[$(fstest) pathconf . _PC_PATH_MAX] # "...including the terminating null character." setglobal path_max = $shExpr('path_max-1') setglobal name = ''"" while : { setglobal name = ""$(name)$[namegen_len $(complen)]/"" setglobal curlen = $[printf "%s" $(name) | wc -c] test $(curlen) -lt $(path_max) || break } setglobal name = $[echo $(name) | cut -b -$(path_max)] setglobal name = $[echo $(name) | sed -E 's@/$@x@] printf "%s" $(name) } proc quick_exit { echo "1..1" echo "ok 1" exit 0 } proc supported { match $(1) { with lchmod if test $(os) != "FreeBSD" { return 1 } with chflags if test $(os) != "FreeBSD" { return 1 } with chflags_SF_SNAPSHOT if test $(os) != "FreeBSD" -o $(fs) != "UFS" { return 1 } } return 0 } proc require { if supported $(1) { return } quick_exit } # usage: # create_file # create_file # create_file # create_file proc create_file { setglobal type = $(1) setglobal name = $(2) match $(type) { with none return with regular expect 0 create $(name) 0644 with dir expect 0 mkdir $(name) 0755 with fifo expect 0 mkfifo $(name) 0644 with block expect 0 mknod $(name) b 0644 1 2 with char expect 0 mknod $(name) c 0644 1 2 with socket expect 0 bind $(name) with symlink expect 0 symlink test $(name) } if test -n $(3) -a -n $(4) -a -n $(5) { expect 0 lchmod $(name) $(3) expect 0 lchown $(name) $(4) $(5) } elif test -n $(3) -a -n $(4) { expect 0 lchown $(name) $(3) $(4) } elif test -n $(3) { expect 0 lchmod $(name) $(3) } } # Tests for whether or not a filesystem is mounted with a particular option # with -o, e.g. `mount -o noexec`. # # Parameters: # - mount_option - noatime, noexec, etc. # # Returns: # - 0 if mounted with the option. # - 1 otherwise. proc has_mount_option { local IFS=, local mount_opt local mount_option_search=$1 # XXX: mountpoint is defined in .../tests/sys/pjdfstest/tests/conf for mount_opt in [$[mount -d -p | awk '$2 == "'$mountpoint'" { print $4 }]] { if test $mount_opt = $mount_option_search { return 0 } } return 1 } # Filesystem must be mounted with -o exec proc requires_exec { if has_mount_option noexec { echo "1..0 # SKIP filesystem mounted with -o noexec" exit 0 } }