xfs: test mkfs.xfs config files
authorDarrick J. Wong <darrick.wong@oracle.com>
Tue, 27 Oct 2020 20:54:50 +0000 (07:54 +1100)
committerEryu Guan <guaneryu@gmail.com>
Sun, 24 Jan 2021 15:15:13 +0000 (23:15 +0800)
Simple tests of the upcoming mkfs.xfs config file feature.  First we
have some simple tests of properly formatted config files, then
improperly formatted config files, and finally we try to spot
conflicts between config file options and the cli.

[dchinner: updated for new libinih-based implementation.]

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
12 files changed:
common/xfs
tests/xfs/522 [new file with mode: 0755]
tests/xfs/522.out [new file with mode: 0644]
tests/xfs/523 [new file with mode: 0755]
tests/xfs/523.out [new file with mode: 0644]
tests/xfs/524 [new file with mode: 0755]
tests/xfs/524.out [new file with mode: 0644]
tests/xfs/525 [new file with mode: 0755]
tests/xfs/525.out [new file with mode: 0644]
tests/xfs/526 [new file with mode: 0755]
tests/xfs/526.out [new file with mode: 0644]
tests/xfs/group

index 3f5c14b..2156749 100644 (file)
@@ -720,6 +720,16 @@ _require_xfs_mkfs_ciname()
                || _notrun "need case-insensitive naming support in mkfs.xfs"
 }
 
