11.8Srillig##	$NetBSD: Makefile,v 1.8 2024/09/08 09:36:48 rillig Exp $
21.1Sbouyer##  Notes:
31.1Sbouyer##    This set of tests creates a dummy directory tree in /tmp and
41.1Sbouyer##    populates it with several files.  The test requires around 1100
51.3Stron##    inodes and 6.8MB. The test system needs to run a kernel with
61.3Stron##    FFS Endian Independent support (options FFS_EI) to be able to
71.3Stron##    perform this test.
81.1Sbouyer##
91.1Sbouyer##    This test verifies that newfs can create filesystems in both bytes
101.1Sbouyer##    orders. For each byte order it is checked that:
111.1Sbouyer##      - the kernel understands both filesystems created
121.1Sbouyer##      - fsck_ffs can convert them from one byte order to the other
131.8Srillig##      - dump handles properly the 'nodump' flag, and that restore can
141.1Sbouyer##        properly restore the filesystem.
151.1Sbouyer##
161.2Sbouyer##    This is derived from work done by Brian Grayson, submitted in PR 6706.
171.1Sbouyer
181.7Schristos.include <bsd.own.mk>
191.5Slukem
201.1SbouyerTMPL=/tmp/ffstemplate
211.1SbouyerTMPMP=/tmp/ffsregresstest_mount
221.1SbouyerTMPIM=/var/tmp/ffsregresstest.im
231.1SbouyerTMPREST=/tmp/restoreregress
241.1SbouyerEN?= be
251.1SbouyerDIGITS=0 1 2 3 4 5 6 7 8 9
261.1Sbouyer
271.1SbouyerVND?= vnd0
281.1SbouyerBVND= /dev/${VND}
291.1SbouyerCVND= /dev/r${VND}
301.1SbouyerMPART?= a
311.1Sbouyer.if (${MACHINE_ARCH} == "i386")
321.1SbouyerRPART?= d
331.1Sbouyer.else
341.1SbouyerRPART?= c
351.1Sbouyer.endif
361.1Sbouyer
371.1Sbouyer# As make is called recusively, and we may cd to ${OBJDIR}, we need to call make
381.1Sbouyer# with some variables propagated.
391.1SbouyerSRCDIR?= ${.CURDIR}
401.1SbouyerMAKECMD= ${MAKE} -f ${SRCDIR}/Makefile SRCDIR=${SRCDIR} EN=${EN} VND=${VND} MPART=${MPART} RPART=${RPART}
411.1Sbouyer
421.1Sbouyerregress: template
431.1Sbouyer	${MAKECMD} EN=be makeregress
441.1Sbouyer	${MAKECMD} clean-tmpfs
451.1Sbouyer	${MAKECMD} EN=le makeregress
461.1Sbouyer	${MAKECMD} clean
471.1Sbouyer
481.1Sbouyermakeregress: tmpfs
491.1Sbouyer	${MAKECMD} dump
501.1Sbouyer	${MAKECMD} fsck
511.1Sbouyer	${MAKECMD} clean-dump;
521.1Sbouyer
531.1Sbouyerclean: clean-tmpfs clean-template clean-dump
541.1Sbouyerclean-dump:
551.1Sbouyer	@echo "***  Cleaning up ${TMPREST}."
561.1Sbouyer	-rm -rf ${TMPREST}
571.1Sbouyerclean-tmpfs:
581.1Sbouyer	@echo "***  Cleaning up ${TMPMP}."
591.1Sbouyer	-umount ${TMPMP}
601.1Sbouyer	-vnconfig -u ${BVND}${RPART}
611.1Sbouyer	-rm -rf ${TMPMP} ${TMPIM}
621.1Sbouyerclean-template:
631.1Sbouyer	@echo "***  Cleaning up ${TMPL}."
641.1Sbouyer	-rm -rf ${TMPL}
651.1Sbouyer
661.1Sbouyercmp:
671.1Sbouyer	diff -r -q ${TMPL} ${TMPMP}
681.1Sbouyer
691.1Sbouyerdump:
701.1Sbouyer	@echo "***  Testing dump nodump flag support."
711.1Sbouyer	@#  First of all, estimate the size of a dump of just the tmpfs.
721.5Slukem	${HOST_SH} ${SRCDIR}/estimatecompare 2572 -S -h9 -0 ${CVND}${MPART}
731.1Sbouyer
741.1Sbouyer	@#  Now estimate the size, after honoring the nodump flag.
751.5Slukem	${HOST_SH} ${SRCDIR}/estimatecompare 347  -S -h0 -0 ${CVND}${MPART}
761.1Sbouyer	@echo "***  Testing dump/restore support"
771.1Sbouyer	mkdir ${TMPREST}
781.1Sbouyer	dump -0 -h9 -B10000 -f - ${CVND}${MPART} | \
791.1Sbouyer	    (cd ${TMPREST}; restore -rf -)
801.1Sbouyer	@#restore should have created a restoresymtable file
811.1Sbouyer	rm ${TMPREST}/restoresymtable
821.1Sbouyer	diff -r -q ${TMPL} ${TMPREST}
831.1Sbouyer
841.1Sbouyerfsck:
851.1Sbouyer	@echo "*** checking fsck_ffs endian conversion."
861.1Sbouyer	umount ${BVND}${MPART}
871.1Sbouyer.if (${EN} == le)
881.1Sbouyer	fsck_ffs -B be -y ${CVND}${MPART}
891.1Sbouyer	mount -o async ${BVND}${MPART} ${TMPMP}
901.1Sbouyer	${MAKECMD} cmp
911.1Sbouyer	umount ${BVND}${MPART}
921.1Sbouyer	fsck_ffs -B le -y ${CVND}${MPART}
931.1Sbouyer	mount -o async ${BVND}${MPART} ${TMPMP}
941.1Sbouyer	${MAKECMD} cmp
951.1Sbouyer.else
961.1Sbouyer	fsck_ffs -B le -y ${CVND}${MPART}
971.1Sbouyer	mount -o async ${BVND}${MPART} ${TMPMP}
981.1Sbouyer	${MAKECMD} cmp
991.1Sbouyer	umount ${BVND}${MPART}
1001.1Sbouyer	fsck_ffs -B be -y ${CVND}${MPART}
1011.1Sbouyer	mount -o async ${BVND}${MPART} ${TMPMP}
1021.1Sbouyer	${MAKECMD} cmp
1031.1Sbouyer.endif
1041.1Sbouyer
1051.1Sbouyertmpfs:
1061.1Sbouyer	@echo "***  Creating a dummy directory tree at ${TMPMP} monted on" \
1071.1Sbouyer	    "${TMPIM}, ${EN} byte order."
1081.1Sbouyer	dd if=/dev/zero of=${TMPIM} count=5860
1091.1Sbouyer	vnconfig -v ${BVND}${RPART} ${TMPIM}
1101.4Stron	disklabel -f ${SRCDIR}/disktab -rw ${VND} floppy288
1111.1Sbouyer	newfs -B ${EN} -i 500 -b 8192 -f 1024 ${CVND}${MPART}
1121.1Sbouyer	mkdir ${TMPMP}
1131.1Sbouyer	mount -o async ${BVND}${MPART} ${TMPMP}
1141.1Sbouyer	# Arg, cp will give an error if the symlink is copied before its target
1151.1Sbouyer	-cp -Rp ${TMPL}/* ${TMPMP}
1161.1Sbouyer	${MAKECMD} cmp
1171.1Sbouyer
1181.1Sbouyertemplate:
1191.1Sbouyer	mkdir ${TMPL}
1201.1Sbouyer	@# Create a directory with a 10K file, with the file marked nodump.
1211.1Sbouyer	mkdir ${TMPL}/nodumpfile
1221.1Sbouyer	jot -r -c -s '' -n 10240 > ${TMPL}/nodumpfile/10k 
1231.1Sbouyer	chflags nodump ${TMPL}/nodumpfile/10k
1241.1Sbouyer	@# And some ordinary 10k files.
1251.1Sbouyer	mkdir ${TMPL}/dumpfile
1261.1Sbouyer	TMPFS_DUMP=${TMPL}/dumpfile/dumpfile.10k; \
1271.1Sbouyer	for f in ${DIGITS}; do \
1281.1Sbouyer	  jot -r -c -s '' -n 10240 > $$TMPFS_DUMP.$$f; done;
1291.1Sbouyer	@# A subdir with a short and a long symbolic link in it
1301.1Sbouyer	mkdir ${TMPL}/dumpfile/subdir
1311.1Sbouyer	ln -s ../dumpfile.10k.0 ${TMPL}/dumpfile/subdir/link;
1321.1Sbouyer	ln -s ../dumpfile.10k.1 ${TMPL}/dumpfile/subdir/really_really_really_really_really_really_long_name_to_use_up_space.link;
1331.1Sbouyer	@# And now the same files, but in a dir marked nodump:
1341.1Sbouyer	mkdir ${TMPL}/nodumpdir
1351.1Sbouyer	chflags nodump ${TMPL}/nodumpdir
1361.1Sbouyer	TMPFS_1=${TMPL}/nodumpdir/10k; \
1371.1Sbouyer	  for f in ${DIGITS}; do  \
1381.1Sbouyer	      jot -r -c -s '' -n 10240 > $$TMPFS_1.$$f; \
1391.1Sbouyer	  done
1401.1Sbouyer	
1411.1Sbouyer	@# Also create a large directory that uses more than one direct block
1421.1Sbouyer	@# (so it has to be larger than 8K).
1431.1Sbouyer	@# Make sure one entry is for a deleted file, also.
1441.1Sbouyer	mkdir ${TMPL}/2blkdir
1451.1Sbouyer	TMPFS_1=${TMPL}/2blkdir; \
1461.1Sbouyer	  jot -r -c -s '' -n 10 > $$TMPFS_1/10b; \
1471.1Sbouyer	  for f in ${DIGITS}; do for g in ${DIGITS}; do \
1481.1Sbouyer	    jot -r -c -s '' -n 10 > \
1491.1Sbouyer	      $$TMPFS_1/really_really_really_really_really_really_long_name_to_use_up_space_$$f$$g ;\
1501.1Sbouyer	    done; done; \
1511.1Sbouyer	  rm $$TMPFS_1/10b
1521.1Sbouyer
1531.1Sbouyer	@# Now create a directory with at least one indirect block.
1541.1Sbouyer	@# On a FS with 8K blocks, we need at least 1 + 12*8192 bytes, or
1551.1Sbouyer	@#   98305 bytes, in the directory.  1000 files does the trick,
1561.1Sbouyer	@#   with the long filename below.
1571.1Sbouyer	mkdir ${TMPL}/indirblk
1581.1Sbouyer	chflags nodump ${TMPL}/indirblk
1591.1Sbouyer	TMPFS_1=${TMPL}/indirblk; \
1601.1Sbouyer	  jot -r -c -s '' -n 10 >  $$TMPFS_1/10b; \
1611.1Sbouyer	  for e in 0; do\
1621.1Sbouyer	  for f in ${DIGITS}; do for g in ${DIGITS}; do for h in ${DIGITS}; do \
1631.1Sbouyer	    jot -r -c -s '' -n 10 >  \
1641.1Sbouyer	      $$TMPFS_1/really_really_really_really_really_really_long_name_to_use_up_dir_entry_space$$e$$f$$g$$h ;\
1651.1Sbouyer	    done; done; done; done; \
1661.1Sbouyer	  rm $$TMPFS_1/10b
1671.1Sbouyer	@# ^---  As before, make sure at least one direntry is a deleted file.
168