Add the undocumented -R option to disable randomness for regression-testing.

Add a couple of simple regression tests accessible with "make test", they
depend on the md(4) driver.

FYI I have also tried running the test against a week old newfs and it
passed.
This commit is contained in:
Poul-Henning Kamp 2002-03-19 21:05:29 +00:00
parent 1f31a77ce8
commit 89fb8ee796
7 changed files with 71 additions and 3 deletions

View File

@ -7,3 +7,9 @@ WARNS?= 2
MAN= newfs.8 MAN= newfs.8
.include <bsd.prog.mk> .include <bsd.prog.mk>
test: ${PROG}
sh ${.CURDIR}/runtest01.sh
sh ${.CURDIR}/runtest00.sh | tee _.test
diff --ignore-matching-lines=FreeBSD _.test ${.CURDIR}/ref.test
echo All Tests Passed

View File

@ -123,8 +123,11 @@ mkfs(struct partition *pp, char *fsys, int fi, int fo)
int width; int width;
char tmpbuf[100]; /* XXX this will break in about 2,500 years */ char tmpbuf[100]; /* XXX this will break in about 2,500 years */
time(&utime); if (Rflag)
if (!randinit) { utime = 1000000000;
else
time(&utime);
if (!Rflag && !randinit) {
randinit = 1; randinit = 1;
srandomdev(); srandomdev();
} }

View File

@ -148,6 +148,7 @@ static struct disklabel *getdisklabel(char *s, int fd);
int Nflag; /* run without writing file system */ int Nflag; /* run without writing file system */
int Oflag; /* format as an 4.3BSD file system */ int Oflag; /* format as an 4.3BSD file system */
int Rflag; /* regression test */
int Uflag; /* enable soft updates for file system */ int Uflag; /* enable soft updates for file system */
int fssize; /* file system size */ int fssize; /* file system size */
int ntracks = NTRACKS; /* # tracks/cylinder */ int ntracks = NTRACKS; /* # tracks/cylinder */
@ -209,7 +210,7 @@ main(int argc, char *argv[])
progname = *argv; progname = *argv;
while ((ch = getopt(argc, argv, while ((ch = getopt(argc, argv,
"NOS:T:Ua:b:c:d:e:f:g:h:i:k:l:m:n:o:p:r:s:t:u:vx:")) != -1) "NORS:T:Ua:b:c:d:e:f:g:h:i:k:l:m:n:o:p:r:s:t:u:vx:")) != -1)
switch (ch) { switch (ch) {
case 'N': case 'N':
Nflag = 1; Nflag = 1;
@ -217,6 +218,9 @@ main(int argc, char *argv[])
case 'O': case 'O':
Oflag = 1; Oflag = 1;
break; break;
case 'R':
Rflag = 1;
break;
case 'S': case 'S':
if ((sectorsize = atoi(optarg)) <= 0) if ((sectorsize = atoi(optarg)) <= 0)
fatal("%s: bad sector size", optarg); fatal("%s: bad sector size", optarg);
@ -596,6 +600,7 @@ usage()
fprintf(stderr, fprintf(stderr,
"\t-N do not create file system, just print out parameters\n"); "\t-N do not create file system, just print out parameters\n");
fprintf(stderr, "\t-O create a 4.3BSD format filesystem\n"); fprintf(stderr, "\t-O create a 4.3BSD format filesystem\n");
fprintf(stderr, "\t-R regression test, supress random factors\n");
fprintf(stderr, "\t-S sector size\n"); fprintf(stderr, "\t-S sector size\n");
#ifdef COMPAT #ifdef COMPAT
fprintf(stderr, "\t-T disktype\n"); fprintf(stderr, "\t-T disktype\n");

View File

@ -39,6 +39,7 @@
*/ */
extern int Nflag; /* run mkfs without writing file system */ extern int Nflag; /* run mkfs without writing file system */
extern int Oflag; /* format as an 4.3BSD file system */ extern int Oflag; /* format as an 4.3BSD file system */
extern int Rflag; /* regression test */
extern int Uflag; /* enable soft updates for file system */ extern int Uflag; /* enable soft updates for file system */
extern int fssize; /* file system size */ extern int fssize; /* file system size */
extern int ntracks; /* # tracks/cylinder */ extern int ntracks; /* # tracks/cylinder */

7
sbin/newfs/ref.test Normal file
View File

@ -0,0 +1,7 @@
# $FreeBSD$
ba20315918bf2d2885eed49fee03e3ca
e2170dc5d6bd192f85da9d1085550265
510df6ee7aadd7a5477b47c1a967e8db
47a1a6afcd21c166f32027020b0b6a7e
6e3b83f554b0216206a2768f8b01d9a1
f6035a903644e118f09c6041fb29f7ce

19
sbin/newfs/runtest00.sh Normal file
View File

@ -0,0 +1,19 @@
#!/bin/sh
# $FreeBSD$
set -e
MD=99
(
for s in 1m 4m 60m 120m 240m 1g
do
(
mdconfig -d -u $MD || true
mdconfig -a -t malloc -s $s -u $MD
disklabel -r -w md$MD auto
./newfs -R /dev/md${MD}c
) 1>&2
md5 < /dev/md${MD}c
done
mdconfig -d -u $MD 1>&2 || true
)

27
sbin/newfs/runtest01.sh Normal file
View File

@ -0,0 +1,27 @@
#!/bin/sh
# $FreeBSD$
set -e
MD=99
ME=98
s=1m
mdconfig -d -u $MD || true
mdconfig -d -u $ME || true
mdconfig -a -t malloc -s $s -u $MD
mdconfig -a -t malloc -s $s -u $ME
disklabel -r -w md$MD auto
disklabel -r -w md$ME auto
./newfs -R /dev/md${MD}c
./newfs -R /dev/md${ME}c
if cmp /dev/md${MD}c /dev/md${ME}c ; then
echo "Test passed"
e=0
else
echo "Test failed"
e=1
fi
mdconfig -d -u $MD || true
mdconfig -d -u $ME || true
exit $e