diff options
Diffstat (limited to 'tests/ts/lsblk')
-rw-r--r-- | tests/ts/lsblk/README | 19 | ||||
-rw-r--r-- | tests/ts/lsblk/dumps/simple-lvm.tar.xz | bin | 0 -> 14216 bytes | |||
-rw-r--r-- | tests/ts/lsblk/dumps/simple-nvme.tar.xz | bin | 0 -> 10292 bytes | |||
-rwxr-xr-x | tests/ts/lsblk/lsblk | 56 | ||||
-rw-r--r-- | tests/ts/lsblk/mk-input.sh | 124 |
5 files changed, 199 insertions, 0 deletions
diff --git a/tests/ts/lsblk/README b/tests/ts/lsblk/README new file mode 100644 index 0000000..6f93710 --- /dev/null +++ b/tests/ts/lsblk/README @@ -0,0 +1,19 @@ + +Howto add new lsblk test: + +* run mk-input.sh <testname> + +* copy testname.tar.xz file to tests/ts/lsblk/dumps + +* copy lsblk-* files from the tarball to tests/expected/lsblk/ + +* run ./tests/run.sh lsblk + +* git add tests/ts/lsblk/testname.tar.xz + git add tests/expected/lsblk/lsblk-testname* + + +Note that we do not use directly lsblk-* from the tarball. It's better to keep +copy of the files in the tests/expected/lsblk/, because output formatting may +be different in the current version. The version in the tarball is just initial +hint only. diff --git a/tests/ts/lsblk/dumps/simple-lvm.tar.xz b/tests/ts/lsblk/dumps/simple-lvm.tar.xz Binary files differnew file mode 100644 index 0000000..b0c8c34 --- /dev/null +++ b/tests/ts/lsblk/dumps/simple-lvm.tar.xz diff --git a/tests/ts/lsblk/dumps/simple-nvme.tar.xz b/tests/ts/lsblk/dumps/simple-nvme.tar.xz Binary files differnew file mode 100644 index 0000000..47229b3 --- /dev/null +++ b/tests/ts/lsblk/dumps/simple-nvme.tar.xz diff --git a/tests/ts/lsblk/lsblk b/tests/ts/lsblk/lsblk new file mode 100755 index 0000000..b790f75 --- /dev/null +++ b/tests/ts/lsblk/lsblk @@ -0,0 +1,56 @@ +#!/bin/bash +# +# Copyright (C) 2018 Karel Zak <kzak@redhat.com> +# +# This file is part of util-linux. +# +# This file 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; either version 3 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will 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, see <http://www.gnu.org/licenses/>. +# +TS_TOPDIR="${0%/*}/../.." +. $TS_TOPDIR/functions.sh + +ts_init "$*" + +ts_check_test_command "$TS_CMD_LSBLK" +ts_check_prog xz +ts_check_prog tar + +for dump in $(ls $TS_SELF/dumps/*.tar.xz | sort); do + name=$(basename $dump .tar.xz) + dumpdir="$TS_OUTDIR/dumps" + + mkdir -p $dumpdir + tar -C $dumpdir --xz -xf $dump + + # + # Read *.cols from the tarball, but the expected output is not used + # from the tarball due to changes in lsblk fomatting etc. We keep up to + # date version in tests/expected/lsblk. + # + for cols_file in $(ls $dumpdir/$name/*.cols | sort); do + subname=$(basename $cols_file .cols) + subtestname="${name}-${subname}" + + ts_init_subtest $subtestname + cols=$(cat $cols_file) + ${TS_CMD_LSBLK} --sysroot "${dumpdir}/${name}" \ + --output $cols \ + >> ${TS_OUTPUT} 2>> $TS_ERRLOG + + ts_finalize_subtest + done +done + +ts_finalize + diff --git a/tests/ts/lsblk/mk-input.sh b/tests/ts/lsblk/mk-input.sh new file mode 100644 index 0000000..2bbd9e3 --- /dev/null +++ b/tests/ts/lsblk/mk-input.sh @@ -0,0 +1,124 @@ +#!/bin/bash +# +# Copyright (C) 2018 Karel Zak <kzak@redhat.com> +# +# This script makes a copy of relevant files from /sys and /proc. +# The files are useful for lsblk(1) regression tests. +# +progname=$(basename $0) + +if [ -z "$1" ]; then + echo -e "\nusage: $progname <testname>\n" + exit 1 +fi + +TS_DUMP="$1" +TS_NAME=$(basename ${TS_DUMP}) +TS_TARBALL="$TS_DUMP.tar.xz" +TS_CMD_LSBLK=${TS_CMD_LSBLK:-"lsblk"} + +# +# procfs +# +mkdir -p $TS_DUMP/proc +mkdir -p $TS_DUMP/proc/self +cp /proc/self/mountinfo ${TS_DUMP}/proc/self +cp /proc/swaps ${TS_DUMP}/proc/swaps +cp /proc/version ${TS_DUMP}/proc/version + + +# +# sysfs +# +mkdir -p $TS_DUMP/sys/{block,dev/block} +cp --no-dereference /sys/dev/block/* ${TS_DUMP}/sys/dev/block +cp --no-dereference /sys/block/* ${TS_DUMP}/sys/block + +DEVS=$(find /sys/dev/block/ -type l) +for x in ${DEVS}; do + DEV="/sys/dev/block/$(readlink $x)" + + mkdir -p ${TS_DUMP}/${DEV} + + # attributes + for f in $(find ${DEV} -type f -not -path '*/trace/*' -not -path '*/uevent'); do + if [ ! -f ${TS_DUMP}/${f} ]; then + SUB=$(dirname $f) + mkdir -p ${TS_DUMP}/${SUB} + cp $f ${TS_DUMP}/$f 2> /dev/null + fi + done + + # symlinks (slave, holders, etc.) + for f in $(find ${DEV} -type l -not -path '*/subsystem' -not -path '*/bdi'); do + if [ ! -f ${TS_DUMP}/${f} ]; then + SUB=$(dirname $f) + mkdir -p ${TS_DUMP}/${SUB} + cp --no-dereference $f ${TS_DUMP}/$f + fi + done + + # device/ files + if [ -d ${DEV}/device/ ]; then + for f in $(find ${DEV}/device/ -maxdepth 1 -type f -not -path '*/uevent'); do + if [ ! -f ${TS_DUMP}/${f} ]; then + SUB=$(dirname $f) + cp $f ${TS_DUMP}/$f 2> /dev/null + fi + done + fi + +done + +# +# udev a lsblk specific +# +mkdir -p $TS_DUMP/dev +DEVS=$(lsblk --noheadings --output PATH) +for d in $DEVS; do + + # udev + udevadm info --query=property $d > $TS_DUMP/$d + + # lsblk + echo "OWNER=$($TS_CMD_LSBLK --noheadings --nodeps --output OWNER $d)" >> $TS_DUMP/$d + echo "GROUP=$($TS_CMD_LSBLK --noheadings --nodeps --output GROUP $d)" >> $TS_DUMP/$d + echo "MODE=$($TS_CMD_LSBLK --noheadings --nodeps --output MODE $d)" >> $TS_DUMP/$d +done + +function mk_output { + local cols="NAME,${2}" + local subname="$1" + + echo "$cols" > ${TS_DUMP}/${subname}.cols + $TS_CMD_LSBLK -o ${cols} > ${TS_DUMP}/lsblk-${TS_NAME}-${subname} +} + + +LANG="POSIX" +LANGUAGE="POSIX" +LC_ALL="POSIX" +CHARSET="UTF-8" + +export LANG LANGUAGE LC_ALL CHARSET + +# +# lsblk info +# +$TS_CMD_LSBLK -V &> ${TS_DUMP}/version + +mk_output basic KNAME,MAJ:MIN,RM,SIZE,TYPE,MOUNTPOINT +mk_output vendor MODEL,VENDOR,REV +mk_output state RO,RM,HOTPLUG,RAND,STATE,ROTA,TYPE,PKNAME,SCHED +mk_output rw RA,WSAME +mk_output topo SIZE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,RQ-SIZE +mk_output discard DISC-ALN,DISC-GRAN,DISC-MAX,DISC-ZERO +mk_output zone ZONED + + +tar --xz -cvf ${TS_TARBALL} $TS_DUMP +rm -rf $TS_DUMP + +echo -e "\nPlease, send ${TS_TARBALL} to util-linux upstream. Thanks!\n" + + |