usertests -c to repeat tests forever
detect memory leaks no more "already ran user tests"
This commit is contained in:
parent
e7ffb74ad1
commit
9de9211b11
|
@ -1418,6 +1418,14 @@ fourteen(char *s)
|
||||||
printf("%s: mkdir 12345678901234/123456789012345 succeeded!\n", s);
|
printf("%s: mkdir 12345678901234/123456789012345 succeeded!\n", s);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clean up
|
||||||
|
unlink("123456789012345/12345678901234");
|
||||||
|
unlink("12345678901234/12345678901234");
|
||||||
|
unlink("12345678901234/12345678901234/12345678901234");
|
||||||
|
unlink("123456789012345/123456789012345/123456789012345");
|
||||||
|
unlink("12345678901234/123456789012345");
|
||||||
|
unlink("12345678901234");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1512,7 +1520,8 @@ dirfile(char *s)
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// test that iput() is called at the end of _namei()
|
// test that iput() is called at the end of _namei().
|
||||||
|
// also tests empty file names.
|
||||||
void
|
void
|
||||||
iref(char *s)
|
iref(char *s)
|
||||||
{
|
{
|
||||||
|
@ -1539,6 +1548,12 @@ iref(char *s)
|
||||||
unlink("xx");
|
unlink("xx");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clean up
|
||||||
|
for(i = 0; i < NINODE + 1; i++){
|
||||||
|
chdir("..");
|
||||||
|
unlink("irefd");
|
||||||
|
}
|
||||||
|
|
||||||
chdir("/");
|
chdir("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2087,13 +2102,32 @@ badarg(char *s)
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// use sbrk() to count how many free physical memory pages there are.
|
||||||
|
//
|
||||||
|
int
|
||||||
|
countfree()
|
||||||
|
{
|
||||||
|
uint64 sz0 = (uint64)sbrk(0);
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
|
while(1){
|
||||||
|
if((uint64)sbrk(4096) == 0xffffffffffffffff){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
n += 1;
|
||||||
|
}
|
||||||
|
sbrk(-((uint64)sbrk(0) - sz0));
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
// run each test in its own process. run returns 1 if child's exit()
|
// run each test in its own process. run returns 1 if child's exit()
|
||||||
// indicates success.
|
// indicates success.
|
||||||
int
|
int
|
||||||
run(void f(char *), char *s) {
|
run(void f(char *), char *s) {
|
||||||
int pid;
|
int pid;
|
||||||
int xstatus;
|
int xstatus;
|
||||||
|
|
||||||
printf("test %s: ", s);
|
printf("test %s: ", s);
|
||||||
if((pid = fork()) < 0) {
|
if((pid = fork()) < 0) {
|
||||||
printf("runtest: fork error\n");
|
printf("runtest: fork error\n");
|
||||||
|
@ -2115,9 +2149,16 @@ run(void f(char *), char *s) {
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *n = 0;
|
int continuous = 0;
|
||||||
if(argc > 1) {
|
char *justone = 0;
|
||||||
n = argv[1];
|
|
||||||
|
if(argc == 2 && strcmp(argv[1], "-c") == 0){
|
||||||
|
continuous = 1;
|
||||||
|
} else if(argc == 2 && argv[1][0] != '-'){
|
||||||
|
justone = argv[1];
|
||||||
|
} else if(argc > 1){
|
||||||
|
printf("Usage: usertests [-c] [testname]\n");
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct test {
|
struct test {
|
||||||
|
@ -2173,25 +2214,48 @@ main(int argc, char *argv[])
|
||||||
{bigdir, "bigdir"}, // slow
|
{bigdir, "bigdir"}, // slow
|
||||||
{ 0, 0},
|
{ 0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
printf("usertests starting\n");
|
|
||||||
|
|
||||||
if(open("usertests.ran", 0) >= 0){
|
if(continuous){
|
||||||
printf("already ran user tests -- rebuild fs.img (rm fs.img; make fs.img)\n");
|
printf("continuous usertests starting\n");
|
||||||
exit(1);
|
while(1){
|
||||||
|
int fail = 0;
|
||||||
|
int free0 = countfree();
|
||||||
|
for (struct test *t = tests; t->s != 0; t++) {
|
||||||
|
if(!run(t->f, t->s)){
|
||||||
|
fail = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(fail){
|
||||||
|
printf("SOME TESTS FAILED\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
int free1 = countfree();
|
||||||
|
if(free1 < free0){
|
||||||
|
printf("FAILED -- lost some free pages\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
close(open("usertests.ran", O_CREATE));
|
|
||||||
|
|
||||||
|
printf("usertests starting\n");
|
||||||
|
int free0 = countfree();
|
||||||
int fail = 0;
|
int fail = 0;
|
||||||
for (struct test *t = tests; t->s != 0; t++) {
|
for (struct test *t = tests; t->s != 0; t++) {
|
||||||
if((n == 0) || strcmp(t->s, n) == 0) {
|
if((justone == 0) || strcmp(t->s, justone) == 0) {
|
||||||
if(!run(t->f, t->s))
|
if(!run(t->f, t->s))
|
||||||
fail = 1;
|
fail = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!fail)
|
|
||||||
printf("ALL TESTS PASSED\n");
|
if(fail){
|
||||||
else
|
|
||||||
printf("SOME TESTS FAILED\n");
|
printf("SOME TESTS FAILED\n");
|
||||||
exit(1); // not reached.
|
exit(1);
|
||||||
|
} else if(countfree() < free0){
|
||||||
|
printf("FAILED -- lost some free pages\n");
|
||||||
|
exit(1);
|
||||||
|
} else {
|
||||||
|
printf("ALL TESTS PASSED\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue