Skip to content

Commit b59b229

Browse files
loli10Kbehlendorf
authored andcommitted
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 <[email protected]> Reviewed-by: John Wren Kennedy <[email protected]> Signed-off-by: loli10K <[email protected]> Closes openzfs#6686
1 parent 269db7a commit b59b229

12 files changed

+518
-0
lines changed

configure.ac

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ AC_CONFIG_FILES([
188188
tests/zfs-tests/tests/functional/cli_root/zfs_copies/Makefile
189189
tests/zfs-tests/tests/functional/cli_root/zfs_create/Makefile
190190
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/Makefile
191+
tests/zfs-tests/tests/functional/cli_root/zfs_diff/Makefile
191192
tests/zfs-tests/tests/functional/cli_root/zfs_get/Makefile
192193
tests/zfs-tests/tests/functional/cli_root/zfs_inherit/Makefile
193194
tests/zfs-tests/tests/functional/cli_root/zfs_load-key/Makefile

tests/runfiles/linux.run

+4
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ tests = ['zfs_destroy_001_pos', 'zfs_destroy_002_pos', 'zfs_destroy_003_pos',
104104
'zfs_destroy_013_neg', 'zfs_destroy_014_pos', 'zfs_destroy_015_pos',
105105
'zfs_destroy_016_pos']
106106

107+
[tests/functional/cli_root/zfs_diff]
108+
tests = ['zfs_diff_changes', 'zfs_diff_cliargs', 'zfs_diff_timestamp',
109+
'zfs_diff_types']
110+
107111
[tests/functional/cli_root/zfs_get]
108112
tests = ['zfs_get_001_pos', 'zfs_get_002_pos', 'zfs_get_003_pos',
109113
'zfs_get_004_pos', 'zfs_get_005_neg', 'zfs_get_006_neg', 'zfs_get_007_neg',

tests/zfs-tests/tests/functional/cli_root/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SUBDIRS = \
1111
zfs_copies \
1212
zfs_create \
1313
zfs_destroy \
14+
zfs_diff \
1415
zfs_get \
1516
zfs_inherit \
1617
zfs_load-key \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/socket
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
include $(top_srcdir)/config/Rules.am
2+
3+
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_diff
4+
5+
dist_pkgdata_SCRIPTS = \
6+
cleanup.ksh \
7+
setup.ksh \
8+
zfs_diff_changes.ksh \
9+
zfs_diff_cliargs.ksh \
10+
zfs_diff_timestamp.ksh \
11+
zfs_diff_types.ksh
12+
13+
pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_diff
14+
15+
pkgexec_PROGRAMS = socket
16+
socket_SOURCES = socket.c
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/ksh -p
2+
#
3+
# This file and its contents are supplied under the terms of the
4+
# Common Development and Distribution License ("CDDL"), version 1.0.
5+
# You may only use this file in accordance with the terms of version
6+
# 1.0 of the CDDL.
7+
#
8+
# A full copy of the text of the CDDL should have accompanied this
9+
# source. A copy of the CDDL is also available via the Internet at
10+
# http://www.illumos.org/license/CDDL.
11+
#
12+
13+
#
14+
# Copyright 2017, loli10K <[email protected]>. All rights reserved.
15+
#
16+
17+
. $STF_SUITE/include/libtest.shlib
18+
19+
default_cleanup
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/ksh -p
2+
#
3+
# This file and its contents are supplied under the terms of the
4+
# Common Development and Distribution License ("CDDL"), version 1.0.
5+
# You may only use this file in accordance with the terms of version
6+
# 1.0 of the CDDL.
7+
#
8+
# A full copy of the text of the CDDL should have accompanied this
9+
# source. A copy of the CDDL is also available via the Internet at
10+
# http://www.illumos.org/license/CDDL.
11+
#
12+
13+
#
14+
# Copyright 2017, loli10K <[email protected]>. All rights reserved.
15+
#
16+
17+
. $STF_SUITE/include/libtest.shlib
18+
19+
DISK=${DISKS%% *}
20+
21+
default_volume_setup $DISK
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* This file and its contents are supplied under the terms of the
3+
* Common Development and Distribution License ("CDDL"), version 1.0.
4+
* You may only use this file in accordance with the terms of version
5+
* 1.0 of the CDDL.
6+
*
7+
* A full copy of the text of the CDDL should have accompanied this
8+
* source. A copy of the CDDL is also available via the Internet at
9+
* http://www.illumos.org/license/CDDL.
10+
*/
11+
12+
/*
13+
* Copyright 2017, loli10K <[email protected]>. All rights reserved.
14+
*/
15+
16+
#include <fcntl.h>
17+
#include <sys/un.h>
18+
#include <sys/socket.h>
19+
#include <sys/stat.h>
20+
#include <sys/types.h>
21+
#include <unistd.h>
22+
#include <errno.h>
23+
#include <stdio.h>
24+
#include <stdlib.h>
25+
26+
/* ARGSUSED */
27+
int
28+
main(int argc, char *argv[])
29+
{
30+
struct sockaddr_un sock;
31+
int fd;
32+
char *path;
33+
34+
if (argc != 2) {
35+
fprintf(stderr, "usage: %s /path/to/socket\n", argv[0]);
36+
exit(1);
37+
}
38+
path = argv[1];
39+
strncpy(sock.sun_path, (char *)path, sizeof (sock.sun_path));
40+
sock.sun_family = AF_UNIX;
41+
if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) {
42+
perror("socket");
43+
return (1);
44+
}
45+
if (bind(fd, (struct sockaddr *)&sock, sizeof (struct sockaddr_un))) {
46+
perror("bind");
47+
return (1);
48+
}
49+
if (close(fd)) {
50+
perror("close");
51+
return (1);
52+
}
53+
return (0);
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/ksh -p
2+
#
3+
# This file and its contents are supplied under the terms of the
4+
# Common Development and Distribution License ("CDDL"), version 1.0.
5+
# You may only use this file in accordance with the terms of version
6+
# 1.0 of the CDDL.
7+
#
8+
# A full copy of the text of the CDDL should have accompanied this
9+
# source. A copy of the CDDL is also available via the Internet at
10+
# http://www.illumos.org/license/CDDL.
11+
#
12+
13+
#
14+
# Copyright 2017, loli10K <[email protected]>. All rights reserved.
15+
#
16+
17+
. $STF_SUITE/include/libtest.shlib
18+
19+
#
20+
# DESCRIPTION:
21+
# 'zfs diff' should display changes correctly.
22+
#
23+
# STRATEGY:
24+
# 1. Create a filesystem with both files and directories, then snapshot it
25+
# 2. Generate different types of changes and verify 'zfs diff' displays them
26+
#
27+
28+
verify_runnable "both"
29+
30+
function cleanup
31+
{
32+
log_must zfs destroy -r "$DATASET"
33+
rm -f "$FILEDIFF"
34+
}
35+
36+
#
37+
# Verify object $path has $change type
38+
# Valid types are:
39+
# * - (The path has been removed)
40+
# * + (The path has been created)
41+
# * M (The path has been modified)
42+
# * R (The path has been renamed)
43+
#
44+
function verify_object_change # <path> <change>
45+
{
46+
path="$1"
47+
change="$2"
48+
49+
log_must eval "zfs diff -F $TESTSNAP1 $TESTSNAP2 > $FILEDIFF"
50+
diffchg="$(awk -v path="$path" '$NF == path { print $1 }' < $FILEDIFF)"
51+
if [[ "$diffchg" != "$change" ]]; then
52+
log_fail "Unexpected change for $path ('$diffchg' != '$change')"
53+
else
54+
log_note "Object $path change is displayed correctly: '$change'"
55+
fi
56+
}
57+
58+
log_assert "'zfs diff' should display changes correctly."
59+
log_onexit cleanup
60+
61+
DATASET="$TESTPOOL/$TESTFS/fs"
62+
TESTSNAP1="$DATASET@snap1"
63+
TESTSNAP2="$DATASET@snap2"
64+
FILEDIFF="$TESTDIR/zfs-diff.txt"
65+
66+
# 1. Create a filesystem with both files and directories, then snapshot it
67+
log_must zfs create $DATASET
68+
MNTPOINT="$(get_prop mountpoint $DATASET)"
69+
log_must touch "$MNTPOINT/fremoved"
70+
log_must touch "$MNTPOINT/frenamed"
71+
log_must touch "$MNTPOINT/fmodified"
72+
log_must mkdir "$MNTPOINT/dremoved"
73+
log_must mkdir "$MNTPOINT/drenamed"
74+
log_must mkdir "$MNTPOINT/dmodified"
75+
log_must zfs snapshot "$TESTSNAP1"
76+
77+
# 2. Generate different types of changes and verify 'zfs diff' displays them
78+
log_must rm -f "$MNTPOINT/fremoved"
79+
log_must mv "$MNTPOINT/frenamed" "$MNTPOINT/frenamed.new"
80+
log_must touch "$MNTPOINT/fmodified"
81+
log_must rmdir "$MNTPOINT/dremoved"
82+
log_must mv "$MNTPOINT/drenamed" "$MNTPOINT/drenamed.new"
83+
log_must touch "$MNTPOINT/dmodified/file"
84+
log_must touch "$MNTPOINT/fcreated"
85+
log_must mkdir "$MNTPOINT/dcreated"
86+
log_must zfs snapshot "$TESTSNAP2"
87+
verify_object_change "$MNTPOINT/fremoved" "-"
88+
verify_object_change "$MNTPOINT/frenamed.new" "R"
89+
verify_object_change "$MNTPOINT/fmodified" "M"
90+
verify_object_change "$MNTPOINT/fcreated" "+"
91+
verify_object_change "$MNTPOINT/dremoved" "-"
92+
verify_object_change "$MNTPOINT/drenamed.new" "R"
93+
verify_object_change "$MNTPOINT/dmodified" "M"
94+
verify_object_change "$MNTPOINT/dcreated" "+"
95+
96+
log_pass "'zfs diff' displays changes correctly."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/ksh -p
2+
#
3+
# This file and its contents are supplied under the terms of the
4+
# Common Development and Distribution License ("CDDL"), version 1.0.
5+
# You may only use this file in accordance with the terms of version
6+
# 1.0 of the CDDL.
7+
#
8+
# A full copy of the text of the CDDL should have accompanied this
9+
# source. A copy of the CDDL is also available via the Internet at
10+
# http://www.illumos.org/license/CDDL.
11+
#
12+
13+
#
14+
# Copyright 2017, loli10K <[email protected]>. All rights reserved.
15+
#
16+
17+
. $STF_SUITE/include/libtest.shlib
18+
19+
#
20+
# DESCRIPTION:
21+
# 'zfs diff' should only work with supported options.
22+
#
23+
# STRATEGY:
24+
# 1. Create two snapshots
25+
# 2. Verify every supported option is accepted
26+
# 3. Verify supported options raise an error with unsupported arguments
27+
# 4. Verify other unsupported options raise an error
28+
#
29+
30+
verify_runnable "both"
31+
32+
function cleanup
33+
{
34+
for snap in $TESTSNAP1 $TESTSNAP2; do
35+
if snapexists "$snap"; then
36+
log_must zfs destroy "$snap"
37+
fi
38+
done
39+
}
40+
41+
log_assert "'zfs diff' should only work with supported options."
42+
log_onexit cleanup
43+
44+
typeset goodopts=("" "-F" "-H" "-t" "-FH" "-Ft" "-Ht" "-FHt")
45+
typeset badopts=("-f" "-h" "-h" "-T" "-Fx" "-Ho" "-tT" "-")
46+
47+
DATASET="$TESTPOOL/$TESTFS"
48+
TESTSNAP1="$DATASET@snap1"
49+
TESTSNAP2="$DATASET@snap2"
50+
51+
# 1. Create two snapshots
52+
log_must zfs snapshot "$TESTSNAP1"
53+
log_must zfs snapshot "$TESTSNAP2"
54+
55+
# 2. Verify every supported option is accepted
56+
for opt in ${goodopts[@]}
57+
do
58+
log_must zfs diff $opt "$TESTSNAP1"
59+
log_must zfs diff $opt "$TESTSNAP1" "$DATASET"
60+
log_must zfs diff $opt "$TESTSNAP1" "$TESTSNAP2"
61+
done
62+
63+
# 3. Verify supported options raise an error with unsupported arguments
64+
for opt in ${goodopts[@]}
65+
do
66+
log_mustnot zfs diff $opt
67+
log_mustnot zfs diff $opt "$DATASET"
68+
log_mustnot zfs diff $opt "$DATASET@noexists"
69+
log_mustnot zfs diff $opt "$DATASET" "$TESTSNAP1"
70+
log_mustnot zfs diff $opt "$TESTSNAP2" "$TESTSNAP1"
71+
done
72+
73+
# 4. Verify other unsupported options raise an error
74+
for opt in ${badopts[@]}
75+
do
76+
log_mustnot zfs diff $opt "$TESTSNAP1" "$DATASET"
77+
log_mustnot zfs diff $opt "$TESTSNAP1" "$TESTSNAP2"
78+
done
79+
80+
log_pass "'zfs diff' only works with supported options."

0 commit comments

Comments
 (0)