Subject: bin/6706: regress test for dump nodump-handling
To: None <gnats-bugs@gnats.netbsd.org>
From: None <bgrayson@ece.utexas.edu>
List: netbsd-bugs
Date: 01/02/1999 00:07:33
>Number:         6706
>Category:       bin
>Synopsis:       regress test for dump nodump-handling
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Jan  1 22:20:00 1999
>Last-Modified:
>Originator:     Brian Grayson
>Organization:
	Parallel and Distributed Systems
	Electrical and Computer Engineering
	The University of Texas at Austin
>Release:        Dec 31 1998
>Environment:

>Description:
	The following patches for /usr/src/regress/sbin/dump
	create Makefile and estimatecompare, which together allow
	a few simple tests of dump's nodump handling, both on
	files and on directories.

	These tests will fail if the nodump dir handling in
	PR6705 is not added in.

	I don't know if there are any rules for stuff in
	/usr/src/regress.  Simply use "make regress" in the
	directory to perform the test.
>How-To-Repeat:
>Fix:
	Besides these patches, sbin needs to be added to SUBDIR in
	/usr/src/regress/Makefile.

--- /dev/null	Fri Jan  1 23:31:53 1999
+++ Makefile	Fri Jan  1 23:23:04 1999
@@ -0,0 +1,93 @@
+##  Notes:
+##    This set of tests creates a dummy directory tree in /tmp and
+##    populates it with several files.  The test requires around 1100
+##    inodes and 350KB.
+##
+##    The tests primarily test the dumping of subdirectories, not full
+##    filesystems.  Also, it tests mostly how nodump is honored, with
+##    a few corner cases (a directory with an indirect block, etc.)
+##    covered.  They were written during testing of the new
+##    nodump-on-directories feature.
+##
+##    The tests could probably be extended by using vnconfig et al to
+##    create a brand new filesystem, thus allowing full dumps to be tested.
+##
+##    Currently, the integrity of the backups is not checked (via
+##    restores or any other method).  But it's a start.
+##
+##  Caveats:
+##    These tests will most likely fail on systems with block sizes
+##    different from 8K.
+##
+##    Enjoy!    		Brian Grayson, Jan 1, 1999.
+
+TMPFS=/tmp/dumpregresstest
+DIGITS=0 1 2 3 4 5 6 7 8 9
+TENK=$(TMPFS)/10k
+ZEROK=$(TMPFS)/0k
+
+FIRST_EST=1488
+regress: tmpfs
+	$(MAKE) regresstest
+	$(MAKE) clean
+regresstest:
+	@echo "***  Testing dump on $(TMPFS)."
+	@#  First of all, estimate the size of a dump of just the tmpfs.
+	$(PWD)/estimatecompare 1488 -S -h9 -0 $(TMPFS)
+
+	@#  Now estimate the size, after honoring the nodump flag.
+	$(PWD)/estimatecompare 263  -S -h0 -0 $(TMPFS)
+
+clean:	cleantmpfs
+cleantmpfs:
+	@echo "***  Cleaning up $(TMPFS)."
+	rm -rf $(TMPFS)
+tmpfs:
+	$(MAKE) cleantmpfs
+	@echo "***  Creating a dummy directory tree at $(TMPFS)."
+	mkdir $(TMPFS)
+	@# Create two handy files -- 0k, and 10k.
+	touch $(ZEROK)
+	dd if=/dev/zero of=$(TENK) bs=1024 count=10
+	@# Create a directory with a 10K file, with the file marked nodump.
+	mkdir $(TMPFS)/nodumpfile
+	cp $(TENK) $(TMPFS)/nodumpfile/10k
+	chflags nodump $(TMPFS)/nodumpfile/10k
+	@# And some ordinary 10k files.
+	mkdir $(TMPFS)/dumpfile
+	TMPFS_DUMP=$(TMPFS)/dumpfile/dumpfile.10k; \
+	for f in $(DIGITS); do \
+	  cp $(TENK) $$TMPFS_DUMP.$$f; done;
+	@# And now the same files, but in a dir marked nodump:
+	mkdir $(TMPFS)/nodumpdir
+	chflags nodump $(TMPFS)/nodumpdir
+	TMPFS_1=$(TMPFS)/nodumpdir/10k; \
+	  for f in $(DIGITS); do cp $(TENK) $$TMPFS_1.$$f; done
+	
+	@# Also create a large directory that uses more than one direct block
+	@# (so it has to be larger than 8K).
+	@# Make sure one entry is for a deleted file, also.
+	mkdir $(TMPFS)/2blkdir
+	TMPFS_1=$(TMPFS)/2blkdir; \
+	  cp $(ZEROK) $$TMPFS_1; \
+	  for f in $(DIGITS); do for g in $(DIGITS); do \
+	    cp $(ZEROK) \
+	      $$TMPFS_1/really_really_really_really_really_really_long_name_to_use_up_space_$$f$$g; \
+	    done; done; \
+	  rm $$TMPFS_1/0k
+
+	@# Now create a directory with at least one indirect block.
+	@# On a FS with 8K blocks, we need at least 1 + 12*8192 bytes, or
+	@#   98305 bytes, in the directory.  1000 files does the trick,
+	@#   with the long filename below.
+	mkdir $(TMPFS)/indirblk
+	chflags nodump $(TMPFS)/indirblk
+	TMPFS_1=$(TMPFS)/indirblk; \
+	  cp $(ZEROK) $$TMPFS_1; \
+	  for e in 0; do\
+	  for f in $(DIGITS); do for g in $(DIGITS); do for h in $(DIGITS); do \
+	    cp $(ZEROK) \
+	      $$TMPFS_1/really_really_really_really_really_really_long_name_to_use_up_dir_entry_space$$e$$f$$g$$h; \
+	    done; done; done; done; \
+	  rm $$TMPFS_1/0k
+	@# ^---  As before, make sure at least one direntry is a deleted file.


--- /dev/null	Fri Jan  1 23:31:53 1999
+++ estimatecompare	Fri Jan  1 23:57:12 1999
@@ -0,0 +1,22 @@
+#!/bin/sh
+##  First arg is expected number of blocks.  Rest are args to be passed to dump.
+expectedest=$1
+shift
+
+echo "Expecting estimate around $expectedest blocks:"
+est=`/sbin/dump $* 2>&1 | grep estimated`
+echo $est
+blkest=`echo $est | awk '{print $3;}'`
+
+diff=`echo $expectedest $blkest |\
+    awk '{if ($1<$2) print $2-$1; else print $1-$2;}'`
+
+thresh=10
+##  Use an error threshold of $thresh blocks.  The error could arise from
+##  one machine with a larger / and /tmp than the system on which this
+##  test was developed.
+
+if [ $diff -gt $thresh ]; then
+  echo "Error:  estimated $blkest blocks!"
+  exit 1
+fi
>Audit-Trail:
>Unformatted: