1##	$NetBSD: Makefile,v 1.6 2004/06/30 03:26:27 jmc Exp $
2##  Notes:
3##    This set of tests creates a dummy directory tree in /tmp and
4##    populates it with several files.  The test requires around 1100
5##    inodes and 6.8MB. The test system needs to run a kernel with
6##    FFS Endian Independent support (options FFS_EI) to be able to
7##    perform this test.
8##
9##    This test verifies that newfs can create filesystems in both bytes
10##    orders. For each byte order it is checked that:
11##      - the kernel understands both filesystems created
12##      - fsck_ffs can convert them from one byte order to the other
13##      - dump handles properly the 'nodump' flag, an that restore can
14##        properly restore the filesystem.
15##
16##    This is derived from work done by Brian Grayson, submitted in PR 6706.
17
18.include <bsd.own.mk>
19
20TMPL=/tmp/ffstemplate
21TMPMP=/tmp/ffsregresstest_mount
22TMPIM=/var/tmp/ffsregresstest.im
23TMPREST=/tmp/restoreregress
24EN?= be
25DIGITS=0 1 2 3 4 5 6 7 8 9
26
27VND?= vnd0
28BVND= /dev/${VND}
29CVND= /dev/r${VND}
30MPART?= a
31.if (${MACHINE_ARCH} == "i386")
32RPART?= d
33.else
34RPART?= c
35.endif
36
37# As make is called recusively, and we may cd to ${OBJDIR}, we need to call make
38# with some variables propagated.
39SRCDIR?= ${.CURDIR}
40MAKECMD= ${MAKE} -f ${SRCDIR}/Makefile SRCDIR=${SRCDIR} EN=${EN} VND=${VND} MPART=${MPART} RPART=${RPART}
41
42regress: template
43	${MAKECMD} EN=be makeregress
44	${MAKECMD} clean-tmpfs
45	${MAKECMD} EN=le makeregress
46	${MAKECMD} clean
47
48makeregress: tmpfs
49	${MAKECMD} dump
50	${MAKECMD} fsck
51	${MAKECMD} clean-dump;
52
53clean: clean-tmpfs clean-template clean-dump
54clean-dump:
55	@echo "***  Cleaning up ${TMPREST}."
56	-rm -rf ${TMPREST}
57clean-tmpfs:
58	@echo "***  Cleaning up ${TMPMP}."
59	-umount ${TMPMP}
60	-vnconfig -u ${BVND}${RPART}
61	-rm -rf ${TMPMP} ${TMPIM}
62clean-template:
63	@echo "***  Cleaning up ${TMPL}."
64	-rm -rf ${TMPL}
65
66cmp:
67	diff -r -q ${TMPL} ${TMPMP}
68
69dump:
70	@echo "***  Testing dump nodump flag support."
71	@#  First of all, estimate the size of a dump of just the tmpfs.
72	${HOST_SH} ${SRCDIR}/estimatecompare 2572 -S -h9 -0 ${CVND}${MPART}
73
74	@#  Now estimate the size, after honoring the nodump flag.
75	${HOST_SH} ${SRCDIR}/estimatecompare 347  -S -h0 -0 ${CVND}${MPART}
76	@echo "***  Testing dump/restore support"
77	mkdir ${TMPREST}
78	dump -0 -h9 -B10000 -f - ${CVND}${MPART} | \
79	    (cd ${TMPREST}; restore -rf -)
80	@#restore should have created a restoresymtable file
81	rm ${TMPREST}/restoresymtable
82	diff -r -q ${TMPL} ${TMPREST}
83
84fsck:
85	@echo "*** checking fsck_ffs endian conversion."
86	umount ${BVND}${MPART}
87.if (${EN} == le)
88	fsck_ffs -B be -y ${CVND}${MPART}
89	mount -o async ${BVND}${MPART} ${TMPMP}
90	${MAKECMD} cmp
91	umount ${BVND}${MPART}
92	fsck_ffs -B le -y ${CVND}${MPART}
93	mount -o async ${BVND}${MPART} ${TMPMP}
94	${MAKECMD} cmp
95.else
96	fsck_ffs -B le -y ${CVND}${MPART}
97	mount -o async ${BVND}${MPART} ${TMPMP}
98	${MAKECMD} cmp
99	umount ${BVND}${MPART}
100	fsck_ffs -B be -y ${CVND}${MPART}
101	mount -o async ${BVND}${MPART} ${TMPMP}
102	${MAKECMD} cmp
103.endif
104
105tmpfs:
106	@echo "***  Creating a dummy directory tree at ${TMPMP} monted on" \
107	    "${TMPIM}, ${EN} byte order."
108	dd if=/dev/zero of=${TMPIM} count=5860
109	vnconfig -v ${BVND}${RPART} ${TMPIM}
110	disklabel -f ${SRCDIR}/disktab -rw ${VND} floppy288
111	newfs -B ${EN} -i 500 -b 8192 -f 1024 ${CVND}${MPART}
112	mkdir ${TMPMP}
113	mount -o async ${BVND}${MPART} ${TMPMP}
114	# Arg, cp will give an error if the symlink is copied before its target
115	-cp -Rp ${TMPL}/* ${TMPMP}
116	${MAKECMD} cmp
117
118template:
119	mkdir ${TMPL}
120	@# Create a directory with a 10K file, with the file marked nodump.
121	mkdir ${TMPL}/nodumpfile
122	jot -r -c -s '' -n 10240 > ${TMPL}/nodumpfile/10k 
123	chflags nodump ${TMPL}/nodumpfile/10k
124	@# And some ordinary 10k files.
125	mkdir ${TMPL}/dumpfile
126	TMPFS_DUMP=${TMPL}/dumpfile/dumpfile.10k; \
127	for f in ${DIGITS}; do \
128	  jot -r -c -s '' -n 10240 > $$TMPFS_DUMP.$$f; done;
129	@# A subdir with a short and a long symbolic link in it
130	mkdir ${TMPL}/dumpfile/subdir
131	ln -s ../dumpfile.10k.0 ${TMPL}/dumpfile/subdir/link;
132	ln -s ../dumpfile.10k.1 ${TMPL}/dumpfile/subdir/really_really_really_really_really_really_long_name_to_use_up_space.link;
133	@# And now the same files, but in a dir marked nodump:
134	mkdir ${TMPL}/nodumpdir
135	chflags nodump ${TMPL}/nodumpdir
136	TMPFS_1=${TMPL}/nodumpdir/10k; \
137	  for f in ${DIGITS}; do  \
138	      jot -r -c -s '' -n 10240 > $$TMPFS_1.$$f; \
139	  done
140	
141	@# Also create a large directory that uses more than one direct block
142	@# (so it has to be larger than 8K).
143	@# Make sure one entry is for a deleted file, also.
144	mkdir ${TMPL}/2blkdir
145	TMPFS_1=${TMPL}/2blkdir; \
146	  jot -r -c -s '' -n 10 > $$TMPFS_1/10b; \
147	  for f in ${DIGITS}; do for g in ${DIGITS}; do \
148	    jot -r -c -s '' -n 10 > \
149	      $$TMPFS_1/really_really_really_really_really_really_long_name_to_use_up_space_$$f$$g ;\
150	    done; done; \
151	  rm $$TMPFS_1/10b
152
153	@# Now create a directory with at least one indirect block.
154	@# On a FS with 8K blocks, we need at least 1 + 12*8192 bytes, or
155	@#   98305 bytes, in the directory.  1000 files does the trick,
156	@#   with the long filename below.
157	mkdir ${TMPL}/indirblk
158	chflags nodump ${TMPL}/indirblk
159	TMPFS_1=${TMPL}/indirblk; \
160	  jot -r -c -s '' -n 10 >  $$TMPFS_1/10b; \
161	  for e in 0; do\
162	  for f in ${DIGITS}; do for g in ${DIGITS}; do for h in ${DIGITS}; do \
163	    jot -r -c -s '' -n 10 >  \
164	      $$TMPFS_1/really_really_really_really_really_really_long_name_to_use_up_dir_entry_space$$e$$f$$g$$h ;\
165	    done; done; done; done; \
166	  rm $$TMPFS_1/10b
167	@# ^---  As before, make sure at least one direntry is a deleted file.
168