From mboxrd@z Thu Jan 1 00:00:00 1970 From: Steven Whitehouse Date: Fri, 14 Dec 2012 13:45:03 +0000 Subject: [Cluster-devel] [PATCH] gfs2-utils tests: Add a script to exercise the utils In-Reply-To: <50CB2D39.3060102@redhat.com> References: <1355396336.2708.9.camel@menhir> <1355491317-8733-1-git-send-email-anprice@redhat.com> <1355492018.2709.17.camel@menhir> <50CB2D39.3060102@redhat.com> Message-ID: <1355492703.2709.18.camel@menhir> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi, On Fri, 2012-12-14 at 13:44 +0000, Andrew Price wrote: > On 14/12/12 13:33, Steven Whitehouse wrote: > > Hi, > > > > On Fri, 2012-12-14 at 13:21 +0000, Andrew Price wrote: > >> Add a test script to make it easy to run gfs2 utils with various options > >> and check their exit codes in sequence. The script is plugged into the > >> test suite and is run with 'make check'. > >> > >> Signed-off-by: Andrew Price > >> --- > >> tests/Makefile.am | 4 +++- > >> tests/tool_tests.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ > >> 2 files changed, 65 insertions(+), 1 deletion(-) > >> create mode 100755 tests/tool_tests.sh > >> > >> diff --git a/tests/Makefile.am b/tests/Makefile.am > >> index 71c1e08..d8aa8f2 100644 > >> --- a/tests/Makefile.am > >> +++ b/tests/Makefile.am > >> @@ -1,4 +1,6 @@ > >> -TESTS = check_libgfs2 > >> +TESTS_ENVIRONMENT = TOPBUILDDIR=$(top_builddir) > >> +TESTS = check_libgfs2 tool_tests.sh > >> +EXTRA_DIST = tool_tests.sh > >> check_PROGRAMS = check_libgfs2 > >> check_libgfs2_SOURCES = check_meta.c \ > >> $(top_srcdir)/gfs2/libgfs2/libgfs2.h > >> diff --git a/tests/tool_tests.sh b/tests/tool_tests.sh > >> new file mode 100755 > >> index 0000000..791b071 > >> --- /dev/null > >> +++ b/tests/tool_tests.sh > >> @@ -0,0 +1,62 @@ > >> +#!/bin/sh > >> + > >> +# This script runs gfs2 utils with various options, checking exit codes against > >> +# expected values. If any test fails to exit with an expected code, the exit code > >> +# of the whole script will be non-zero but the tests will continue to be run. The > >> +# sparse file which is used as the target of the tests can be configured by > >> +# setting the environment variables TEST_TARGET (the filename) and TEST_TARGET_SZ > >> +# (its apparent size in gigabytes). Defaults to "test_sparse" and 10GB. > >> + > >> +MKFS="${TOPBUILDDIR}/gfs2/mkfs/mkfs.gfs2 -qO" > >> +FSCK="${TOPBUILDDIR}/gfs2/fsck/fsck.gfs2 -qn" > >> + > >> +# Name of the sparse file we'll use for testing > >> +TEST_TARGET=${TEST_TARGET:-test_sparse} > >> +# Size, in GB, of the sparse file we'll create to run the tests > >> +TEST_TARGET_SZ=${TEST_TARGET_SZ:-10} > >> +[ $TEST_TARGET_SZ -gt 0 ] || { echo "Target size (in GB) must be greater than 0" >&2; exit 1; } > >> +# Overall success (so we can keep going if one test fails) > >> +TEST_RET=0 > >> + > >> +fn_test() > >> +{ > >> + local expected="$1" > >> + local cmd="$2" > >> + echo -n "Running '$cmd' - (Exp: $expected Got: " > >> + $cmd &> /dev/null; > >> + local ret=$? > >> + echo -n "$ret) " > >> + if [ "$ret" != "$expected" ]; > >> + then > >> + echo "FAIL" > >> + TEST_RET=1 > >> + TEST_GRP_RET=1 > >> + else > >> + echo "PASS" > >> + fi > >> +} > >> + > >> +fn_rm_target() > >> +{ > >> + fn_test 0 "rm -f $TEST_TARGET" > >> +} > >> + > >> +fn_recreate_target() > >> +{ > >> + fn_rm_target > >> + fn_test 0 "dd if=/dev/null of=$TEST_TARGET bs=1 count=0 seek=${TEST_TARGET_SZ}G" > > > > This doesn't look very sparse, shouldn't we be creating it with truncate > > rather than dd? > > Looks sparse to me: > > $ dd if=/dev/null of=test_sparse bs=1 count=0 seek=10G > 0+0 records in > 0+0 records out > 0 bytes (0 B) copied, 1.4466e-05 s, 0.0 kB/s > $ du test_sparse > 0 test_sparse > $ du --apparent-size test_sparse > 10485760 test_sparse > > Truncate would work too but unless there's a hidden problem with the > above I'll need more convincing to change it :) > > Andy > Ah, sorry. I missed the seek= the first time. Yes, that should be ok, Steve. > > > > Steve. > > > > > >> +} > >> + > >> + > >> +# Tests start here > >> +fn_recreate_target > >> +fn_test 0 "$MKFS -p lock_nolock $TEST_TARGET" > >> +fn_test 0 "$MKFS -p lock_dlm -t foo:bar $TEST_TARGET" > >> +fn_test 255 "$MKFS -p badprotocol $TEST_TARGET" > >> +fn_test 0 "$FSCK $TEST_TARGET" > >> + > >> +# Tests end here > >> + > >> +# Clean up > >> +fn_test 0 "rm -f $TEST_TARGET" > >> +exit $TEST_RET > > > > >