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 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
15#
16
17. $STF_SUITE/include/libtest.shlib
18
19#
20# DESCRIPTION:
21# 'zpool set' should be able to enable features on pools
22#
23# STRATEGY:
24# 1. Create a pool with all features disabled
25# 2. Verify 'zpool set' is able to enable a single feature
26# 3. Create a pool with all features enabled
27# 4. Verify 'zpool set' is *not* able to disable a single feature
28# 5. Rinse and repeat for known features
29#
30
31verify_runnable "both"
32
33function cleanup
34{
35	destroy_pool $TESTPOOL1
36	rm -f $FILEVDEV
37}
38
39log_assert "'zpool set' should be able to enable features on pools"
40log_onexit cleanup
41
42typeset -a features=(
43    "async_destroy"
44    "large_blocks"
45    "hole_birth"
46    "large_dnode"
47    "userobj_accounting"
48    "encryption"
49)
50FILEVDEV="$TEST_BASE_DIR/zpool_set_features.$$.dat"
51
52# Verify 'zpool set' is able to enable a single feature
53for feature in "${features[@]}"
54do
55	propname="feature@$feature"
56	truncate -s $SPA_MINDEVSIZE $FILEVDEV
57	log_must zpool create -d -f $TESTPOOL1 $FILEVDEV
58	log_must zpool set "$propname=enabled" $TESTPOOL1
59	propval="$(get_pool_prop $propname $TESTPOOL1)"
60	log_must test "$propval" ==  'enabled' -o "$propval" ==  'active'
61	cleanup
62done
63# Verify 'zpool set' is *not* able to disable a single feature
64for feature in "${features[@]}"
65do
66	propname="feature@$feature"
67	truncate -s $SPA_MINDEVSIZE $FILEVDEV
68	log_must zpool create -f $TESTPOOL1 $FILEVDEV
69	log_mustnot zpool set "$propname=disabled" $TESTPOOL1
70	propval="$(get_pool_prop $propname $TESTPOOL1)"
71	log_must test "$propval" ==  'enabled' -o "$propval" ==  'active'
72	cleanup
73done
74
75log_pass "'zpool set' can enable features on pools"
76