From: Aaron Haslett Date: Mon, 30 Jul 2018 22:07:53 +0000 (+1200) Subject: tdb: test for readonly locks mode on tdbbackup command X-Git-Tag: ldb-1.5.0~53 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04217372f4114bd7583ba56a3860ebbe22ae0719;p=thirdparty%2Fsamba.git tdb: test for readonly locks mode on tdbbackup command Simple bash test for readonly locks on tdbbackup: 1. Running tdbbackup on a database with and without readonly locks enabled. 2. Dump both backups and original. 3. Check all three dumps match. A binary sample_tdb.tdb file is included for the test because the existing sample tdbs in lib/tdb/test are either corrupt or empty. Signed-off-by: Aaron Haslett Reviewed-by: Andrew Bartlett Reviewed-by: Gary Lockyer --- diff --git a/lib/tdb/test/sample_tdb.tdb b/lib/tdb/test/sample_tdb.tdb new file mode 100644 index 00000000000..a40e50c4f9a Binary files /dev/null and b/lib/tdb/test/sample_tdb.tdb differ diff --git a/lib/tdb/test/test_tdbbackup.sh b/lib/tdb/test/test_tdbbackup.sh new file mode 100755 index 00000000000..cf87921dac2 --- /dev/null +++ b/lib/tdb/test/test_tdbbackup.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# Blackbox test for tdbbackup of given ldb or tdb database +# Copyright (C) 2018 Andrew Bartlett + +if [ $# -lt 1 ]; then + echo "Usage: $0 LDBFILE" + exit 1; +fi + +LDBFILE=$1 + +timestamp() { + date -u +'time: %Y-%m-%d %H:%M:%S.%6NZ' | sed 's/\..*NZ$/.000000Z/' +} + +subunit_fail_test () { + timestamp + printf 'failure: %s [\n' "$1" + cat - + echo "]" +} + +testit () { + name="$1" + shift + cmdline="$@" + timestamp + printf 'test: %s\n' "$1" + output=`$cmdline 2>&1` + status=$? + if [ x$status = x0 ]; then + timestamp + printf 'success: %s\n' "$name" + else + echo "$output" | subunit_fail_test "$name" + fi + return $status +} + +$BINDIR/tdbdump $LDBFILE | sort > orig_dump + +testit "normal tdbbackup on tdb file" $BINDIR/tdbbackup $LDBFILE -s .bak +$BINDIR/tdbdump $LDBFILE.bak | sort > bak_dump +testit "cmp between tdbdumps of original and backup" cmp orig_dump bak_dump +rm $LDBFILE.bak +rm bak_dump + +testit "readonly tdbbackup on tdb file" $BINDIR/tdbbackup $LDBFILE -s .bak -r +$BINDIR/tdbdump $LDBFILE.bak | sort > bak_dump +testit "cmp between tdbdumps of original and back dbs" cmp orig_dump bak_dump +rm $LDBFILE.bak +rm bak_dump + +rm orig_dump diff --git a/lib/tdb/wscript b/lib/tdb/wscript index fdf218ccd54..414943a761f 100644 --- a/lib/tdb/wscript +++ b/lib/tdb/wscript @@ -213,6 +213,17 @@ def testonly(ctx): if not os.path.exists(link): os.symlink(os.path.abspath(os.path.join(env.cwd, 'test')), link) + sh_tests = ["test/test_tdbbackup.sh test/jenkins-be-hash.tdb"] + + for sh_test in sh_tests: + cmd = "BINDIR={} {}".format(Utils.g_module.blddir, sh_test) + print("shell test: " + cmd) + ret = samba_utils.RUN_COMMAND(cmd) + if ret != 0: + print("%s sh test failed" % cmd) + ecode = ret + break + for t in tdb1_unit_tests: f = "tdb1-" + t cmd = "cd " + testdir + " && " + os.path.abspath(os.path.join(Utils.g_module.blddir, f)) + " > test-output 2>&1"