Skip to content

Commit

Permalink
Integrate test fixes (openzfs#96)
Browse files Browse the repository at this point in the history
* fix python3 compat in zfs_clone_010

* Fix broken diff test on FreeBSD

* Fix test script setup on FreeBSD

* fix multipath disk detection in tests on FreeBSD

* Skip MMP testfail callbacks on FreeBSD, for now

* Add gpart and mdconfig commands to test sandbox

* Fix delete_partitions in libtest

* Skip ext2 test on FreeBSD and ufs test on Linux

* Just use the ksh print built-in, it works

Fixes "\n" appearing in log messages instead of newlines on FreeBSD.

* Fix erroneous assertion

* Fix zfs_diff_types test on FreeBSD

On FreeBSD, mknod can't be used to create named pipes.
Use mkfifo instead.

ZoF Issue: openzfs#46

* s/\[ is_freebsd \]/is_freebsd/ in tests

Calling a function in a test expression doesn't work like that.
This only appeared to work on FreeBSD because `[ is_freebsd ]` is
always true and `[ ! is_freebsd ]` is always false.

* Use `mount -p` to check mount options on FreeBSD

* Merge FreeBSD and Linux cases in some tests
  • Loading branch information
Ryan Moeller authored May 1, 2019
1 parent 620e33c commit cf4017b
Show file tree
Hide file tree
Showing 99 changed files with 228 additions and 289 deletions.
2 changes: 1 addition & 1 deletion lib/libzfs/libzfs_diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ differ(void *arg)
if (err)
return ((void *)-1);
if (di->zerr) {
ASSERT(di->zerr == EINVAL);
ASSERT(di->zerr == EPIPE);
(void) snprintf(di->errbuf, sizeof (di->errbuf),
dgettext(TEXT_DOMAIN,
"Internal error: bad data from diff IOCTL"));
Expand Down
14 changes: 8 additions & 6 deletions scripts/zfs-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ TAGS=""
ITERATIONS=1
ZFS_DBGMSG="$STF_SUITE/callbacks/zfs_dbgmsg.ksh"
ZFS_DMESG="$STF_SUITE/callbacks/zfs_dmesg.ksh"
ZFS_MMP="$STF_SUITE/callbacks/zfs_mmp.ksh"
TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DBGMSG:$ZFS_DMESG:$ZFS_MMP"}
LOSETUP=${LOSETUP:-/sbin/losetup}
DMSETUP=${DMSETUP:-/sbin/dmsetup}
UNAME=$(uname -s)

# Override some defaults if on FreeBSD
if [ "$UNAME" = "FreeBSD" ] ; then
TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DBGMSG:$ZFS_DMESG"}
LOSETUP=/sbin/mdconfig
DMSETUP=/sbin/gpart
else
ZFS_MMP="$STF_SUITE/callbacks/zfs_mmp.ksh"
TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DBGMSG:$ZFS_DMESG:$ZFS_MMP"}
LOSETUP=${LOSETUP:-/sbin/losetup}
DMSETUP=${DMSETUP:-/sbin/dmsetup}
fi

#
Expand Down Expand Up @@ -258,7 +260,7 @@ constrain_path() {
else
# Constrained path set to /var/tmp/constrained_path.*
SYSTEMDIR=${SYSTEMDIR:-/var/tmp/constrained_path.XXXX}
STF_PATH=$(/bin/mktemp -d "$SYSTEMDIR")
STF_PATH=$(mktemp -d "$SYSTEMDIR")
STF_PATH_REMOVE="yes"
STF_MISSING_BIN=""

Expand Down Expand Up @@ -505,7 +507,7 @@ if [ "$UNAME" = "FreeBSD" ] ; then
[ -e "/usr/local/bin/ksh93" ] || fail \
"Missing /usr/local/bin/ksh93 - Please install ksh93"
if [ ! -e "/bin/ksh" ] ; then
ln -s /usr/local/bin/ksh93 /bin/ksh
sudo ln -s /usr/local/bin/ksh93 /bin/ksh
fi
else
[ -e "$STF_PATH/ksh" ] || fail "This test suite requires ksh."
Expand Down
13 changes: 0 additions & 13 deletions tests/test-runner/include/logapi.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,6 @@

. ${STF_TOOLS}/include/stf.shlib

if [ "$(uname -o)" = "FreeBSD" ]; then

function print
{
if [ "$1" = "-u2" ] ; then
echo $@ | cut -d ' ' -f 2-
else
echo $@
fi
}

fi

# Output an assertion
#
# $@ - assertion text
Expand Down
13 changes: 12 additions & 1 deletion tests/zfs-tests/include/blkdev.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,17 @@ function is_loop_device #disk
}

#
# Linux:
# Check if the given device is a multipath device and if there is a sybolic
# link to a device mapper and to a disk
# Currently no support for dm devices alone without multipath
#
# FreeBSD:
# Check if the given device is a gmultipath device.
#
# Others:
# No multipath detection.
#
function is_mpath_device #disk
{
typeset disk=$1
Expand All @@ -136,6 +143,10 @@ function is_mpath_device #disk
else
return $?
fi
elif is_freebsd; then
test -b $DEV_MPATHDIR/$disk
else
false
fi
}

Expand Down Expand Up @@ -206,7 +217,7 @@ function get_device_dir #device
typeset device=$1

if ! $(is_physical_device $device) ; then
if [[ is_freebsd ]] ; then
if is_freebsd ; then
echo "/dev"
return 0
fi
Expand Down
3 changes: 3 additions & 0 deletions tests/zfs-tests/include/commands.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export SYSTEM_FILES='arp
getent
getfacl
getfattr
gpart
grep
groupadd
groupdel
Expand All @@ -72,7 +73,9 @@ export SYSTEM_FILES='arp
lsmod
lsscsi
md5sum
mdconfig
mkdir
mkfifo
mknod
mkswap
mktemp
Expand Down
1 change: 1 addition & 0 deletions tests/zfs-tests/include/default.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ elif is_freebsd; then
ZVOL_RDEVDIR="/dev/zvol"
DEV_DSKDIR="/dev"
DEV_RDSKDIR="/dev"
DEV_MPATHDIR="/dev/multipath"

NEWFS_DEFAULT_FS="ufs"
else
Expand Down
75 changes: 21 additions & 54 deletions tests/zfs-tests/include/libtest.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -959,64 +959,31 @@ function set_partition #<slice_num> <slice_start> <size_plus_units> <whole_disk
#
function delete_partitions
{
typeset -i j=1

if [[ -z $DISK_ARRAY_NUM ]]; then
DISK_ARRAY_NUM=$(echo ${DISKS} | nawk '{print NF}')
fi
if [[ -z $DISKSARRAY ]]; then
DISKSARRAY=$DISKS
fi

if is_linux; then
if (( $DISK_ARRAY_NUM == 1 )); then
while ((j < MAX_PARTITIONS)); do
parted $DEV_DSKDIR/$DISK -s rm $j \
> /dev/null 2>&1
if (( $? == 1 )); then
lsblk | egrep ${DISK}${SLICE_PREFIX}${j} > /dev/null
if (( $? == 1 )); then
log_note "Partitions for $DISK should be deleted"
else
log_fail "Partition for ${DISK}${SLICE_PREFIX}${j} not deleted"
fi
return 0
for disk in $DISKSARRAY; do
for (( j = 1; j < MAX_PARTITIONS; j++ )); do
typeset partition=${disk}${SLICE_PREFIX}${j}
parted $DEV_DSKDIR/$disk -s rm $j > /dev/null 2>&1
if lsblk | grep -qF ${partition}; then
log_fail "Partition ${partition} not deleted"
else
lsblk | egrep ${DISK}${SLICE_PREFIX}${j} > /dev/null
if (( $? == 0 )); then
log_fail "Partition for ${DISK}${SLICE_PREFIX}${j} not deleted"
fi
log_note "Partition ${partition} deleted"
fi
((j = j+1))
done
else
for disk in `echo $DISKSARRAY`; do
while ((j < MAX_PARTITIONS)); do
parted $DEV_DSKDIR/$disk -s rm $j > /dev/null 2>&1
if (( $? == 1 )); then
lsblk | egrep ${disk}${SLICE_PREFIX}${j} > /dev/null
if (( $? == 1 )); then
log_note "Partitions for $disk should be deleted"
else
log_fail "Partition for ${disk}${SLICE_PREFIX}${j} not deleted"
fi
j=7
else
lsblk | egrep ${disk}${SLICE_PREFIX}${j} > /dev/null
if (( $? == 0 )); then
log_fail "Partition for ${disk}${SLICE_PREFIX}${j} not deleted"
fi
fi
((j = j+1))
done
j=1
done
fi
done
elif is_freebsd; then
/sbin/gpart destroy -F $DEV_DSKDIR/$DISK
return $?
for disk in $DISKSARRAY; do
if gpart destroy -F $disk; then
log_note "Partitions for ${disk} deleted"
else
log_fail "Partitions for ${disk} not deleted"
fi
done
fi
return 0
}

#
Expand Down Expand Up @@ -2470,7 +2437,7 @@ function del_group_freebsd #<group_name>
#
function add_user #<group_name> <user_name> <basedir>
{
if [ is_freebsd ] ; then
if is_freebsd ; then
add_user_freebsd "$1" "$2" "$3"
return $?
fi
Expand Down Expand Up @@ -2507,7 +2474,7 @@ function add_user #<group_name> <user_name> <basedir>
#
function del_user #<logname> <basedir>
{
if [ is_freebsd ] ; then
if is_freebsd ; then
del_user_freebsd "$1" "$2"
return $?
fi
Expand Down Expand Up @@ -2535,7 +2502,7 @@ function del_user #<logname> <basedir>
#
function add_group #<group_name>
{
if [ is_freebsd ] ; then
if is_freebsd ; then
add_group_freebsd "$1"
return $?
fi
Expand Down Expand Up @@ -2579,7 +2546,7 @@ function add_group #<group_name>
#
function del_group #<group_name>
{
if [ is_freebsd ] ; then
if is_freebsd ; then
del_group_freebsd "$1"
return $?
fi
Expand Down Expand Up @@ -3185,7 +3152,7 @@ function user_run
shift

log_note "user:$user $@"
if [ is_freebsd ]; then
if is_freebsd; then
eval "su \$user -c \"$@\"" > $TEST_BASE_DIR/out 2>$TEST_BASE_DIR/err
return $?
else
Expand Down Expand Up @@ -3317,7 +3284,7 @@ function get_objnum
typeset objnum

[[ -e $pathname ]] || log_fail "No such file or directory: $pathname"
if [ is_freebsd ];then
if is_freebsd; then
objnum=$(stat -f "%i" $pathname)
else
objnum=$(stat -c %i $pathname)
Expand Down
2 changes: 1 addition & 1 deletion tests/zfs-tests/tests/functional/acl/posix/cleanup.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/acl/acl_common.kshlib

if [ is_freebsd ];then
if is_freebsd; then
log_unsupported "ACL tests not fully implemented on FreeBSD"
fi

Expand Down
2 changes: 1 addition & 1 deletion tests/zfs-tests/tests/functional/acl/posix/setup.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/acl/acl_common.kshlib

if [ is_freebsd ];then
if is_freebsd; then
log_unsupported "ACL tests not fully implemented on FreeBSD"
else
log_must getfacl --version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function log_program_construct_args
test -s /dev/stdin && cat > $tmpin

# test -s /dev/stdin doesn't work on FreeBSD
if [ is_freebsd ]; then
if is_freebsd; then
if [ "$1" = "-" ] ; then
cat > $tmpin
fi
Expand Down
8 changes: 4 additions & 4 deletions tests/zfs-tests/tests/functional/chattr/chattr_001_pos.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ set -A files writable immutable append
function cleanup
{
for i in ${files[*]}; do
if [ is_freebsd ] ; then
if is_freebsd ; then
log_must /bin/chflags noschg $TESTDIR/$i
log_must rm -f $TESTDIR/$i
else
Expand All @@ -60,7 +60,7 @@ function cleanup

log_onexit cleanup

if [ is_freebsd ] ; then
if is_freebsd ; then
log_assert "Check whether chflags works as expected"
else
log_assert "Check whether chattr works as expected"
Expand All @@ -70,7 +70,7 @@ log_must touch $TESTDIR/writable
log_must touch $TESTDIR/immutable
log_must touch $TESTDIR/append

if [ is_freebsd ] ; then
if is_freebsd ; then
log_must /bin/chflags noschg $TESTDIR/writable
log_must /bin/chflags schg $TESTDIR/immutable
log_must /bin/chflags sappnd $TESTDIR/append
Expand All @@ -87,7 +87,7 @@ log_mustnot eval "echo test >> $TESTDIR/immutable"
log_mustnot eval "echo test > $TESTDIR/append"
log_must eval "echo test >> $TESTDIR/append"

if [ is_freebsd ] ; then
if is_freebsd ; then
log_pass "chflags works as expected"
else
log_pass "chattr works as expected"
Expand Down
2 changes: 1 addition & 1 deletion tests/zfs-tests/tests/functional/chattr/chattr_002_neg.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# 3. Try to chattr with unprivileged user
#

if [ is_freebsd ] ; then
if is_freebsd ; then
log_unsupported "User flags not enabled on FreeBSD"
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ typeset -i i=1
while [[ $i -lt ${#CHECKSUM_TYPES[*]} ]]; do
type=${CHECKSUM_TYPES[i]}
# edonr not supported on FreeBSD
if [ is_freebsd -a "$type" = "edonr" ] ; then
if is_freebsd && [[ "$type" == "edonr" ]] ; then
(( i = i + 1 ))
continue
fi
Expand All @@ -106,7 +106,7 @@ typeset -i j=1
while [[ $j -lt ${#CHECKSUM_TYPES[*]} ]]; do
type=${CHECKSUM_TYPES[$j]}
# edonr not supported on FreeBSD
if [ is_freebsd -a "$type" = "edonr" ] ; then
if is_freebsd && [[ "$type" == "edonr" ]] ; then
(( j = j + 1 ))
continue
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function cleanup
datasetexists $TESTPOOL && destroy_pool $TESTPOOL
}

if [ is_freebsd ] ; then
if is_freebsd ; then
# FreeBSD won't allow writing to an in-use device without this set
log_must /sbin/sysctl kern.geom.debugflags=16
DEV_RDSKDIR="/dev"
Expand Down
4 changes: 2 additions & 2 deletions tests/zfs-tests/tests/functional/cli_root/zdb/zdb_004_pos.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# 7. Verify labels 0 and 1 have unique Uberblocks, but 2 and 3 have none
#

if [ is_freebsd ] ; then
if is_freebsd ; then
# FreeBSD won't allow writing to an in-use device without this set
log_must /sbin/sysctl kern.geom.debugflags=16
DEV_RDSKDIR="/dev"
Expand All @@ -51,7 +51,7 @@ function cleanup
verify_runnable "global"
verify_disk_count "$DISKS" 2
set -A DISK $DISKS
if [ is_freebsd ] ; then
if is_freebsd ; then
WHOLE_DISK=/dev/${DISK[0]}
else
WHOLE_DISK=${DISK[0]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

. $STF_SUITE/include/libtest.shlib

if [ is_freebsd ] ; then
if is_freebsd ; then
# FreeBSD won't allow writing to an in-use device without this set
log_must /sbin/sysctl kern.geom.debugflags=16
DEV_RDSKDIR="/dev"
Expand Down
Loading

0 comments on commit cf4017b

Please sign in to comment.