Add 'zfs diff' coverage to the ZFS Test Suite

This change adds four new tests to the ZTS:

 * zfs_diff_changes: verify type of changes diplayed (-, +, R and M)
 * zfs_diff_cliargs: verify command line options and arguments
 * zfs_diff_timestamp: verify 'zfs diff -t'
 * zfs_diff_types: verify type of objects (files, dirs, pipes...)

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: loli10K <ezomori.nozomu@gmail.com>
Closes #6686
This commit is contained in:
LOLi 2017-09-28 22:04:14 +02:00 committed by Brian Behlendorf
parent 269db7a4b3
commit b59b22972d
12 changed files with 518 additions and 0 deletions

View File

@ -188,6 +188,7 @@ AC_CONFIG_FILES([
tests/zfs-tests/tests/functional/cli_root/zfs_copies/Makefile tests/zfs-tests/tests/functional/cli_root/zfs_copies/Makefile
tests/zfs-tests/tests/functional/cli_root/zfs_create/Makefile tests/zfs-tests/tests/functional/cli_root/zfs_create/Makefile
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/Makefile tests/zfs-tests/tests/functional/cli_root/zfs_destroy/Makefile
tests/zfs-tests/tests/functional/cli_root/zfs_diff/Makefile
tests/zfs-tests/tests/functional/cli_root/zfs_get/Makefile tests/zfs-tests/tests/functional/cli_root/zfs_get/Makefile
tests/zfs-tests/tests/functional/cli_root/zfs_inherit/Makefile tests/zfs-tests/tests/functional/cli_root/zfs_inherit/Makefile
tests/zfs-tests/tests/functional/cli_root/zfs_load-key/Makefile tests/zfs-tests/tests/functional/cli_root/zfs_load-key/Makefile

View File

@ -104,6 +104,10 @@ tests = ['zfs_destroy_001_pos', 'zfs_destroy_002_pos', 'zfs_destroy_003_pos',
'zfs_destroy_013_neg', 'zfs_destroy_014_pos', 'zfs_destroy_015_pos', 'zfs_destroy_013_neg', 'zfs_destroy_014_pos', 'zfs_destroy_015_pos',
'zfs_destroy_016_pos'] 'zfs_destroy_016_pos']
[tests/functional/cli_root/zfs_diff]
tests = ['zfs_diff_changes', 'zfs_diff_cliargs', 'zfs_diff_timestamp',
'zfs_diff_types']
[tests/functional/cli_root/zfs_get] [tests/functional/cli_root/zfs_get]
tests = ['zfs_get_001_pos', 'zfs_get_002_pos', 'zfs_get_003_pos', tests = ['zfs_get_001_pos', 'zfs_get_002_pos', 'zfs_get_003_pos',
'zfs_get_004_pos', 'zfs_get_005_neg', 'zfs_get_006_neg', 'zfs_get_007_neg', 'zfs_get_004_pos', 'zfs_get_005_neg', 'zfs_get_006_neg', 'zfs_get_007_neg',

View File

@ -11,6 +11,7 @@ SUBDIRS = \
zfs_copies \ zfs_copies \
zfs_create \ zfs_create \
zfs_destroy \ zfs_destroy \
zfs_diff \
zfs_get \ zfs_get \
zfs_inherit \ zfs_inherit \
zfs_load-key \ zfs_load-key \

View File

@ -0,0 +1 @@
/socket

View File

@ -0,0 +1,16 @@
include $(top_srcdir)/config/Rules.am
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_diff
dist_pkgdata_SCRIPTS = \
cleanup.ksh \
setup.ksh \
zfs_diff_changes.ksh \
zfs_diff_cliargs.ksh \
zfs_diff_timestamp.ksh \
zfs_diff_types.ksh
pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_diff
pkgexec_PROGRAMS = socket
socket_SOURCES = socket.c

View File

@ -0,0 +1,19 @@
#!/bin/ksh -p
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
#
# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
default_cleanup

View File

@ -0,0 +1,21 @@
#!/bin/ksh -p
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
#
# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
DISK=${DISKS%% *}
default_volume_setup $DISK

View File

@ -0,0 +1,54 @@
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/
/*
* Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
*/
#include <fcntl.h>
#include <sys/un.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
/* ARGSUSED */
int
main(int argc, char *argv[])
{
struct sockaddr_un sock;
int fd;
char *path;
if (argc != 2) {
fprintf(stderr, "usage: %s /path/to/socket\n", argv[0]);
exit(1);
}
path = argv[1];
strncpy(sock.sun_path, (char *)path, sizeof (sock.sun_path));
sock.sun_family = AF_UNIX;
if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) {
perror("socket");
return (1);
}
if (bind(fd, (struct sockaddr *)&sock, sizeof (struct sockaddr_un))) {
perror("bind");
return (1);
}
if (close(fd)) {
perror("close");
return (1);
}
return (0);
}

View File

@ -0,0 +1,96 @@
#!/bin/ksh -p
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
#
# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
#
# DESCRIPTION:
# 'zfs diff' should display changes correctly.
#
# STRATEGY:
# 1. Create a filesystem with both files and directories, then snapshot it
# 2. Generate different types of changes and verify 'zfs diff' displays them
#
verify_runnable "both"
function cleanup
{
log_must zfs destroy -r "$DATASET"
rm -f "$FILEDIFF"
}
#
# Verify object $path has $change type
# Valid types are:
# * - (The path has been removed)
# * + (The path has been created)
# * M (The path has been modified)
# * R (The path has been renamed)
#
function verify_object_change # <path> <change>
{
path="$1"
change="$2"
log_must eval "zfs diff -F $TESTSNAP1 $TESTSNAP2 > $FILEDIFF"
diffchg="$(awk -v path="$path" '$NF == path { print $1 }' < $FILEDIFF)"
if [[ "$diffchg" != "$change" ]]; then
log_fail "Unexpected change for $path ('$diffchg' != '$change')"
else
log_note "Object $path change is displayed correctly: '$change'"
fi
}
log_assert "'zfs diff' should display changes correctly."
log_onexit cleanup
DATASET="$TESTPOOL/$TESTFS/fs"
TESTSNAP1="$DATASET@snap1"
TESTSNAP2="$DATASET@snap2"
FILEDIFF="$TESTDIR/zfs-diff.txt"
# 1. Create a filesystem with both files and directories, then snapshot it
log_must zfs create $DATASET
MNTPOINT="$(get_prop mountpoint $DATASET)"
log_must touch "$MNTPOINT/fremoved"
log_must touch "$MNTPOINT/frenamed"
log_must touch "$MNTPOINT/fmodified"
log_must mkdir "$MNTPOINT/dremoved"
log_must mkdir "$MNTPOINT/drenamed"
log_must mkdir "$MNTPOINT/dmodified"
log_must zfs snapshot "$TESTSNAP1"
# 2. Generate different types of changes and verify 'zfs diff' displays them
log_must rm -f "$MNTPOINT/fremoved"
log_must mv "$MNTPOINT/frenamed" "$MNTPOINT/frenamed.new"
log_must touch "$MNTPOINT/fmodified"
log_must rmdir "$MNTPOINT/dremoved"
log_must mv "$MNTPOINT/drenamed" "$MNTPOINT/drenamed.new"
log_must touch "$MNTPOINT/dmodified/file"
log_must touch "$MNTPOINT/fcreated"
log_must mkdir "$MNTPOINT/dcreated"
log_must zfs snapshot "$TESTSNAP2"
verify_object_change "$MNTPOINT/fremoved" "-"
verify_object_change "$MNTPOINT/frenamed.new" "R"
verify_object_change "$MNTPOINT/fmodified" "M"
verify_object_change "$MNTPOINT/fcreated" "+"
verify_object_change "$MNTPOINT/dremoved" "-"
verify_object_change "$MNTPOINT/drenamed.new" "R"
verify_object_change "$MNTPOINT/dmodified" "M"
verify_object_change "$MNTPOINT/dcreated" "+"
log_pass "'zfs diff' displays changes correctly."

View File

@ -0,0 +1,80 @@
#!/bin/ksh -p
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
#
# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
#
# DESCRIPTION:
# 'zfs diff' should only work with supported options.
#
# STRATEGY:
# 1. Create two snapshots
# 2. Verify every supported option is accepted
# 3. Verify supported options raise an error with unsupported arguments
# 4. Verify other unsupported options raise an error
#
verify_runnable "both"
function cleanup
{
for snap in $TESTSNAP1 $TESTSNAP2; do
if snapexists "$snap"; then
log_must zfs destroy "$snap"
fi
done
}
log_assert "'zfs diff' should only work with supported options."
log_onexit cleanup
typeset goodopts=("" "-F" "-H" "-t" "-FH" "-Ft" "-Ht" "-FHt")
typeset badopts=("-f" "-h" "-h" "-T" "-Fx" "-Ho" "-tT" "-")
DATASET="$TESTPOOL/$TESTFS"
TESTSNAP1="$DATASET@snap1"
TESTSNAP2="$DATASET@snap2"
# 1. Create two snapshots
log_must zfs snapshot "$TESTSNAP1"
log_must zfs snapshot "$TESTSNAP2"
# 2. Verify every supported option is accepted
for opt in ${goodopts[@]}
do
log_must zfs diff $opt "$TESTSNAP1"
log_must zfs diff $opt "$TESTSNAP1" "$DATASET"
log_must zfs diff $opt "$TESTSNAP1" "$TESTSNAP2"
done
# 3. Verify supported options raise an error with unsupported arguments
for opt in ${goodopts[@]}
do
log_mustnot zfs diff $opt
log_mustnot zfs diff $opt "$DATASET"
log_mustnot zfs diff $opt "$DATASET@noexists"
log_mustnot zfs diff $opt "$DATASET" "$TESTSNAP1"
log_mustnot zfs diff $opt "$TESTSNAP2" "$TESTSNAP1"
done
# 4. Verify other unsupported options raise an error
for opt in ${badopts[@]}
do
log_mustnot zfs diff $opt "$TESTSNAP1" "$DATASET"
log_mustnot zfs diff $opt "$TESTSNAP1" "$TESTSNAP2"
done
log_pass "'zfs diff' only works with supported options."

View File

@ -0,0 +1,100 @@
#!/bin/ksh -p
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
#
# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
#
# DESCRIPTION:
# 'zfs diff -t' should display inode change time correctly.
#
# STRATEGY:
# 1. Create a snapshot
# 2. Create some files with a random delay and snapshot the filesystem again
# 3. Verify 'zfs diff -t' correctly display timestamps
#
verify_runnable "both"
function cleanup
{
for snap in $TESTSNAP1 $TESTSNAP2; do
if snapexists "$snap"; then
log_must zfs destroy "$snap"
fi
done
find "$MNTPOINT" -type f -delete
rm -f "$FILEDIFF"
}
#
# Creates $count files in $fspath. Waits a random delay between each file.
#
function create_random # <fspath> <count>
{
fspath="$1"
typeset -i count="$2"
typeset -i i=0
while (( i < count )); do
log_must touch "$fspath/file$i"
sleep $(random 3)
(( i = i + 1 ))
done
}
log_assert "'zfs diff -t' should display inode change time correctly."
log_onexit cleanup
DATASET="$TESTPOOL/$TESTFS"
TESTSNAP1="$DATASET@snap1"
TESTSNAP2="$DATASET@snap2"
MNTPOINT="$(get_prop mountpoint $DATASET)"
FILEDIFF="$TESTDIR/zfs-diff.txt"
FILENUM=5
# 1. Create a snapshot
log_must zfs snapshot "$TESTSNAP1"
# 2. Create some files with a random delay and snapshot the filesystem again
create_random "$MNTPOINT" $FILENUM
log_must zfs snapshot "$TESTSNAP2"
# 3. Verify 'zfs diff -t' correctly display timestamps
typeset -i count=0
log_must eval "zfs diff -t $TESTSNAP1 $TESTSNAP2 > $FILEDIFF"
awk '{print substr($1,0,index($1,".")-1)" "$NF}' < "$FILEDIFF" | while read line
do
read ctime file <<< "$line"
# If path from 'zfs diff' is not a file (could be xattr object) skip it
if [[ ! -f "$file" ]]; then
continue;
fi
filetime="$(stat -c '%Z' $file)"
if [[ "$filetime" != "$ctime" ]]; then
log_fail "Unexpected ctime for file $file ($filetime != $ctime)"
else
log_note "Correct ctime read on $file: $ctime"
fi
(( i = i + 1 ))
done
if [[ $i != $FILENUM ]]; then
log_fail "Wrong number of files verified ($i != $FILENUM)"
fi
log_pass "'zfs diff -t' displays inode change time correctly."

View File

@ -0,0 +1,125 @@
#!/bin/ksh -p
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
#
# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
#
# DESCRIPTION:
# 'zfs diff -F' shows different object types correctly.
#
# STRATEGY:
# 1. Prepare a dataset
# 2. Create different objects and verify 'zfs diff -F' shows the correct type
#
verify_runnable "both"
function cleanup
{
log_must zfs destroy -r "$DATASET"
rm -f "$FILEDIFF"
}
#
# Verify object at $path is of type $symbol using 'zfs diff -F'
# Valid types are:
# * B (Block device)
# * C (Character device)
# * / (Directory)
# * > (Door)
# * | (Named pipe)
# * @ (Symbolic link)
# * P (Event port)
# * = (Socket)
# * F (Regular file)
#
function verify_object_class # <path> <symbol>
{
path="$1"
symbol="$2"
log_must eval "zfs diff -F $TESTSNAP1 $TESTSNAP2 > $FILEDIFF"
diffsym="$(awk -v path="$path" '$NF == path { print $2 }' < $FILEDIFF)"
if [[ "$diffsym" != "$symbol" ]]; then
log_fail "Unexpected type for $path ('$diffsym' != '$symbol')"
else
log_note "Object $path type is correctly displayed as '$symbol'"
fi
log_must zfs destroy "$TESTSNAP1"
log_must zfs destroy "$TESTSNAP2"
}
log_assert "'zfs diff -F' should show different object types correctly."
log_onexit cleanup
DATASET="$TESTPOOL/$TESTFS/fs"
TESTSNAP1="$DATASET@snap1"
TESTSNAP2="$DATASET@snap2"
FILEDIFF="$TESTDIR/zfs-diff.txt"
MAJOR=$(stat -c %t /dev/null)
MINOR=$(stat -c %T /dev/null)
# 1. Prepare a dataset
log_must zfs create $DATASET
MNTPOINT="$(get_prop mountpoint $DATASET)"
log_must zfs set devices=on $DATASET
log_must zfs set xattr=sa $DATASET
# 2. Create different objects and verify 'zfs diff -F' shows the correct type
# 2. F (Regular file)
log_must zfs snapshot "$TESTSNAP1"
log_must touch "$MNTPOINT/file"
log_must zfs snapshot "$TESTSNAP2"
verify_object_class "$MNTPOINT/file" "F"
# 2. @ (Symbolic link)
log_must zfs snapshot "$TESTSNAP1"
log_must ln -s "$MNTPOINT/file" "$MNTPOINT/link"
log_must zfs snapshot "$TESTSNAP2"
verify_object_class "$MNTPOINT/link" "@"
# 2. B (Block device)
log_must zfs snapshot "$TESTSNAP1"
log_must mknod "$MNTPOINT/bdev" b $MAJOR $MINOR
log_must zfs snapshot "$TESTSNAP2"
verify_object_class "$MNTPOINT/bdev" "B"
# 2. C (Character device)
log_must zfs snapshot "$TESTSNAP1"
log_must mknod "$MNTPOINT/cdev" c $MAJOR $MINOR
log_must zfs snapshot "$TESTSNAP2"
verify_object_class "$MNTPOINT/cdev" "C"
# 2. | (Named pipe)
log_must zfs snapshot "$TESTSNAP1"
log_must mknod "$MNTPOINT/fifo" p
log_must zfs snapshot "$TESTSNAP2"
verify_object_class "$MNTPOINT/fifo" "|"
# 2. / (Directory)
log_must zfs snapshot "$TESTSNAP1"
log_must mkdir "$MNTPOINT/dir"
log_must zfs snapshot "$TESTSNAP2"
verify_object_class "$MNTPOINT/dir" "/"
# 2. = (Socket)
log_must zfs snapshot "$TESTSNAP1"
log_must $STF_SUITE/tests/functional/cli_root/zfs_diff/socket "$MNTPOINT/sock"
log_must zfs snapshot "$TESTSNAP2"
verify_object_class "$MNTPOINT/sock" "="
log_pass "'zfs diff -F' shows different object types correctly."