summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLOLi <[email protected]>2017-05-02 22:43:53 +0200
committerBrian Behlendorf <[email protected]>2017-05-02 13:43:53 -0700
commite7fbeb606a18b9f04daadddc19b9c4f9a9b34841 (patch)
tree8b9e4a464343553bc5d8b01ca1dd25b917a73990 /tests
parent03b60eee78b0bf1125878dbad0fcffd717def61f (diff)
Add zfs_nicebytes() to print human-readable sizes
* Add zfs_nicebytes() to print human-readable sizes Some 'zfs', 'zpool' and 'zdb' output strings can be confusing to the user when no units are specified. This add a new zfs_nicenum_format "ZFS_NICENUM_BYTES" used to print bytes in their human-readable form. Additionally, update some test cases to use machine-parsable 'zfs get'. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: loli10K <[email protected]> Closes #2414 Closes #3185 Closes #3594 Closes #6032
Diffstat (limited to 'tests')
-rw-r--r--tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib8
-rwxr-xr-xtests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh8
-rw-r--r--tests/zfs-tests/tests/functional/cli_root/zfs_create/properties.kshlib14
-rw-r--r--tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib2
-rwxr-xr-xtests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_021_pos.ksh6
-rwxr-xr-xtests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_022_pos.ksh6
-rwxr-xr-xtests/zfs-tests/tests/functional/userquota/userquota_004_pos.ksh9
-rw-r--r--tests/zfs-tests/tests/functional/userquota/userquota_common.kshlib2
8 files changed, 28 insertions, 27 deletions
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib
index 5114a1c61..a86b2f78f 100644
--- a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib
+++ b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib
@@ -58,11 +58,7 @@ function get_used_prop
typeset ds=$1
typeset used
- used=`zfs list -H -o used $ds`
- used=${used%[m|M]}
- if [[ $used == *K ]]; then
- used=0
- fi
+ used=`zfs list -H -p -o used $ds`
echo $used
}
@@ -79,7 +75,7 @@ function check_used
typeset -i cfactor
typeset -i fsize=${FILESIZE%[m|M]}
- ((used = ${charged_spc%[m|M]}))
+ ((used = $charged_spc / 1024 / 1024))
((cfactor = used / fsize))
if ((cfactor != expected_cfactor)); then
log_fail "The space is not charged correctly while setting" \
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh
index 68f907e0b..a5a9729dc 100755
--- a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh
+++ b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh
@@ -88,20 +88,22 @@ else
fi
for val in 1 2 3; do
blks=`ls -ls /$TESTPOOL/fs_$val/$FILE | awk '{print $1}'`
- (( used = blks * $blksize / (1024 * 1024) ))
+ (( used = blks * $blksize )) # bytes
check_used $used $val
done
log_note "Verify df(1M) can corectly display the space charged."
for val in 1 2 3; do
- used=`df -F zfs -h /$TESTPOOL/fs_$val/$FILE | grep $TESTPOOL/fs_$val \
+ used=`df -F zfs -k /$TESTPOOL/fs_$val/$FILE | grep $TESTPOOL/fs_$val \
| awk '{print $3}'`
+ (( used = used * 1024 )) # kb -> bytes
check_used $used $val
done
log_note "Verify du(1) can correctly display the space charged."
for val in 1 2 3; do
- used=`du -h /$TESTPOOL/fs_$val/$FILE | awk '{print $1}'`
+ used=`du -k /$TESTPOOL/fs_$val/$FILE | awk '{print $1}'`
+ (( used = used * 1024 )) # kb -> bytes
check_used $used $val
done
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/properties.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_create/properties.kshlib
index cf3568679..00b5ad8bd 100644
--- a/tests/zfs-tests/tests/functional/cli_root/zfs_create/properties.kshlib
+++ b/tests/zfs-tests/tests/functional/cli_root/zfs_create/properties.kshlib
@@ -28,9 +28,9 @@
# Copyright (c) 2012, 2015 by Delphix. All rights reserved.
#
-set -A RW_FS_PROP "quota=512M" \
- "reservation=512M" \
- "recordsize=256K" \
+set -A RW_FS_PROP "quota=536870912" \
+ "reservation=536870912" \
+ "recordsize=262144" \
"mountpoint=/tmp/mnt$$" \
"checksum=fletcher2" \
"compression=lzjb" \
@@ -43,7 +43,7 @@ set -A RW_FS_PROP "quota=512M" \
"canmount=off" \
"local:department=123"
-set -A RW_VOL_PROP "volblocksize=16K" \
+set -A RW_VOL_PROP "volblocksize=16384" \
"checksum=fletcher2" \
"compression=lzjb" \
"readonly=on" \
@@ -54,8 +54,8 @@ set -A RW_VOL_CLONE_PROP "checksum=fletcher2" \
"readonly=on" \
"local:department=123"
-set -A FS_ONLY_PROP "quota=512M" \
- "recordsize=64K" \
+set -A FS_ONLY_PROP "quota=536870912" \
+ "recordsize=65536" \
"mountpoint=/tmp/mnt$$" \
"atime=off" \
"devices=off" \
@@ -66,4 +66,4 @@ set -A FS_ONLY_PROP "quota=512M" \
"canmount=off" \
"version=1"
-set -A VOL_ONLY_PROP "volblocksize=16K" "volsize=512M"
+set -A VOL_ONLY_PROP "volblocksize=16384" "volsize=536870912"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib
index 222b8e8f5..4c3f8b908 100644
--- a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib
+++ b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib
@@ -43,7 +43,7 @@ function propertycheck
typeset prop=$(echo $propstr | awk -F= '{print $1}')
typeset expect_value=$(echo $propstr | awk -F= '{print $2}')
- typeset value=$(zfs get -H -o value $prop $dtst)
+ typeset value=$(zfs get -H -p -o value $prop $dtst)
if [[ "$expect_value" == "$value" ]]; then
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_021_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_021_pos.ksh
index f049d147d..8f64c9d44 100755
--- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_021_pos.ksh
+++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_021_pos.ksh
@@ -56,9 +56,9 @@ log_onexit cleanup
log_assert "'zpool create -O property=value pool' can successfully create a pool \
with correct filesystem property set."
-set -A RW_FS_PROP "quota=512M" \
- "reservation=512M" \
- "recordsize=64K" \
+set -A RW_FS_PROP "quota=536870912" \
+ "reservation=536870912" \
+ "recordsize=262144" \
"mountpoint=/tmp/mnt$$" \
"checksum=fletcher2" \
"compression=lzjb" \
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_022_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_022_pos.ksh
index 48025e987..4e6d25512 100755
--- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_022_pos.ksh
+++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_022_pos.ksh
@@ -56,9 +56,9 @@ log_onexit cleanup
log_assert "'zpool create -O property=value pool' can successfully create a pool \
with multiple filesystem properties set."
-set -A RW_FS_PROP "quota=512M" \
- "reservation=512M" \
- "recordsize=64K" \
+set -A RW_FS_PROP "quota=536870912" \
+ "reservation=536870912" \
+ "recordsize=262144" \
"mountpoint=/tmp/mnt$$" \
"checksum=fletcher2" \
"compression=lzjb" \
diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_004_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userquota_004_pos.ksh
index 36433fa29..ae748e2c6 100755
--- a/tests/zfs-tests/tests/functional/userquota/userquota_004_pos.ksh
+++ b/tests/zfs-tests/tests/functional/userquota/userquota_004_pos.ksh
@@ -53,6 +53,7 @@ log_assert "Check the basic function of {user|group} used"
sync_pool
typeset user_used=$(get_value "userused@$QUSER1" $QFS)
typeset group_used=$(get_value "groupused@$QGROUP" $QFS)
+typeset file_size='100m'
if [[ $user_used != 0 ]]; then
log_fail "FAIL: userused is $user_used, should be 0"
@@ -62,15 +63,17 @@ if [[ $group_used != 0 ]]; then
fi
mkmount_writable $QFS
-log_must user_run $QUSER1 mkfile 100m $QFILE
+log_must user_run $QUSER1 mkfile $file_size $QFILE
sync_pool
user_used=$(get_value "userused@$QUSER1" $QFS)
group_used=$(get_value "groupused@$QGROUP" $QFS)
-if [[ $user_used != "100M" ]]; then
+# get_value() reads the exact byte value which is slightly more than 100m
+if [[ "$(($user_used/1024/1024))m" != "$file_size" ]]; then
log_note "user $QUSER1 used is $user_used"
- log_fail "userused for user $QUSER1 expected to be 50.0M, not $user_used"
+ log_fail "userused for user $QUSER1 expected to be $file_size, " \
+ "not $user_used"
fi
if [[ $user_used != $group_used ]]; then
diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_common.kshlib b/tests/zfs-tests/tests/functional/userquota/userquota_common.kshlib
index 299fd5a7d..70b935d7f 100644
--- a/tests/zfs-tests/tests/functional/userquota/userquota_common.kshlib
+++ b/tests/zfs-tests/tests/functional/userquota/userquota_common.kshlib
@@ -111,7 +111,7 @@ function get_value # property dataset
typeset prop=$1
typeset dataset=$2
- prop_val=$(zfs get -H -o value $prop $dataset 2>/dev/null)
+ prop_val=$(zfs get -H -p -o value $prop $dataset 2>/dev/null)
if [[ $? -ne 0 ]]; then
log_note "Unable to get $prop property for dataset " \
"$dataset"