summaryrefslogtreecommitdiffstats
path: root/tests/ts
diff options
context:
space:
mode:
authorKarel Zak2018-06-20 12:59:40 +0200
committerKarel Zak2018-06-21 13:19:28 +0200
commit314adce6681d8ad619b8d884ac0aa37288b61976 (patch)
tree55acc418eb86b2deeb8f4772839aa63941c7ec92 /tests/ts
parentlsblk: fix COL_SCHED (diff)
downloadkernel-qcow2-util-linux-314adce6681d8ad619b8d884ac0aa37288b61976.tar.gz
kernel-qcow2-util-linux-314adce6681d8ad619b8d884ac0aa37288b61976.tar.xz
kernel-qcow2-util-linux-314adce6681d8ad619b8d884ac0aa37288b61976.zip
tests: add lsblk test script
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'tests/ts')
-rw-r--r--tests/ts/lsblk/README19
-rwxr-xr-xtests/ts/lsblk/lsblk56
-rw-r--r--tests/ts/lsblk/mk-input.sh23
3 files changed, 92 insertions, 6 deletions
diff --git a/tests/ts/lsblk/README b/tests/ts/lsblk/README
new file mode 100644
index 000000000..6f937102c
--- /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/lsblk b/tests/ts/lsblk/lsblk
new file mode 100755
index 000000000..d51438bc8
--- /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>&1
+
+ ts_finalize_subtest
+ done
+done
+
+ts_finalize
+
diff --git a/tests/ts/lsblk/mk-input.sh b/tests/ts/lsblk/mk-input.sh
index d2bd76505..8cd467e9a 100644
--- a/tests/ts/lsblk/mk-input.sh
+++ b/tests/ts/lsblk/mk-input.sh
@@ -3,7 +3,7 @@
# 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 lscpu(1) regression tests.
+# The files are useful for lsblk(1) regression tests.
#
progname=$(basename $0)
@@ -13,6 +13,8 @@ if [ -z "$1" ]; then
fi
TS_DUMP="$1"
+TS_NAME=$(basename ${TS_DUMP})
+TS_TARBALL="$TS_DUMP.tar.xz"
TS_CMD_LSBLK=${TS_CMD_LSBLK:-"lsblk"}
#
@@ -70,12 +72,21 @@ done
function mk_output {
- cols="$2"
- name="$1"
+ local cols="NAME,${2}"
+ local subname="$1"
- $TS_CMD_LSBLK -o NAME,${cols} > ${TS_DUMP}/lsblk.${name}
+ 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
#
@@ -90,9 +101,9 @@ mk_output discard DISC-ALN,DISC-GRAN,DISC-MAX,DISC-ZERO
mk_output zone ZONED
-tar zcvf lsblk-$TS_DUMP.tar.gz $TS_DUMP
+tar --xz -cvf ${TS_TARBALL} $TS_DUMP
rm -rf $TS_DUMP
-echo -e "\nPlease, send lsblk-$TS_DUMP.tar.gz to util-linux upstream. Thanks!\n"
+echo -e "\nPlease, send ${TS_TARBALL} to util-linux upstream. Thanks!\n"