aboutsummaryrefslogtreecommitdiff
path: root/sys/contrib/openzfs/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.list_user_props.ksh
blob: a454a27533028fe2b48278c3a22856651906e8d6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/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 (c) 2017 by Delphix. All rights reserved.
#

. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib

#
# DESCRIPTION:
#       Listing zfs user properties should work correctly.
#
#       Note, that this file tests both zfs.list.user_properties
#       and it's alias zfs.list.properties.
#

verify_runnable "global"

TESTPROP="org.openzfs:test_property"
TESTPROP1=$TESTPROP-1
TESTPROP2=$TESTPROP-2
TESTPROP3=$TESTPROP-3
TESTPROP4=$TESTPROP-4

TESTVAL="true"
TESTVAL1="busy"
TESTVAL2="9223372036854775808"
TESTVAL3="801f2266-3715-41f4-9080-3d5e913b0f15"
TESTVAL4="TOZwOfACvQtmDyiq68elB3a3g9YYyxBjSnLtN3ZyQYNOAKykzIE2khKKOBncJiDx"


# 0 properties handled correctly
log_must_program $TESTPOOL - <<-EOF
	n = 0
	for p in zfs.list.user_properties("$TESTPOOL/$TESTFS") do
		n = n + 1
	end
	assert(n == 0)
	return 0
EOF
log_must_program $TESTPOOL - <<-EOF
	n = 0
	for p in zfs.list.properties("$TESTPOOL/$TESTFS") do
		n = n + 1
	end
	assert(n == 0)
	return 0
EOF

# Add a single user property
log_must zfs set $TESTPROP="$TESTVAL" $TESTPOOL/$TESTFS

log_must_program $TESTPOOL - <<-EOF
	n = 0
	for p,v in zfs.list.user_properties("$TESTPOOL/$TESTFS") do
		assert(p == "$TESTPROP")
		assert(v == "$TESTVAL")
		n = n + 1
	end
	assert(n == 1)
	return 0
EOF
log_must_program $TESTPOOL - <<-EOF
	n = 0
	for p,v in zfs.list.properties("$TESTPOOL/$TESTFS") do
		assert(p == "$TESTPROP")
		assert(v == "$TESTVAL")
		n = n + 1
	end
	assert(n == 1)
	return 0
EOF

log_must zfs set $TESTPROP1="$TESTVAL1" $TESTPOOL/$TESTFS
log_must zfs set $TESTPROP2="$TESTVAL2" $TESTPOOL/$TESTFS
log_must zfs set $TESTPROP3="$TESTVAL3" $TESTPOOL/$TESTFS
log_must zfs set $TESTPROP4="$TESTVAL4" $TESTPOOL/$TESTFS

# All user properties have correct value and appear exactly once
log_must_program $TESTPOOL - <<-EOF
	a = {}
	a["$TESTPROP"] = false
	a["$TESTPROP1"] = false
	a["$TESTPROP2"] = false
	a["$TESTPROP3"] = false
	a["$TESTPROP4"] = false
	m = {}
	m["$TESTPROP"] = "$TESTVAL"
	m["$TESTPROP1"] = "$TESTVAL1"
	m["$TESTPROP2"] = "$TESTVAL2"
	m["$TESTPROP3"] = "$TESTVAL3"
	m["$TESTPROP4"] = "$TESTVAL4"
	n = 0
	for p,v in zfs.list.user_properties("$TESTPOOL/$TESTFS") do
		assert(not a[p])
		a[p] = true
		assert(v == m[p])
		n = n + 1
	end
	assert(n == 5)
	assert(a["$TESTPROP"] and
	    a["$TESTPROP1"] and
	    a["$TESTPROP2"] and
	    a["$TESTPROP3"] and
	    a["$TESTPROP4"])
	return 0
EOF
log_must_program $TESTPOOL - <<-EOF
	a = {}
	a["$TESTPROP"] = false
	a["$TESTPROP1"] = false
	a["$TESTPROP2"] = false
	a["$TESTPROP3"] = false
	a["$TESTPROP4"] = false
	m = {}
	m["$TESTPROP"] = "$TESTVAL"
	m["$TESTPROP1"] = "$TESTVAL1"
	m["$TESTPROP2"] = "$TESTVAL2"
	m["$TESTPROP3"] = "$TESTVAL3"
	m["$TESTPROP4"] = "$TESTVAL4"
	n = 0
	for p,v in zfs.list.properties("$TESTPOOL/$TESTFS") do
		assert(not a[p])
		a[p] = true
		assert(v == m[p])
		n = n + 1
	end
	assert(n == 5)
	assert(a["$TESTPROP"] and
	    a["$TESTPROP1"] and
	    a["$TESTPROP2"] and
	    a["$TESTPROP3"] and
	    a["$TESTPROP4"])
	return 0
EOF

log_pass "Listing zfs user properties should work correctly."