+# this test requires mkfs.xfs have configuration file support
+_require_xfs_mkfs_cfgfile()
+{
+       echo > /tmp/a
+       _scratch_mkfs_xfs_supported -c options=/tmp/a >/dev/null 2>&1
+       res=$?
+       rm -rf /tmp/a
+       test $res -eq 0 || _notrun "need configuration file support in mkfs.xfs"
+}
+
 # XFS_DEBUG requirements
 _require_xfs_debug()
 {
diff --git a/tests/xfs/522 b/tests/xfs/522
new file mode 100755 (executable)
index 0000000..4b9dbc9
--- /dev/null
@@ -0,0 +1,219 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2020 Oracle.  All Rights Reserved.
+#
+# FS QA Test No. 522
+#
+# Feed valid mkfs config files to the mkfs parser to ensure that they are
+# recognized as valid.
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1       # failure is the default!
+trap '_cleanup; exit $status' 0 1 2 3 15
+
+_cleanup()
+{
+       cd /
+       rm -f $tmp.* $def_cfgfile $fsimg
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs xfs
+_require_test
+_require_scratch_nocheck
+_require_xfs_mkfs_cfgfile
+
+def_cfgfile=$TEST_DIR/a
+fsimg=$TEST_DIR/a.img
+rm -f $def_cfgfile $fsimg
+$XFS_IO_PROG -c "truncate 20t" -f $fsimg
+
+test_mkfs_config() {
+       local cfgfile="$1"
+       if [ -z "$cfgfile" ] || [ "$cfgfile" = "-" ]; then
+               cfgfile=$def_cfgfile
+               cat > $cfgfile
+       fi
+       $MKFS_XFS_PROG -c options=$cfgfile -f -N $fsimg >> $seqres.full 2> $tmp.err
+       cat $tmp.err | _filter_test_dir
+}
+
+echo Simplest config file
+cat > $def_cfgfile << ENDL
+[metadata]
+crc = 0
+ENDL
+test_mkfs_config $def_cfgfile
+
+echo Piped-in config file
+test_mkfs_config << ENDL
+[metadata]
+crc = 0
+ENDL
+test_mkfs_config << ENDL
+[metadata]
+crc = 1
+ENDL
+
+echo Full line comment
+test_mkfs_config << ENDL
+# This is a full line comment.
+[metadata]
+crc = 0
+ENDL
+test_mkfs_config << ENDL
+ # This is a full line comment.
+[metadata]
+crc = 0
+ENDL
+test_mkfs_config << ENDL
+#This is a full line comment.
+[metadata]
+crc = 0
+ENDL
+
+echo End of line comment
+test_mkfs_config << ENDL
+[metadata]
+crc = 0 ; This is an eol comment.
+ENDL
+test_mkfs_config << ENDL
+[metadata]
+crc = 0 ;This is an eol comment.
+ENDL
+
+echo Multiple directives
+test_mkfs_config << ENDL
+[metadata]
+crc = 0
+finobt = 0
+ENDL
+
+echo Multiple sections
+test_mkfs_config << ENDL
+[metadata]
+crc = 0
+
+[inode]
+sparse = 0
+ENDL
+
+echo No directives at all
+test_mkfs_config << ENDL
+[metadata]
+ENDL
+
+echo Space around the section name
+test_mkfs_config << ENDL
+ [metadata]
+crc = 0
+ENDL
+test_mkfs_config << ENDL
+[metadata] 
+crc = 0
+ENDL
+test_mkfs_config << ENDL
+ [metadata] 
+crc = 0
+ENDL
+
+echo Single space around the key/value directive
+test_mkfs_config << ENDL
+[metadata]
+ crc=0
+ENDL
+test_mkfs_config << ENDL
+[metadata]
+crc =0
+ENDL
+test_mkfs_config << ENDL
+[metadata]
+crc= 0
+ENDL
+test_mkfs_config << ENDL
+[metadata]
+crc=0 
+ENDL
+
+echo Two spaces around the key/value directive
+test_mkfs_config << ENDL
+[metadata]
+ crc =0
+ENDL
+test_mkfs_config << ENDL
+[metadata]
+ crc= 0
+ENDL
+test_mkfs_config << ENDL
+[metadata]
+ crc=0 
+ENDL
+test_mkfs_config << ENDL
+[metadata]
+crc = 0
+ENDL
+test_mkfs_config << ENDL
+[metadata]
+crc =0 
+ENDL
+test_mkfs_config << ENDL
+[metadata]
+crc= 0 
+ENDL
+
+echo Three spaces around the key/value directive
+test_mkfs_config << ENDL
+[metadata]
+ crc = 0
+ENDL
+test_mkfs_config << ENDL
+[metadata]
+ crc= 0 
+ENDL
+test_mkfs_config << ENDL
+[metadata]
+crc = 0 
+ENDL
+
+echo Four spaces around the key/value directive
+test_mkfs_config << ENDL
+[metadata]
+ crc = 0 
+ENDL
+
+echo Arbitrary spaces and tabs
+test_mkfs_config << ENDL
+[metadata]
+         crc           =                0                        
+ENDL
+
+echo ambiguous comment/section names
+test_mkfs_config << ENDL
+[metadata]
+#[data]
+crc = 0
+ENDL
+
+echo ambiguous comment/variable names
+test_mkfs_config << ENDL
+[metadata]
+#foo = 0 ; is this a comment or a key '#foo' ?
+ENDL
+
+# success, all done
+status=0
+exit
diff --git a/tests/xfs/522.out b/tests/xfs/522.out
new file mode 100644 (file)
index 0000000..5a406a5
--- /dev/null
@@ -0,0 +1,16 @@
+QA output created by 522
+Simplest config file
+Piped-in config file
+Full line comment
+End of line comment
+Multiple directives
+Multiple sections
+No directives at all
+Space around the section name
+Single space around the key/value directive
+Two spaces around the key/value directive
+Three spaces around the key/value directive
+Four spaces around the key/value directive
+Arbitrary spaces and tabs
+ambiguous comment/section names
+ambiguous comment/variable names
diff --git a/tests/xfs/523 b/tests/xfs/523
new file mode 100755 (executable)
index 0000000..491414b
--- /dev/null
@@ -0,0 +1,195 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2020 Oracle.  All Rights Reserved.
+#
+# FS QA Test No. 523
+#
+# Feed invalid mkfs config files to the mkfs parser to ensure that they are
+# recognized as invalid.
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1       # failure is the default!
+trap '_cleanup; exit $status' 0 1 2 3 15
+
+_cleanup()
+{
+       cd /
+       rm -f $tmp.* $def_cfgfile $fsimg
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs xfs
+_require_test
+_require_scratch_nocheck
+_require_xfs_mkfs_cfgfile
+
+def_cfgfile=$TEST_DIR/a
+fsimg=$TEST_DIR/a.img
+rm -f $def_cfgfile $fsimg
+$XFS_IO_PROG -c "truncate 20t" -f $fsimg
+
+test_mkfs_config() {
+       local cfgfile="$1"
+       if [ -z "$cfgfile" ] || [ "$cfgfile" = "-" ]; then
+               cfgfile=$def_cfgfile
+               cat > $cfgfile
+       fi
+       $MKFS_XFS_PROG -c options=$cfgfile -f -N $fsimg >> $seqres.full 2> $tmp.err
+       if [ $? -eq 0 ]; then
+               echo "Test passed, should have failed! Config file parameters:"
+               cat $cfgfile
+       fi
+}
+
+echo Spaces in a section name
+test_mkfs_config << ENDL
+[meta data]
+crc = 0
+ENDL
+test_mkfs_config << ENDL
+[meta  data]
+crc = 0
+ENDL
+test_mkfs_config << ENDL
+[ metadata]
+crc = 0
+ENDL
+test_mkfs_config << ENDL
+[metadata ]
+crc = 0
+ENDL
+test_mkfs_config << ENDL
+[ metadata ]
+crc = 0
+ENDL
+test_mkfs_config << ENDL
+[ metadata] 
+crc = 0
+ENDL
+test_mkfs_config << ENDL
+[metadata ] 
+crc = 0
+ENDL
+test_mkfs_config << ENDL
+ [ metadata]
+crc = 0
+ENDL
+test_mkfs_config << ENDL
+ [metadata ]
+crc = 0
+ENDL
+test_mkfs_config << ENDL
+ [ metadata ]
+crc = 0
+ENDL
+test_mkfs_config << ENDL
+ [metadata ] 
+crc = 0
+ENDL
+test_mkfs_config << ENDL
+ [ metadata ] 
+crc = 0
+ENDL
+test_mkfs_config << ENDL
+                                [                              metadata                                          ]                             
+crc = 0
+ENDL
+
+echo Spaces in the middle of a key name
+test_mkfs_config << ENDL
+[metadata]
+c rc = 0
+ENDL
+
+echo Invalid value
+test_mkfs_config << ENDL
+[metadata]
+crc = waffles
+ENDL
+
+echo Nonexistent sections
+test_mkfs_config << ENDL
+[goober]
+crc = 0
+ENDL
+
+echo Nonexistent keys
+test_mkfs_config << ENDL
+[metadata]
+goober = 0
+ENDL
+
+echo Only zero or one
+test_mkfs_config << ENDL
+[metadata]
+crc = 50
+ENDL
+test_mkfs_config << ENDL
+[metadata]
+crc = -1
+ENDL
+
+echo sysctl style files
+test_mkfs_config << ENDL
+metadata.crc = 1
+ENDL
+
+echo binaries
+test_mkfs_config $MKFS_XFS_PROG 2>&1 | sed -e "s#$MKFS_XFS_PROG#MKFS_XFS_PROG#g"
+
+echo respecified options
+test_mkfs_config << ENDL
+[metadata]
+crc = 0
+crc = 1
+ENDL
+
+echo respecified sections
+test_mkfs_config << ENDL
+[metadata]
+crc = 0
+[metadata]
+crc = 1
+ENDL
+
+echo ambiguous comment/section names
+test_mkfs_config << ENDL
+[meta#data]
+crc = 0
+ENDL
+
+echo ambiguous comment/variable names
+test_mkfs_config << ENDL
+[metadata]
+fo#o = 0
+ENDL
+test_mkfs_config << ENDL
+[metadata]
+foo#=# 0
+ENDL
+test_mkfs_config << ENDL
+[metadata]
+foo =# 0
+ENDL
+test_mkfs_config << ENDL
+[metadata]
+crc = 0;This is an eol comment.
+ENDL
+
+# success, all done
+status=0
+exit
diff --git a/tests/xfs/523.out b/tests/xfs/523.out
new file mode 100644 (file)
index 0000000..92d71c4
--- /dev/null
@@ -0,0 +1,13 @@
+QA output created by 523
+Spaces in a section name
+Spaces in the middle of a key name
+Invalid value
+Nonexistent sections
+Nonexistent keys
+Only zero or one
+sysctl style files
+binaries
+respecified options
+respecified sections
+ambiguous comment/section names
+ambiguous comment/variable names
diff --git a/tests/xfs/524 b/tests/xfs/524
new file mode 100755 (executable)
index 0000000..8b53c1a
--- /dev/null
@@ -0,0 +1,65 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2020 Oracle.  All Rights Reserved.
+#
+# FS QA Test No. 524
+#
+# Test formatting with a well known config file.
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1       # failure is the default!
+trap '_cleanup; exit $status' 0 1 2 3 15
+
+_cleanup()
+{
+       cd /
+       rm -f $tmp.* $def_cfgfile $fsimg
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs xfs
+_require_test
+_require_scratch_nocheck
+_require_xfs_mkfs_cfgfile
+
+echo "Silence is golden"
+
+def_cfgfile=$TEST_DIR/a
+fsimg=$TEST_DIR/a.img
+rm -f $def_cfgfile $fsimg
+$XFS_IO_PROG -c "truncate 20t" -f $fsimg
+
+cat > $def_cfgfile << ENDL
+[metadata]
+crc = 1
+rmapbt = 1
+reflink = 1
+
+[inode]
+sparse = 1
+ENDL
+
+$MKFS_XFS_PROG -c options=$def_cfgfile -f $SCRATCH_DEV > $tmp.mkfs
+cat $tmp.mkfs >> $seqres.full
+grep -q 'crc=1' $tmp.mkfs || echo 'v5 not enabled'
+grep -q 'rmapbt=1' $tmp.mkfs || echo 'rmap not enabled'
+grep -q 'reflink=1' $tmp.mkfs || echo 'reflink not enabled'
+grep -q 'sparse=1' $tmp.mkfs || echo 'sparse inodes not enabled'
+
+# success, all done
+status=0
+exit
diff --git a/tests/xfs/524.out b/tests/xfs/524.out
new file mode 100644 (file)
index 0000000..7af4ad0
--- /dev/null
@@ -0,0 +1,2 @@
+QA output created by 524
+Silence is golden
diff --git a/tests/xfs/525 b/tests/xfs/525
new file mode 100755 (executable)
index 0000000..cf10c8a
--- /dev/null
@@ -0,0 +1,62 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2020 Oracle.  All Rights Reserved.
+#
+# FS QA Test No. 525
+#
+# Test formatting with a config file that contains conflicting options.
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1       # failure is the default!
+trap '_cleanup; exit $status' 0 1 2 3 15
+
+_cleanup()
+{
+       cd /
+       rm -f $tmp.* $def_cfgfile
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs xfs
+_require_test
+_require_scratch_nocheck
+_require_xfs_mkfs_cfgfile
+
+echo "Silence is golden"
+
+def_cfgfile=$TEST_DIR/a
+rm -rf $def_cfgfile
+
+cat > $def_cfgfile << ENDL
+[metadata]
+crc = 0
+rmapbt = 1
+reflink = 1
+
+[inode]
+sparse = 1
+ENDL
+
+$MKFS_XFS_PROG -c options=$def_cfgfile -f $SCRATCH_DEV > $tmp.mkfs 2>&1
+if [ $? -eq 0 ]; then
+       echo "mkfs.xfs did not fail!"
+       cat $tmp.mkfs
+fi
+
+# success, all done
+status=0
+exit
diff --git a/tests/xfs/525.out b/tests/xfs/525.out
new file mode 100644 (file)
index 0000000..f160c37
--- /dev/null
@@ -0,0 +1,2 @@
+QA output created by 525
+Silence is golden
diff --git a/tests/xfs/526 b/tests/xfs/526
new file mode 100755 (executable)
index 0000000..9b57678
--- /dev/null
@@ -0,0 +1,64 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2020 Oracle.  All Rights Reserved.
+#
+# FS QA Test No. 526
+#
+# Test formatting with conflicts between the config file and the cli.
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1       # failure is the default!
+trap '_cleanup; exit $status' 0 1 2 3 15
+
+_cleanup()
+{
+       cd /
+       rm -f $tmp.* $def_cfgfile
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs xfs
+_require_test
+_require_scratch_nocheck
+_require_xfs_mkfs_cfgfile
+
+cfgfile=$TEST_DIR/a
+rm -rf $cfgfile
+
+# disable crc in config file, enable rmapbt (which requires crc=1) in cli
+cat > $cfgfile << ENDL
+[metadata]
+crc = 0
+ENDL
+
+$MKFS_XFS_PROG -c options=$cfgfile -f -m rmapbt=1 $SCRATCH_DEV > $tmp.mkfs 2>&1
+cat $tmp.mkfs >> $seqres.full
+grep 'rmapbt not supported without CRC support' $tmp.mkfs
+
+# enable rmapbt (which requires crc=1) in config file, disable crc in cli
+cat > $cfgfile << ENDL
+[metadata]
+rmapbt = 1
+ENDL
+
+$MKFS_XFS_PROG -c options=$cfgfile -f -m crc=0 $SCRATCH_DEV > $tmp.mkfs 2>&1
+cat $tmp.mkfs >> $seqres.full
+grep 'rmapbt not supported without CRC support' $tmp.mkfs
+
+# success, all done
+status=0
+exit
diff --git a/tests/xfs/526.out b/tests/xfs/526.out
new file mode 100644 (file)
index 0000000..fed0d0a
--- /dev/null
@@ -0,0 +1,3 @@
+QA output created by 526
+rmapbt not supported without CRC support
+rmapbt not supported without CRC support
index b89c0a4..9e78036 100644 (file)
 519 auto quick reflink
 520 auto quick reflink
 521 auto quick realtime growfs
+522 auto quick mkfs
+523 auto quick mkfs
+524 auto quick mkfs
+525 auto quick mkfs
+526 auto quick mkfs