On Fri, Jun 24, 2016 at 11:08:33AM -0400, je...@suse.com wrote:
> From: Jeff Mahoney
>
> This tests the sysfs publishing for btrfs allocation and device
> membership info under a number of different layouts, similar to the
> btrfs replace test. We test the allocation files only for existence and
> that they contain numerical values. We test the device membership
> by mapping the devices used to create the file system to sysfs paths
> and matching them against the paths used for the device membership
> symlinks.
>
> It passes on kernels without a /sys/fs/btrfs/ directory.
>
> Signed-off-by: Jeff Mahoney
> ---
> common/config | 4 +-
> common/rc | 7 ++
> tests/btrfs/125 | 193
>
> tests/btrfs/125.out | 2 +
> tests/btrfs/group | 1 +
> 5 files changed, 205 insertions(+), 2 deletions(-)
> create mode 100755 tests/btrfs/125
> create mode 100644 tests/btrfs/125.out
>
> diff --git a/common/config b/common/config
> index c25b1ec..c5e65f7 100644
> --- a/common/config
> +++ b/common/config
> @@ -201,13 +201,13 @@ export DEBUGFS_PROG="`set_prog_path debugfs`"
> # newer systems have udevadm command but older systems like RHEL5 don't.
> # But if neither one is available, just set it to "sleep 1" to wait for lv to
> # be settled
> -UDEV_SETTLE_PROG="`set_prog_path udevadm`"
> +UDEVADM_PROG="`set_prog_path udevadm`"
> if [ "$UDEV_SETTLE_PROG" == "" ]; then
$UDEVADM_PROG should be checked here, not $UDEV_SETTLE_PROG anymore.
> # try udevsettle command
> UDEV_SETTLE_PROG="`set_prog_path udevsettle`"
> else
> # udevadm is available, add 'settle' as subcommand
> - UDEV_SETTLE_PROG="$UDEV_SETTLE_PROG settle"
> + UDEV_SETTLE_PROG="$UDEVADM_PROG settle"
> fi
> # neither command is available, use sleep 1
> if [ "$UDEV_SETTLE_PROG" == "" ]; then
> diff --git a/common/rc b/common/rc
> index 4b05fcf..f4c4312 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -76,6 +76,13 @@ _btrfs_get_subvolid()
> $BTRFS_UTIL_PROG sub list $mnt | grep $name | awk '{ print $2 }'
> }
>
> +_btrfs_get_feature_flags()
> +{
> + local dev=$1
> + local class=$2
> + $BTRFS_SHOW_SUPER_PROG $dev | grep ^${class}_flags | awk '{print $NF}'
> +}
> +
> _btrfs_get_fsid()
> {
> local dev=$1
> diff --git a/tests/btrfs/125 b/tests/btrfs/125
> new file mode 100755
> index 000..83f1921
> --- /dev/null
> +++ b/tests/btrfs/125
> @@ -0,0 +1,193 @@
> +#! /bin/bash
> +# FS QA Test No. 125
> +#
> +# Test of the btrfs sysfs publishing
> +#
> +#---
> +# Copyright (C) 2013-2016 SUSE. All rights reserved.
Copyright year is 2016.
> +#
> +# This program is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU General Public License as
> +# published by the Free Software Foundation.
> +#
> +# This program is distributed in the hope that it would be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write the Free Software Foundation,
> +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
> +#
> +#---
> +#
> +
> +seq=`basename $0`
> +seqres=$RESULT_DIR/$seq
> +echo "== QA output created by $seq"
> +
> +here=`pwd`
> +tmp=/tmp/$$
> +status=1
Missing _cleanup and trap, use "./new btrfs" to generate new btrfs test.
> +
> +# get standard environment, filters and checks
> +. ./common/rc
> +. ./common/filter
> +
> +# real QA test starts here
> +_supported_fs btrfs
Missing "_supported_os" call. Following the template create by the
'./new' script makes it easier :)
> +_require_scratch
> +_require_scratch_dev_pool
> +_require_command "$UDEVADM_PROG"
We usually provide a program name as a second param
_require_command "$UDEVADM_PROG" udevadm
> +
> +rm -f $seqres.full
> +rm -f $tmp.tmp
This should be "rm -f $tmp.*" and belongs to _cleanup()
> +
> +check_file() {
> + local file=$1
> + base="$(echo "$file" | sed -e 's#/sys/fs/btrfs/[0-9a-f-][0-9a-f-]*/##')"
> + if [ ! -f "$file" ]; then
> + echo "$base missing."
> + return 0
No need to return 0/1 based on failure/pass, because check_chunk()
doesn't need to exit on failure.
> + else
> + value="$(cat $file)"
> + if [ -n "$(echo $value | tr -d 0-9)" ]; then
> + echo "ERROR: $base: numerical value expected" \
> + "(got $value)"
> + return 0
> + fi
> + fi
> + return 1
> +}
> +
> +check_chunk() {
> + path=$1
> + mkfs_options=$2
> + error=false
> +
> +