1#!/usr/local/bin/ksh93 -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23# $FreeBSD$
24
25#
26# Copyright 2017 Spectra Logic Corp.  All rights reserved.
27# Use is subject to license terms.
28#
29
30. $STF_SUITE/include/libtest.kshlib
31. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib
32
33verify_runnable "both"
34
35log_assert "'zfs diff' output for typical operations"
36
37# First create a bunch of files and directories
38
39#log_must ${CD} $TESTDIR
40log_must ${MKDIR} ${TESTDIR}/dirs
41log_must ${MKDIR} ${TESTDIR}/dirs/leavealone
42log_must ${MKDIR} ${TESTDIR}/dirs/modify
43log_must ${MKDIR} ${TESTDIR}/dirs/rename
44log_must ${MKDIR} ${TESTDIR}/dirs/delete
45log_must ${MKDIR} ${TESTDIR}/files
46log_must ${TOUCH} ${TESTDIR}/files/leavealone
47log_must ${TOUCH} ${TESTDIR}/files/modify
48log_must ${TOUCH} ${TESTDIR}/files/rename
49log_must ${TOUCH} ${TESTDIR}/files/delete
50log_must ${MKDIR} ${TESTDIR}/files/srcdir
51log_must ${MKDIR} ${TESTDIR}/files/dstdir
52log_must ${TOUCH} ${TESTDIR}/files/srcdir/move
53
54log_must $ZFS snapshot $TESTPOOL/$TESTFS@1
55
56# Now modify them in different ways
57log_must ${TOUCH} ${TESTDIR}/dirs/modify
58log_must ${MV} ${TESTDIR}/dirs/rename ${TESTDIR}/dirs/rename.new
59log_must ${RMDIR} ${TESTDIR}/dirs/delete
60log_must ${MKDIR} ${TESTDIR}/dirs/create
61log_must ${DATE} >> ${TESTDIR}/files/modify
62log_must ${MV} ${TESTDIR}/files/rename ${TESTDIR}/files/rename.new
63log_must ${RM} ${TESTDIR}/files/delete
64log_must ${MV} ${TESTDIR}/files/srcdir/move ${TESTDIR}/files/dstdir/move
65log_must ${TOUCH} ${TESTDIR}/files/create
66
67log_must $ZFS snapshot $TESTPOOL/$TESTFS@2
68
69# "zfs diff"'s output order is unspecified, so we must sort it.  The golden
70# file is already sorted.
71LC_ALL=C $ZFS diff $TESTPOOL/$TESTFS@1 $TESTPOOL/$TESTFS@2 | ${SORT} > $TESTDIR/zfs_diff_output.txt
72if [ $? -ne 0 ]; then
73	log_fail "zfs diff failed"
74fi
75
76# Finally, compare output to the golden output
77log_must diff $STF_SUITE/tests/cli_root/zfs_diff/zfs_diff_001_pos.golden $TESTDIR/zfs_diff_output.txt
78
79log_pass "'zfs diff' gave the expected output"
80