]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.list_children.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / channel_program / synctask_core / tst.list_children.ksh
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 (c) 2016 by Delphix. All rights reserved.
15 #
16
17 . $STF_SUITE/tests/functional/channel_program/channel_common.kshlib
18
19 #
20 # DESCRIPTION:
21 #       Listing zfs children should work correctly.
22 #
23
24 verify_runnable "global"
25
26 log_assert "Listing zfs children should work correctly."
27
28 TESTCHILD=$TESTPOOL/$TESTFS/testchild
29 TESTCHILD1=$TESTCHILD-1
30 TESTCHILD2=$TESTCHILD-2
31 TESTCHILD3=$TESTCHILD-3
32
33 function cleanup
34 {
35         destroy_dataset $TESTCHILD
36         destroy_dataset $TESTCHILD1
37         destroy_dataset $TESTCHILD2
38         destroy_dataset $TESTCHILD3
39 }
40
41 log_onexit cleanup
42
43 # 0 children handled correctly
44 log_must_program $TESTPOOL - <<-EOF
45         n = 0
46         for s in zfs.list.children("$TESTPOOL/$TESTFS") do
47                 n = n + 1
48         end
49         assert(n == 0)
50         return 0
51 EOF
52
53 log_must_program $TESTPOOL - <<-EOF
54         n = 0
55         for s in zfs.list.children("$TESTPOOL") do
56                 assert(s == "$TESTPOOL/$TESTFS")
57                 n = n + 1
58         end
59         assert(n == 1)
60         return 0
61 EOF
62
63 # Create a child fs
64 log_must zfs create $TESTCHILD
65
66 log_must_program $TESTPOOL - <<-EOF
67         n = 0
68         for s in zfs.list.children("$TESTPOOL/$TESTFS") do
69                 assert(s == "$TESTCHILD")
70                 n = n + 1
71         end
72         assert(n == 1)
73         return 0
74 EOF
75
76 log_must zfs create $TESTCHILD1
77 log_must zfs create $TESTCHILD2
78 log_must zfs create $TESTCHILD3
79
80 # All children appear exactly once
81 log_must_program $TESTPOOL - <<-EOF
82         a = {}
83         a["$TESTCHILD"] = false
84         a["$TESTCHILD1"] = false
85         a["$TESTCHILD2"] = false
86         a["$TESTCHILD3"] = false
87         n = 0
88         for s in zfs.list.children("$TESTPOOL/$TESTFS") do
89                 assert(not a[s])
90                 a[s] = true
91                 n = n + 1
92         end
93         assert(n == 4)
94         assert(a["$TESTCHILD"] and
95             a["$TESTCHILD1"] and
96             a["$TESTCHILD2"] and
97             a["$TESTCHILD3"])
98         return 0
99 EOF
100
101 # Bad input
102 log_mustnot_program $TESTPOOL - <<-EOF
103         zfs.list.children("$TESTPOOL/not-a-fs")
104         return 0
105 EOF
106
107 log_mustnot_program $TESTPOOL - <<-EOF
108         zfs.list.children("not-a-pool/$TESTFS")
109         return 0
110 EOF
111
112 # Can't look in a different pool than the one specified on command line
113 log_mustnot_program $TESTPOOL - <<-EOF
114         zfs.list.children("rpool")
115         return 0
116 EOF
117
118 create_snapshot
119 log_mustnot_program $TESTPOOL - <<-EOF
120         zfs.list.children("$TESTPOOL/$TESTFS@$TESTSNAP")
121         return 0
122 EOF
123 destroy_snapshot
124
125 log_pass "Listing zfs children should work correctly."