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#
24# Copyright 2017 Spectra Logic Corp.  All rights reserved.
25# Use is subject to license terms.
26#
27
28. $STF_SUITE/include/libtest.kshlib
29. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib
30
31verify_runnable "both"
32
33log_assert "'zfs diff' output for typical operations"
34
35# First create a bunch of files and directories
36
37#log_must ${CD} $TESTDIR
38log_must ${MKDIR} ${TESTDIR}/dirs
39log_must ${MKDIR} ${TESTDIR}/dirs/leavealone
40log_must ${MKDIR} ${TESTDIR}/dirs/modify
41log_must ${MKDIR} ${TESTDIR}/dirs/rename
42log_must ${MKDIR} ${TESTDIR}/dirs/delete
43log_must ${MKDIR} ${TESTDIR}/files
44log_must ${TOUCH} ${TESTDIR}/files/leavealone
45log_must ${TOUCH} ${TESTDIR}/files/modify
46log_must ${TOUCH} ${TESTDIR}/files/rename
47log_must ${TOUCH} ${TESTDIR}/files/delete
48log_must ${MKDIR} ${TESTDIR}/files/srcdir
49log_must ${MKDIR} ${TESTDIR}/files/dstdir
50log_must ${TOUCH} ${TESTDIR}/files/srcdir/move
51
52log_must $ZFS snapshot $TESTPOOL/$TESTFS@1
53
54# Now modify them in different ways
55log_must ${TOUCH} ${TESTDIR}/dirs/modify
56log_must ${MV} ${TESTDIR}/dirs/rename ${TESTDIR}/dirs/rename.new
57log_must ${RMDIR} ${TESTDIR}/dirs/delete
58log_must ${MKDIR} ${TESTDIR}/dirs/create
59log_must ${DATE} >> ${TESTDIR}/files/modify
60log_must ${MV} ${TESTDIR}/files/rename ${TESTDIR}/files/rename.new
61log_must ${RM} ${TESTDIR}/files/delete
62log_must ${MV} ${TESTDIR}/files/srcdir/move ${TESTDIR}/files/dstdir/move
63log_must ${TOUCH} ${TESTDIR}/files/create
64
65log_must $ZFS snapshot $TESTPOOL/$TESTFS@2
66
67# "zfs diff"'s output order is unspecified, so we must sort it.  The golden
68# file is already sorted.
69LC_ALL=C $ZFS diff $TESTPOOL/$TESTFS@1 $TESTPOOL/$TESTFS@2 | ${SORT} > $TESTDIR/zfs_diff_output.txt
70if [ $? -ne 0 ]; then
71	log_fail "zfs diff failed"
72fi
73
74# Finally, compare output to the golden output
75log_must diff $STF_SUITE/tests/cli_root/zfs_diff/zfs_diff_001_pos.golden $TESTDIR/zfs_diff_output.txt
76
77log_pass "'zfs diff' gave the expected output"
78